Recent

Author Topic: [Solved]problem with locate on tsqlquery  (Read 4011 times)

nicola69

  • New Member
  • *
  • Posts: 15
[Solved]problem with locate on tsqlquery
« on: February 04, 2013, 12:55:31 pm »
Hi
My lazarus version is 1.04 , fpc 2.6.0 , cpu icore 5 and my so is windows xp 32 bit.
I use sqlite as db.

I need copy my table on memory and search field on it.
I write my application but when use locate of tsqlquery  for searching in a column it find wrong row of table.
It find a row with a string that begin and i don't use loPartialKey as option
I have attach my sqlite db .

my unit example is

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, sqlite3conn, sqldb, db, FileUtil, Forms, Controls,
  Graphics, Dialogs, DBGrids, StdCtrls, DbCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Datasource1: TDatasource;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    SQLite3Connection1: TSQLite3Connection;
    SQLQuery1: TSQLQuery;
    SQLTransaction1: TSQLTransaction;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin

  SQLQuery1.Locate('cod_age','FA0160',[]);

 ShowMessage(IntToStr(SQLQuery1.RecNo));

end;

end.


                                             
showmessage return 21 but correct row is 823

Someone could help me to understand why it doesn't work ?


« Last Edit: February 04, 2013, 04:51:59 pm by nicola69 »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: problem with locate on tsqlquery
« Reply #1 on: February 04, 2013, 01:27:11 pm »
Thanks for posting the database and some code.

Please upload a complete sample project so others can help you easier.
Use e.g. menu  Project/Publish Project then zip up the result and attach it. Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

nicola69

  • New Member
  • *
  • Posts: 15
Re: problem with locate on tsqlquery
« Reply #2 on: February 04, 2013, 02:05:50 pm »
ok
you can download my sample application on this link

https://dl.dropbox.com/u/64726031/test%20sqlite.zip

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: problem with locate on tsqlquery
« Reply #3 on: February 04, 2013, 03:34:47 pm »
Thanks a lot.
Edit: ok, I see the problem.
« Last Edit: February 04, 2013, 03:37:18 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: problem with locate on tsqlquery
« Reply #4 on: February 04, 2013, 03:52:52 pm »
This:
Code: [Select]
showmessage('size: '+inttostr(sqlquery1.fields.FieldByName('cod_age').Size));shows fpc thinks the field size is 5 which it is according to sqlite manager:
Code: [Select]
CREATE TABLE "anagrafica" ("id" INTEGER PRIMARY KEY  NOT NULL ,"cod_age" char(5),"regione" varchar(70),"provincia" varchar(70))... what happens if you change it to char(6)

yes, you managed to squeeze in more data than you should... but I think that's an sqlite "feature" ;) )
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

nicola69

  • New Member
  • *
  • Posts: 15
Re: [Solved]problem with locate on tsqlquery
« Reply #5 on: February 04, 2013, 04:53:27 pm »
thank BigChimp
i have made a mistake
i have changed from char(5) to char(6) and now work.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: [Solved]problem with locate on tsqlquery
« Reply #6 on: February 04, 2013, 05:10:58 pm »
Great! Glad it works.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified