Page 1 of 1

TZSQLiteStatement.ExecuteUpdate

Posted: 24.12.2008, 22:58
by DKameleon
Was trying to use SQLite on D2009, but during insert got a message:

Code: Select all

SQL Error: near "I": syntax error.
After a little discovery located that function passes to the dll pointer to unicode sting and sqlite fails to parse it:

Code: Select all

function TZSQLiteStatement.ExecuteUpdate(const SQL: string): Integer;
var
  ErrorCode: Integer;
  ErrorMessage: PAnsiChar;
begin
  ErrorMessage := '';
  ErrorCode := FPlainDriver.Execute(FHandle, [b]PAnsiChar(SQL)[/b], nil, nil,
    ErrorMessage);
hope my report will be useful :)

Regards.

Posted: 25.12.2008, 22:28
by mdaems
The report would be even more usefull if you can change the code so it just works :) You're into it and thus at the best position to fix it.

Is it enough to include some conversion function in case of D2009? Please send us the code you changed, so we can work it into our code (eventually IFDEF'ed for D2009 only).

Mark

Posted: 25.12.2008, 23:34
by DKameleon
Yes, Y've made following change:

Code: Select all

function TZSQLiteStatement.ExecuteUpdate(const SQL: string): Integer;
var
  ErrorCode: Integer;
  ErrorMessage: PAnsiChar;
begin
  ErrorMessage := '';
  ErrorCode := FPlainDriver.Execute(FHandle, PAnsiChar(UTF8String(SQL)), nil, nil,
    ErrorMessage);
Added casting to UTF8String and it becomes working :)
Test also passed with Cyrillic sybmols :)

But select with the same cyrilic gave me wrong result:
I saw previously inserted UTF8 text as ANSI (обменник).

Seems there could be also problem with backward conversion. :(

As I see code above:

Code: Select all

function TZSQLiteStatement.ExecuteQuery(const SQL: string): IZResultSet;
var
  ErrorCode: Integer;
  ErrorMessage: PAnsiChar;
  SQLTail: PAnsiChar;
  StmtHandle: Psqlite_vm;
  ColumnCount: Integer;
  ColumnValues: PPAnsiChar;
  ColumnNames: PPAnsiChar;
begin
  ErrorMessage := '';
  SQLTail := '';
  ColumnCount := 0;
  {$IFDEF DELPHI12_UP}
  ErrorCode := FPlainDriver.Compile(FHandle, PAnsiChar(UTF8String(SQL)), Length(SQL), SQLTail,
    StmtHandle, ErrorMessage);
  {$ELSE}
  ErrorCode := FPlainDriver.Compile(FHandle, PAnsiChar(SQL), Length(SQL), SQLTail,
    StmtHandle, ErrorMessage);
  {$ENDIF}
There was already added casting to UTF8, but not sure about correct results interpretation.

Posted: 26.12.2008, 08:53
by mdaems
Check what changes are needed in the TZSQLiteResultSet.GetXXXX and TZSQLiteResultSet.GetXXXX functions that retrieve string data.

Mark

Posted: 18.01.2009, 09:41
by tkamphuis
I have the same problem when inserting a record in a simple SQLite database (1 field of the varchar type). Is there a workaround?