Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-04

LocateNext

14 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joost van der Sluis

Hi all,

I'm busy implementing TBufDataset.Locate and friends. I had the idea to overload Locate like this:

function Locate(const keyfields: string; const keyvalues: Variant;
  options: TLocateOptions; LocateNext : boolean ) : boolean;

So that it's possible to doe a 'locatenext'

But I saw that sqlite simply has a 'locatenext' function. But it is also possible to add a TLocateOption...

I'm thinking about implementing this (abstract) at the TDataset level. What option should I choose and what do you guys think the idea?

Met vriendelijke groeten, Joost van der Sluis CNOC Informatiesystemen en Netwerken http://www.cnoc.nl

Reply by email

Micha Nelissen
to Joost van der Sluis
Show quoted text 10 lines
function Locate(const keyfields: string; const keyvalues: Variant; options: TLocateOptions; LocateNext : boolean ) : boolean; So that it's possible to doe a 'locatenext' But I saw that sqlite simply has a 'locatenext' function. But it is also possible to add a TLocateOption... I'm thinking about implementing this (abstract) at the TDataset level. What option should I choose and what do you guys think the idea?

I think .Filter in combination with .FindFirst/Prior/Next/Last is just as powerful, so a LocateNext should not be needed. Does Locate guarantee finding the first record that matches ?

Micha

Reply by email

Michael Van Canneyt
to Micha Nelissen
Micha Nelissen wrote 17 lines
On Fri, 07 Apr 2006 21:16:23 +0200 Joost van der Sluis wrote: > function Locate(const keyfields: string; const keyvalues: Variant; > options: TLocateOptions; LocateNext : boolean ) : boolean; > > So that it's possible to doe a 'locatenext' > > But I saw that sqlite simply has a 'locatenext' function. But it is also > possible to add a TLocateOption... > > I'm thinking about implementing this (abstract) at the TDataset level. > What option should I choose and what do you guys think the idea? I think .Filter in combination with .FindFirst/Prior/Next/Last is just as powerful, so a LocateNext should not be needed. Does Locate guarantee finding the first record that matches ?

It should.

Personally, I always use filter for such things.

Michael.

Reply by email

Doug Nettleton
to Joost van der Sluis: I'm busy implementing TBufDataset.Locate and friends. I had the idea to overload Locate…

Hi All,

I'm new here - variously playing with Lazarus and mseide&msegui. I posted the :

Show quoted text 10 lines
bug in tmsesqlquery, certain field types don't appear in the FieldDefs list. Initailly, I had a file with four character fields and four decimal(7,3) fields. "select * from mytable" as the SQL and setting active to True. FieldDefs property only contains the 4 character (TString) fields. Adding a date field to the table and setting active flag to false then back to true, FieldDefs property contains 5 fields - the 4 character fields and the date field.

and got the following from Martin...

This problem lies probably in the underlying TSQLQuery. Could you discuss it with Jost van der Sluis at FPC-Devel mailing list?

I've looked in the 2.0.2 source, 2.0.3 snapshot source, 2.1.x snapshot source and don't see an obvious reason why character and date fields would work differently from decimal although I noticed comments somewhere last week about the "new" decimal field in MySQL version 5.0.

The function MySQLDataType, in fcl/db/sqldb/mysql/mysqlconn.inc refers to FIELD_TYPE_DECIMAL in one of the case clauses. Perhaps version 5.0 changed this value?

On another matter, are there any plans to implement a datasource property on TMySQLQuery for resolving parameters? This is a very powerful facility. I think I know a workaround, but I'd prefer not to use it.

Doug

Reply by email

Michael Van Canneyt
to Doug Nettleton
Doug Nettleton wrote 25 lines
Hi All, I'm new here - variously playing with Lazarus and mseide&msegui. I posted the : > bug in tmsesqlquery, certain field types don't appear in the FieldDefs > list. > Initailly, I had a file with four character fields and four decimal(7,3) > fields. "select * from mytable" as the SQL and setting active to True. > FieldDefs property only contains the 4 character (TString) fields. > Adding a > date field to the table and setting active flag to false then back to > true, > FieldDefs property contains 5 fields - the 4 character fields and the > date field. and got the following from Martin... This problem lies probably in the underlying TSQLQuery. Could you discuss it with Jost van der Sluis at FPC-Devel mailing list? I've looked in the 2.0.2 source, 2.0.3 snapshot source, 2.1.x snapshot source and don't see an obvious reason why character and date fields would work differently from decimal although I noticed comments somewhere last week about the "new" decimal field in MySQL version 5.0.

