Taj Morton wrote:
> Dennis Cote wrote:
>
>> Taj,
>>
>> I'm not sure what wrapper you are using, but the sqlite.dll provided
>> by SQLite has two API functions that are used to open and close the
>> database connection. You use sqlite3_open() to open the connection,
>> and sqlite3_close() to close it. Between these two calls you can
>> execute as many queries as you want, either using sqlite3_exec() or
>> the sqlite3_prepare()/sqlite3_step()/sqlite3_finalize() APIs.
>>
>>
> Dennis,
> I've done some testing and the wrapper and it appears that TEMPORARY
> TABLEs don't stick around between sqlite_exec's :(. (I'm using SQLite
> 2.8.15, and thus not using the sqlite3_* functions, because the
> TSQLite wrapper uses the SQLite 2). I'm not really sure what's going
> on... It appears that the Query function just calles sqlite_exec. If
> I do this: DB.SQL:='CREATE TEMPORARY TABLE cname2cid(id INTEGER,name
> VARCHAR(512))'; DB.ExecSQL;
>
> DB.SQL does this:
> ...
> SQLite_Exec(fSQLite, PChar(Sql), @ExecCallback, Self, fPMsg);
> ...
>
> Other queries don't know about cname2cid...even the command line
> doesn't know about it. Of course, if I CREATE TEMPORARY TABLE from the
> commandline, then queries from anywhere (either from the wraper/DLL or
> the command line)...
>
> Any ideas?
>
> Thanks for the help,

Taj,

>From your description it sounds like you are using the Delphi wrapper listed
in the wiki as:

 Delphi class for SQLite.
http://www.torry.net/db/direct/db_directsql/tsqlite.zip

I'm not sure since this class doesn't have an ExecSQL method or a pulic SQL
property which you mention. If it is, I have looked at this Delphi class and
believe it should work correctly with SQLite 2.8 and temp tables.

If you do something like this:

procedure Test();
var
  MyDB: TSQLite;
  Table: TStringList;
begin
  //sqlite db is opened here
  MyDB := TSQLite.Create('MyDbFile.db');

  //create temp table
  MyDB.Query('create temp table t(a, b)');

  //write into temp table
  MyDB.Query('insert into t values (1,2)');
  MyDB.Query('insert into t values (3,4)');

  //read from temp table
  MyDB.Query('select * from t', Table);
  //do something with table here

  //sqlite db is closed here by destuctor when MyDB goes out of scope
end;

I suspect that your TSQLite variable does not have a long enough lifetime.
It must persist between your calls to the Query method.

I hope this helps.

Dennis Cote

Reply via email to