[Gambas-user] DataSource
Benoît Minisini
g4mba5 at gmail.com
Mon Nov 23 21:36:11 CET 2020
Le 22/11/2020 à 22:59, Fabien Bodard a écrit :
> I need help..
>
> I want my datasource reach a given line given one field and not a line
> index... how can I achieve that quickly ... Actually I'm doing it by a
> Force and stupid way.
>
>
> Static Private reference As String
>
> Public Sub Run(Value As String)
>
> reference = Value
> FClientEdit.Showmodal
>
> End
>
> Public Sub Form_Open()
>
> Dim i As Integer
> Dim aGeo As String[]
>
> '----- HERE HOW TO FIND LINE :-/ --------------
> DataSource1.MoveFirst
> For i = 0 To DataSource1.Count - 1
> If DataSource1["reference"] = reference Then Break
> DataSource1.MoveNext
> Next
> '-------------------------------------------
Hi Fabien,
I have added in the last commit the Find() and FindNext() method to the
DataSource class. They should do what your want.
I first thought it was impossible, but I didn't know the ROW_NUMBER()
SQL function, that hopefully is present in Sqlite, MySQL and PostgreSQL.
But beware, only since version 8 in MySQL.
You use them that way:
iIndex = DataSource1.Find("reference = &1", reference)
Find() returns the index of the first matching row.
FindNext() returns the index of the first matching row next to the
current DataSource position.
Anyway, it will be faster to not use DataSource for that, and use direct
requests to the database.
Regards,
--
Benoît Minisini
More information about the User
mailing list