Probably that is used.

The function MySQLDataType, in fcl/db/sqldb/mysql/mysqlconn.inc refers to FIELD_TYPE_DECIMAL in one of the case clauses. Perhaps version 5.0 changed this value?

No. It did introduce a new type "MYSQL_TYPE_NEWDECIMAL"

I added support for this new fieldtype.

On another matter, are there any plans to implement a datasource property on TMySQLQuery for resolving parameters? This is a very powerful facility. I think I know a workaround, but I'd prefer not to use it.

It is implemented for SQLDB since last week, but for MySQL it doesn't work yet: the parameters are ignored. (because MySQL has no native parameter support) It does work for firebird and postgres. It should be easy to add, however, to mysql. All that needs to be done is to replace the parameter names with the actual current values.

Michael.

Reply by email

Marc Weustink
to Micha Nelissen: On Fri, 07 Apr 2006 21:16:23 +0200 I think .Filter in combination with…
Micha Nelissen wrote 18 lines
On Fri, 07 Apr 2006 21:16:23 +0200 Joost van der Sluis wrote: >function Locate(const keyfields: string; const keyvalues: Variant; > options: TLocateOptions; LocateNext : boolean ) : boolean; > >So that it's possible to doe a 'locatenext' > >But I saw that sqlite simply has a 'locatenext' function. But it is also >possible to add a TLocateOption... > >I'm thinking about implementing this (abstract) at the TDataset level. >What option should I choose and what do you guys think the idea? I think .Filter in combination with .FindFirst/Prior/Next/Last is just as powerful, so a LocateNext should not be needed.

Not really. Sometimes I use a locate to find a record in a dataset. I don't want to limit the records in that dataset with a filter.

Marc

Show quoted text 8 lines
Does Locate guarantee finding the first record that matches ? Micha _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Micha Nelissen
to Marc Weustink
Show quoted text 5 lines
> I think .Filter in combination with .FindFirst/Prior/Next/Last is just as > powerful, so a LocateNext should not be needed. Not really. Sometimes I use a locate to find a record in a dataset. I don't want to limit the records in that dataset with a filter.
If you don't want to limit, then set .Filtered := false; and use
FindFirst etc.

Micha

Reply by email

Alexandrov Alexandru
to Joost van der Sluis: I'm busy implementing TBufDataset.Locate and friends. I had the idea to overload Locate…
Joost van der Sluis wrote 12 lines
Hi all, I'm busy implementing TBufDataset.Locate and friends. I had the idea to overload Locate like this: function Locate(const keyfields: string; const keyvalues: Variant; options: TLocateOptions; LocateNext : boolean ) : boolean; So that it's possible to doe a 'locatenext' But I saw that sqlite simply has a 'locatenext' function. But it is also possible to add a TLocateOption...

There is no need to pass again keyfields, keyvalues and options parameters to locate next match. What to do if they are not the same as for first locate?
IMO sqlite aproach is better.

I'm thinking about implementing this (abstract) at the TDataset level. What option should I choose and what do you guys think the idea?

I think a LocateNext function would be fine.

Alex

Reply by email

Joost van der Sluis
to Micha Nelissen: On Sat, 08 Apr 2006 17:19:34 +0200 If you don't want to limit, then set .Filtered :=…
Show quoted text 5 lines
> Not really. Sometimes I use a locate to find a record in a dataset. I > don't want to limit the records in that dataset with a filter. If you don't want to limit, then set .Filtered := false; and use FindFirst etc.

wich won't work with current sqldb, since filtering there simply adds a 'where' part to the query.
An which is much slower then locate and locatenext.

Isn't the mean reason why you and Michael aren't using locate, that locatenext is missing?

Met vriendelijke groeten, Joost van der Sluis CNOC Informatiesystemen en Netwerken http://www.cnoc.nl

Reply by email

Joost van der Sluis
to Alexandrov Alexandru: There is no need to pass again keyfields, keyvalues and options parameters to locate next…
Show quoted text 14 lines
> I'm busy implementing TBufDataset.Locate and friends. I had the idea to > overload Locate like this: > > function Locate(const keyfields: string; const keyvalues: Variant; > options: TLocateOptions; LocateNext : boolean ) : boolean; > > So that it's possible to doe a 'locatenext' > > But I saw that sqlite simply has a 'locatenext' function. But it is also > possible to add a TLocateOption... There is no need to pass again keyfields, keyvalues and options parameters to locate next match. What to do if they are not the same as for first locate?

