aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-27 15:52:30 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2008-10-27 15:52:30 +0000
commitf209316474cc121b51455770df6c24b9c64796a9 (patch)
tree150a982d7f1dc84d27590d9956366872a326cae1 /src
parentd6770dd47dcb871f021868dec2b333527ffb8ee8 (diff)
downloadusdx-f209316474cc121b51455770df6c24b9c64796a9.tar.gz
usdx-f209316474cc121b51455770df6c24b9c64796a9.tar.xz
usdx-f209316474cc121b51455770df6c24b9c64796a9.zip
- Results of UTF8Encode() in TSQLiteDatabase.BindData() are stored in a local AnsiString variable instead of directly converting it to PChar
old: PAnsiChar(UTF8Encode(WideString(Bindings[I].VPWideChar))); new: AnsiStr := UTF8Encode(WideString(Bindings[I].VPWideChar)); DataPtr := PAnsiChar(AnsiStr); Although Delphi and FPC create a temporary AnsiString on the stack which is valid until the end of the method, it is more safe not to rely on this behavior. Maybe in some future version of Delphi/FPC the reference count might be decremented and invalidated after converting the temporary AnsiString to a PChar and the PChar will point to invalid data. In contrast to this, the scope of AnsiStr is obvious. - {$IFDEF WIN32} -> {$IFDEF MSWINDOWS} - {$WARNINGS OFF/ON} removed - var-parameters of SQLite3_Open/SQLite3_Prepare/SQLite3_Prepare_v2 declared as out git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1480 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--src/lib/SQLite/SQLite3.pas6
-rw-r--r--src/lib/SQLite/SQLiteTable3.pas24
2 files changed, 11 insertions, 19 deletions
diff --git a/src/lib/SQLite/SQLite3.pas b/src/lib/SQLite/SQLite3.pas
index 6120e013..9537606c 100644
--- a/src/lib/SQLite/SQLite3.pas
+++ b/src/lib/SQLite/SQLite3.pas
@@ -97,7 +97,7 @@ type
Buf2Len: integer; Buf2: pointer): integer; cdecl;
-function SQLite3_Open(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_open';
+function SQLite3_Open(filename: PAnsiChar; out db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_open';
function SQLite3_Close(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_close';
function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_exec';
function SQLite3_Version(): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_libversion';
@@ -113,8 +113,8 @@ procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCall
procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer); cdecl; external SQLiteDLL name 'sqlite3_busy_timeout';
function SQLite3_Changes(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_changes';
function SQLite3_TotalChanges(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_total_changes';
-function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare';
-function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare_v2';
+function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; out hStmt: TSqliteStmt; out pzTail: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare';
+function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; out hStmt: TSqliteStmt; out pzTail: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare_v2';
function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_column_count';
function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_column_name';
function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_column_decltype';
diff --git a/src/lib/SQLite/SQLiteTable3.pas b/src/lib/SQLite/SQLiteTable3.pas
index 33d52354..7df76363 100644
--- a/src/lib/SQLite/SQLiteTable3.pas
+++ b/src/lib/SQLite/SQLiteTable3.pas
@@ -401,19 +401,23 @@ begin
DataSize := Length(AnsiStrPtr^)+1;
end;
vtPWideChar: begin
- DataPtr := PAnsiChar(UTF8Encode(WideString(Bindings[I].VPWideChar)));
+ AnsiStr := UTF8Encode(WideString(Bindings[I].VPWideChar));
+ DataPtr := PAnsiChar(AnsiStr);
DataSize := -1;
end;
vtWideString: begin
- DataPtr := PAnsiChar(UTF8Encode(PWideString(@Bindings[I].VWideString)^));
+ AnsiStr := UTF8Encode(PWideString(@Bindings[I].VWideString)^);
+ DataPtr := PAnsiChar(AnsiStr);
DataSize := -1;
end;
vtChar: begin
- DataPtr := PAnsiChar(String(Bindings[I].VChar));
+ AnsiStr := AnsiString(Bindings[I].VChar);
+ DataPtr := PAnsiChar(AnsiStr);
DataSize := 2;
end;
vtWideChar: begin
- DataPtr := PAnsiChar(UTF8Encode(WideString(Bindings[I].VWideChar)));
+ AnsiStr := UTF8Encode(WideString(Bindings[I].VWideChar));
+ DataPtr := PAnsiChar(AnsiStr);
DataSize := -1;
end;
else
@@ -514,7 +518,6 @@ begin
end;
end;
-{$WARNINGS OFF}
procedure TSQLiteDatabase.ExecSQL(Query: TSQLiteQuery);
var
iStepResult: integer;
@@ -531,9 +534,7 @@ begin
Sqlite3_Reset(Query.Statement);
end;
end;
-{$WARNINGS ON}
-{$WARNINGS OFF}
function TSQLiteDatabase.PrepareSQL(const SQL: Ansistring): TSQLiteQuery;
var
Stmt: TSQLiteStmt;
@@ -552,9 +553,7 @@ begin
RaiseError('Could not prepare SQL statement', SQL);
DoQuery(SQL);
end;
-{$WARNINGS ON}
-{$WARNINGS OFF}
procedure TSQLiteDatabase.BindSQL(Query: TSQLiteQuery; const Index: Integer; const Value: Integer);
begin
if Assigned(Query.Statement) then
@@ -562,9 +561,7 @@ begin
else
RaiseError('Could not bind integer to prepared SQL statement', Query.SQL);
end;
-{$WARNINGS ON}
-{$WARNINGS OFF}
procedure TSQLiteDatabase.BindSQL(Query: TSQLiteQuery; const Index: Integer; const Value: String);
begin
if Assigned(Query.Statement) then
@@ -572,9 +569,7 @@ begin
else
RaiseError('Could not bind string to prepared SQL statement', Query.SQL);
end;
-{$WARNINGS ON}
-{$WARNINGS OFF}
procedure TSQLiteDatabase.ReleaseSQL(Query: TSQLiteQuery);
begin
if Assigned(Query.Statement) then
@@ -585,7 +580,6 @@ begin
else
RaiseError('Could not release prepared SQL statement', Query.SQL);
end;
-{$WARNINGS ON}
procedure TSQLiteDatabase.UpdateBlob(const SQL: Ansistring; BlobData: TStream);
var
@@ -1295,7 +1289,6 @@ begin
end;
end;
-{$WARNINGS OFF}
function TSQLiteTable.MoveTo(position: cardinal): boolean;
begin
Result := False;
@@ -1305,7 +1298,6 @@ begin
Result := True;
end;
end;
-{$WARNINGS ON}