Recent

Author Topic: 2 question about SQLite  (Read 4003 times)

free07

  • New member
  • *
  • Posts: 9
2 question about SQLite
« on: November 22, 2012, 04:10:28 pm »
Hi all,

Using Free Pascal and XCode, i have two question :

First one :
Here is my code :
Code: [Select]
function TAccesBase.GetLibSequence(P_iSequence : integer; var P_sLibSequence : UnicodeString) : boolean;
var l_bOk : boolean;
{$IFDEF FPC}
    l_sSQL : UnicodeString;
    l_DB : TSQLite;
    l_SL : Classes.TStringList;
{$ENDIF}

begin
  l_bOk := false;
P_sLibSequence := '';
{$IFDEF FPC}
  try
    l_SL := Classes.TStringList.create;
    l_DB := TSQLite.Create(UnicodeString(pAB_sFileName));
l_sSQL := 'SELECT Libelle FROM Sequence WHERE IdSequence = ''' + IntToStr(P_iSequence) + '''';
    l_bOk := l_DB.Query(l_sSQL, l_SL);
    if l_bOk = true then
      P_sLibSequence := l_SL.Text;   // the result is allways : 'Libelle Libx"
    l_bOk := Length(P_sLibSequence) > 0;
    freeandnil(l_DB);
    freeandnil(l_SL);
except
    on E:Exception do
    begin
      ShowMessage(E.Message);
l_bOk := false;
    end;
  end;
{$ENDIF}
Result := l_bOk;
end;

I get my libelle, every is ok except the string libelle is added before my libelle , why ?
In fact, he added in first the name of the column, how can i get it without it ?

2nd Question :

How can i get a blob contains a bitmap, i cannot used DB.Query to obtain it because the syntax is :
DB.Query(sql : string, result : string)...

Where can i find documentation about TSQLite ?

Sorry it made 3 questions :)
TIA

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: 2 question about SQLite
« Reply #1 on: November 23, 2012, 05:58:52 pm »
I'm not aware of any documentation for the TSQLite class. Looking at the source code copyright it looks like some of the oldest code in FPC. And it is clunky to use at first.

The query result is a TStringList. The first item is a comma-separated list of fields identifying the data returned. Each additional item in the TStringList is a comma-separated list of data - that is, each item indexed starting with 1 is data record.

In your case, you're returning only a single item and a single record, so you don't need to parse either the field list or the data list. Just l_SL[1] is all you need. For multiple fields, use the ValueList procedure to do the parsing.

I find it useful to use "object composition" to wrap a TSQLite object in a Pascal class. See the UnicodeDb.pas unit here for an example:

http://web.fastermac.net/~MacPgmr/qxotica/QxoticaStatus.html


Also, you don't need to use UnicodeString. FPC's SQLite units wrap the UTF8 functions in the SQLite library, not the UTF16 functions.


You can store a bitmap as a hex string in the file and thus query it as a string.

Thanks.

-Phil



free07

  • New member
  • *
  • Posts: 9
Re: 2 question about SQLite
« Reply #2 on: November 23, 2012, 06:33:17 pm »
Thanks Phil,

Sorry i don't find UnicodeDb.pas ...
Yes, in fact, i need a simple Free Pascal wrapper for the SQLite API. without configuration and component, just a class that can be used with SQLite Database.
And with documentation :-)
If anyone knows it ...
TIA

Phil

  • Hero Member
  • *****
  • Posts: 2737

 

TinyPortal © 2005-2018