I planned to give locatenext exactly the same parameters as locate itself. So you have to pass the same parameters again, but it adds some flexibility. For example if you're on a 'random' record, and want to locate the next one. Then you won't need to do a 'locate' first, but can do a locatenext immediately.

Joost

Reply by email

Alexandrov Alexandru
to Joost van der Sluis
Joost van der Sluis wrote 20 lines
> > I'm busy implementing TBufDataset.Locate and friends. I had the idea to > > overload Locate like this: > > > > function Locate(const keyfields: string; const keyvalues: Variant; > > options: TLocateOptions; LocateNext : boolean ) : boolean; > > > > So that it's possible to doe a 'locatenext' > > > > But I saw that sqlite simply has a 'locatenext' function. But it is also > > possible to add a TLocateOption... > > There is no need to pass again keyfields, keyvalues and options > parameters to locate next match. What to do if they are not the same > as for first locate? I planned to give locatenext exactly the same parameters as locate itself. So you have to pass the same parameters again, but it adds some flexibility. For example if you're on a 'random' record, and want to locate the next one. Then you won't need to do a 'locate' first, but can do a locatenext immediately.

Then i suggest you to name that function LocateRest. Both functions are useful.

Alex

Reply by email

Michael Van Canneyt
to Joost van der Sluis: wich won't work with current sqldb, since filtering there simply adds a 'where' part to…
Joost van der Sluis wrote 12 lines
>> Not really. Sometimes I use a locate to find a record in a dataset. I >> don't want to limit the records in that dataset with a filter. > > If you don't want to limit, then set .Filtered := false; and use > FindFirst etc. wich won't work with current sqldb, since filtering there simply adds a 'where' part to the query. An which is much slower then locate and locatenext. Isn't the mean reason why you and Michael aren't using locate, that locatenext is missing?

I definitely use locate.

But if I would need a 'LocateNext' kind of functionality, I would use a filter.

Michael.

Reply by email

Luiz Americo Pereira Camara
to Micha Nelissen: On Mon, 10 Apr 2006 12:33:18 +0200 Same story for TDbf :-). Oh, I am using Locate. I'm…
Micha Nelissen wrote 30 lines
On Mon, 10 Apr 2006 12:33:18 +0200 Joost van der Sluis wrote: >> If you don't want to limit, then set .Filtered := false; and use >> FindFirst etc. >> > wich won't work with current sqldb, since filtering there simply adds a > 'where' part to the query. > An which is much slower then locate and locatenext. > Same story for TDbf :-). > Isn't the mean reason why you and Michael aren't using locate, that > locatenext is missing? > Oh, I am using Locate. I'm just talking from the general TDataSet POV. That said, LocateNext may be useful, but I would rather add a flag to Locate; a TLocateNagivation (lnFirst, lnPrior, lnNext, lnLast), with the default being lnFirst, thus compatible. It's a bit more flexible. OTOH, is it really impossible to do it the "right" way, implementing the filter more efficiently, in sqldb ? Adding redundant ways to do the same thing is not ideal IMHO.

Just one information. I based the LocateNext implemetation of TCustomSqliteDataset in the found at FIBL which was the only TDataset that had it implemented.
Here is the FIBL approach:

function Locate(const KeyFields: String; const KeyValues: Variant;
      Options: TLocateOptions): Boolean;
function LocateNext(const KeyFields: String; const KeyValues: Variant;
      Options: TLocateOptions): Boolean; // Sister function to Locate

Luiz

Reply by email

Micha Nelissen
to Joost van der Sluis: wich won't work with current sqldb, since filtering there simply adds a 'where' part to…
Show quoted text 6 lines
> If you don't want to limit, then set .Filtered := false; and use > FindFirst etc. wich won't work with current sqldb, since filtering there simply adds a 'where' part to the query. An which is much slower then locate and locatenext.

Same story for TDbf :-).

Isn't the mean reason why you and Michael aren't using locate, that locatenext is missing?

Oh, I am using Locate. I'm just talking from the general TDataSet POV.

That said, LocateNext may be useful, but I would rather add a flag to Locate; a TLocateNagivation (lnFirst, lnPrior, lnNext, lnLast), with the default being lnFirst, thus compatible. It's a bit more flexible.

OTOH, is it really impossible to do it the "right" way, implementing the filter more efficiently, in sqldb ?

Adding redundant ways to do the same thing is not ideal IMHO.

Micha

Reply by email