aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/SQLite/SQLite3.pas40
-rw-r--r--src/lib/SQLite/SQLiteTable3.pas165
2 files changed, 104 insertions, 101 deletions
diff --git a/src/lib/SQLite/SQLite3.pas b/src/lib/SQLite/SQLite3.pas
index b300f9f2..6120e013 100644
--- a/src/lib/SQLite/SQLite3.pas
+++ b/src/lib/SQLite/SQLite3.pas
@@ -80,16 +80,16 @@ const
type
TSQLiteDB = Pointer;
- TSQLiteResult = ^PChar;
+ TSQLiteResult = ^PAnsiChar;
TSQLiteStmt = Pointer;
type
- PPCharArray = ^TPCharArray;
- TPCharArray = array[0 .. (MaxInt div SizeOf(PChar))-1] of PChar;
+ PPAnsiCharArray = ^TPAnsiCharArray;
+ TPAnsiCharArray = array[0 .. (MaxInt div SizeOf(PAnsiChar))-1] of PAnsiChar;
type
TSQLiteExecCallback = function(UserData: Pointer; NumCols: integer; ColValues:
- PPCharArray; ColNames: PPCharArray): integer; cdecl;
+ PPAnsiCharArray; ColNames: PPAnsiCharArray): integer; cdecl;
TSQLiteBusyHandlerCallback = function(UserData: Pointer; P2: integer): integer; cdecl;
//function prototype for define own collate
@@ -97,27 +97,27 @@ type
Buf2Len: integer; Buf2: pointer): integer; cdecl;
-function SQLite3_Open(filename: PChar; var db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_open';
+function SQLite3_Open(filename: PAnsiChar; var 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: PChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PChar): integer; cdecl; external SQLiteDLL name 'sqlite3_exec';
-function SQLite3_Version(): PChar; cdecl; external SQLiteDLL name 'sqlite3_libversion';
-function SQLite3_ErrMsg(db: TSQLiteDB): PChar; cdecl; external SQLiteDLL name 'sqlite3_errmsg';
+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';
+function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_errmsg';
function SQLite3_ErrCode(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_errcode';
-procedure SQlite3_Free(P: PChar); cdecl; external SQLiteDLL name 'sqlite3_free';
-function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PChar): integer; cdecl; external SQLiteDLL name 'sqlite3_get_table';
+procedure SQlite3_Free(P: PAnsiChar); cdecl; external SQLiteDLL name 'sqlite3_free';
+function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_get_table';
procedure SQLite3_FreeTable(Table: TSQLiteResult); cdecl; external SQLiteDLL name 'sqlite3_free_table';
-function SQLite3_Complete(P: PChar): boolean; cdecl; external SQLiteDLL name 'sqlite3_complete';
+function SQLite3_Complete(P: PAnsiChar): boolean; cdecl; external SQLiteDLL name 'sqlite3_complete';
function SQLite3_LastInsertRowID(db: TSQLiteDB): int64; cdecl; external SQLiteDLL name 'sqlite3_last_insert_rowid';
procedure SQLite3_Interrupt(db: TSQLiteDB); cdecl; external SQLiteDLL name 'sqlite3_interrupt';
procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl; external SQLiteDLL name 'sqlite3_busy_handler';
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: PChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare';
-function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare_v2';
+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_ColumnCount(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_column_count';
-function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): pchar; cdecl; external SQLiteDLL name 'sqlite3_column_name';
-function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): pchar; cdecl; external SQLiteDLL name 'sqlite3_column_decltype';
+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';
function SQLite3_Step(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_step';
function SQLite3_DataCount(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_data_count';
@@ -125,7 +125,7 @@ function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl
function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_column_bytes';
function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double; cdecl; external SQLiteDLL name 'sqlite3_column_double';
function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_column_int';
-function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): pchar; cdecl; external SQLiteDLL name 'sqlite3_column_text';
+function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_column_text';
function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_column_type';
function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl; external SQLiteDLL name 'sqlite3_column_int64';
function SQLite3_Finalize(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_finalize';
@@ -162,7 +162,7 @@ function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer;
ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
cdecl; external SQLiteDLL name 'sqlite3_bind_blob';
function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer;
- Text: PChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
+ Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
cdecl; external SQLiteDLL name 'sqlite3_bind_text';
function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
cdecl; external SQLiteDLL name 'sqlite3_bind_double';
@@ -173,13 +173,13 @@ function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64):
function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
cdecl; external SQLiteDLL name 'sqlite3_bind_null';
-function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PChar): integer;
+function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
cdecl; external SQLiteDLL name 'sqlite3_bind_parameter_index';
function sqlite3_enable_shared_cache(Value: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_enable_shared_cache';
//user collate definiton
-function SQLite3_create_collation(db: TSQLiteDB; Name: Pchar; eTextRep: integer;
+function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer;
UserData: pointer; xCompare: TCollateXCompare): integer; cdecl; external SQLiteDLL name 'sqlite3_create_collation';
function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
@@ -240,7 +240,7 @@ begin
end;
end;
-function ColValueToStr(Value: PChar): AnsiString;
+function ColValueToStr(Value: PAnsiChar): AnsiString;
begin
if (Value = nil) then
Result := 'NULL'
diff --git a/src/lib/SQLite/SQLiteTable3.pas b/src/lib/SQLite/SQLiteTable3.pas
index ab465ef8..33d52354 100644
--- a/src/lib/SQLite/SQLiteTable3.pas
+++ b/src/lib/SQLite/SQLiteTable3.pas
@@ -64,7 +64,7 @@ interface
{$ENDIF}
uses
- {$IFDEF WIN32}
+ {$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
SQLite3, Classes, SysUtils;
@@ -118,23 +118,23 @@ type
public
constructor Create(const FileName: string);
destructor Destroy; override;
- function GetTable(const SQL: string): TSQLiteTable; overload;
- function GetTable(const SQL: string; const Bindings: array of const): TSQLiteTable; overload;
- procedure ExecSQL(const SQL: string); overload;
- procedure ExecSQL(const SQL: string; const Bindings: array of const); overload;
+ function GetTable(const SQL: Ansistring): TSQLiteTable; overload;
+ function GetTable(const SQL: Ansistring; const Bindings: array of const): TSQLiteTable; overload;
+ procedure ExecSQL(const SQL: Ansistring); overload;
+ procedure ExecSQL(const SQL: Ansistring; const Bindings: array of const); overload;
procedure ExecSQL(Query: TSQLiteQuery); overload;
- function PrepareSQL(const SQL: string): TSQLiteQuery;
+ function PrepareSQL(const SQL: Ansistring): TSQLiteQuery;
procedure BindSQL(Query: TSQLiteQuery; const Index: Integer; const Value: Integer); overload;
procedure BindSQL(Query: TSQLiteQuery; const Index: Integer; const Value: String); overload;
procedure ReleaseSQL(Query: TSQLiteQuery);
- function GetUniTable(const SQL: string): TSQLiteUniTable; overload;
- function GetUniTable(const SQL: string; const Bindings: array of const): TSQLiteUniTable; overload;
- function GetTableValue(const SQL: string): int64; overload;
- function GetTableValue(const SQL: string; const Bindings: array of const): int64; overload;
- function GetTableString(const SQL: string): string; overload;
- function GetTableString(const SQL: string; const Bindings: array of const): string; overload;
- procedure GetTableStrings(const SQL: string; const Value: TStrings);
- procedure UpdateBlob(const SQL: string; BlobData: TStream);
+ function GetUniTable(const SQL: Ansistring): TSQLiteUniTable; overload;
+ function GetUniTable(const SQL: Ansistring; const Bindings: array of const): TSQLiteUniTable; overload;
+ function GetTableValue(const SQL: Ansistring): int64; overload;
+ function GetTableValue(const SQL: Ansistring; const Bindings: array of const): int64; overload;
+ function GetTableString(const SQL: Ansistring): string; overload;
+ function GetTableString(const SQL: Ansistring; const Bindings: array of const): string; overload;
+ procedure GetTableStrings(const SQL: Ansistring; const Value: TStrings);
+ procedure UpdateBlob(const SQL: Ansistring; BlobData: TStream);
procedure BeginTransaction;
procedure Commit;
procedure Rollback;
@@ -177,8 +177,8 @@ type
function GetCount: integer;
function GetCountResult: integer;
public
- constructor Create(DB: TSQLiteDatabase; const SQL: string); overload;
- constructor Create(DB: TSQLiteDatabase; const SQL: string; const Bindings: array of const); overload;
+ constructor Create(DB: TSQLiteDatabase; const SQL: Ansistring); overload;
+ constructor Create(DB: TSQLiteDatabase; const SQL: Ansistring; const Bindings: array of const); overload;
destructor Destroy; override;
function FieldAsInteger(I: cardinal): int64;
function FieldAsBlob(I: cardinal): TMemoryStream;
@@ -221,8 +221,8 @@ type
function GetFieldByName(FieldName: string): string;
function GetFieldIndex(FieldName: string): integer;
public
- constructor Create(DB: TSQLiteDatabase; const SQL: string); overload;
- constructor Create(DB: TSQLiteDatabase; const SQL: string; const Bindings: array of const); overload;
+ constructor Create(DB: TSQLiteDatabase; const SQL: Ansistring); overload;
+ constructor Create(DB: TSQLiteDatabase; const SQL: Ansistring; const Bindings: array of const); overload;
destructor Destroy; override;
function FieldAsInteger(I: cardinal): int64;
function FieldAsBlob(I: cardinal): TMemoryStream;
@@ -243,7 +243,7 @@ type
procedure DisposePointer(ptr: pointer); cdecl;
-{$IFDEF WIN32}
+{$IFDEF MSWINDOWS}
function SystemCollate(Userdta: pointer; Buf1Len: integer; Buf1: pointer;
Buf2Len: integer; Buf2: pointer): integer; cdecl;
{$ENDIF}
@@ -256,7 +256,7 @@ begin
freemem(ptr);
end;
-{$IFDEF WIN32}
+{$IFDEF MSWINDOWS}
function SystemCollate(Userdta: pointer; Buf1Len: integer; Buf1: pointer;
Buf2Len: integer; Buf2: pointer): integer; cdecl;
begin
@@ -271,9 +271,9 @@ end;
constructor TSQLiteDatabase.Create(const FileName: string);
var
- Msg: pchar;
+ Msg: PAnsiChar;
iResult: integer;
- utf8FileName: string;
+ utf8FileName: UTF8string;
begin
inherited Create;
fParams := TList.Create;
@@ -282,8 +282,8 @@ begin
Msg := nil;
try
- utf8FileName := AnsiToUtf8(FileName);
- iResult := SQLite3_Open(PChar(utf8FileName), Fdb);
+ utf8FileName := UTF8String(FileName);
+ iResult := SQLite3_Open(PAnsiChar(utf8FileName), Fdb);
if iResult <> SQLITE_OK then
if Assigned(Fdb) then
@@ -338,7 +338,7 @@ end;
procedure TSQLiteDatabase.RaiseError(s: string; SQL: string);
//look up last error and raise an exception with an appropriate message
var
- Msg: PChar;
+ Msg: PAnsiChar;
ret : integer;
begin
@@ -388,7 +388,7 @@ begin
case Bindings[I].VType of
vtString: begin // ShortString
AnsiStr := Bindings[I].VString^;
- DataPtr := PChar(AnsiStr);
+ DataPtr := PAnsiChar(AnsiStr);
DataSize := Length(AnsiStr)+1;
end;
vtPChar: begin
@@ -396,24 +396,24 @@ begin
DataSize := -1;
end;
vtAnsiString: begin
- AnsiStrPtr := PString(@Bindings[I].VAnsiString);
- DataPtr := PChar(AnsiStrPtr^);
+ AnsiStrPtr := PAnsiString(@Bindings[I].VAnsiString);
+ DataPtr := PAnsiChar(AnsiStrPtr^);
DataSize := Length(AnsiStrPtr^)+1;
end;
vtPWideChar: begin
- DataPtr := PChar(UTF8Encode(WideString(Bindings[I].VPWideChar)));
+ DataPtr := PAnsiChar(UTF8Encode(WideString(Bindings[I].VPWideChar)));
DataSize := -1;
end;
vtWideString: begin
- DataPtr := PChar(UTF8Encode(PWideString(@Bindings[I].VWideString)^));
+ DataPtr := PAnsiChar(UTF8Encode(PWideString(@Bindings[I].VWideString)^));
DataSize := -1;
end;
vtChar: begin
- DataPtr := PChar(String(Bindings[I].VChar));
+ DataPtr := PAnsiChar(String(Bindings[I].VChar));
DataSize := 2;
end;
vtWideChar: begin
- DataPtr := PChar(UTF8Encode(WideString(Bindings[I].VWideChar)));
+ DataPtr := PAnsiChar(UTF8Encode(WideString(Bindings[I].VWideChar)));
DataSize := -1;
end;
else
@@ -449,7 +449,7 @@ begin
if (Bindings[I].VObject is TCustomMemoryStream) then
begin
BlobMemStream := TCustomMemoryStream(Bindings[I].VObject);
- if (sqlite3_bind_blob(Stmt, I+1, @PChar(BlobMemStream.Memory)[BlobMemStream.Position],
+ if (sqlite3_bind_blob(Stmt, I+1, @PAnsiChar(BlobMemStream.Memory)[BlobMemStream.Position],
BlobMemStream.Size-BlobMemStream.Position, SQLITE_STATIC) <> SQLITE_OK) then
begin
RaiseError('Could not bind BLOB', 'BindData');
@@ -481,19 +481,19 @@ begin
end;
end;
-procedure TSQLiteDatabase.ExecSQL(const SQL: string);
+procedure TSQLiteDatabase.ExecSQL(const SQL: Ansistring);
begin
ExecSQL(SQL, []);
end;
-procedure TSQLiteDatabase.ExecSQL(const SQL: string; const Bindings: array of const);
+procedure TSQLiteDatabase.ExecSQL(const SQL: Ansistring; const Bindings: array of const);
var
Stmt: TSQLiteStmt;
- NextSQLStatement: Pchar;
+ NextSQLStatement: PAnsiChar;
iStepResult: integer;
begin
try
- if Sqlite3_Prepare_v2(self.fDB, PChar(SQL), -1, Stmt, NextSQLStatement) <>
+ if Sqlite3_Prepare_v2(self.fDB, PAnsiChar(SQL), -1, Stmt, NextSQLStatement) <>
SQLITE_OK then
RaiseError('Error executing SQL', SQL);
if (Stmt = nil) then
@@ -534,15 +534,15 @@ end;
{$WARNINGS ON}
{$WARNINGS OFF}
-function TSQLiteDatabase.PrepareSQL(const SQL: string): TSQLiteQuery;
+function TSQLiteDatabase.PrepareSQL(const SQL: Ansistring): TSQLiteQuery;
var
Stmt: TSQLiteStmt;
- NextSQLStatement: Pchar;
+ NextSQLStatement: PAnsiChar;
begin
Result.SQL := SQL;
Result.Statement := nil;
- if Sqlite3_Prepare(self.fDB, PChar(SQL), -1, Stmt, NextSQLStatement) <>
+ if Sqlite3_Prepare(self.fDB, PAnsiChar(SQL), -1, Stmt, NextSQLStatement) <>
SQLITE_OK then
RaiseError('Error executing SQL', SQL)
else
@@ -568,7 +568,7 @@ end;
procedure TSQLiteDatabase.BindSQL(Query: TSQLiteQuery; const Index: Integer; const Value: String);
begin
if Assigned(Query.Statement) then
- Sqlite3_Bind_Text(Query.Statement, Index, PChar(Value), Length(Value), Pointer(SQLITE_STATIC))
+ Sqlite3_Bind_Text(Query.Statement, Index, PAnsiChar(Value), Length(Value), Pointer(SQLITE_STATIC))
else
RaiseError('Could not bind string to prepared SQL statement', Query.SQL);
end;
@@ -587,13 +587,13 @@ begin
end;
{$WARNINGS ON}
-procedure TSQLiteDatabase.UpdateBlob(const SQL: string; BlobData: TStream);
+procedure TSQLiteDatabase.UpdateBlob(const SQL: Ansistring; BlobData: TStream);
var
iSize: integer;
ptr: pointer;
Stmt: TSQLiteStmt;
- Msg: Pchar;
- NextSQLStatement: Pchar;
+ Msg: PAnsiChar;
+ NextSQLStatement: PAnsiChar;
iStepResult: integer;
iBindResult: integer;
begin
@@ -604,7 +604,7 @@ begin
Msg := nil;
try
- if Sqlite3_Prepare_v2(self.fDB, PChar(SQL), -1, Stmt, NextSQLStatement) <>
+ if Sqlite3_Prepare_v2(self.fDB, PAnsiChar(SQL), -1, Stmt, NextSQLStatement) <>
SQLITE_OK then
RaiseError('Could not prepare SQL statement', SQL);
@@ -650,32 +650,32 @@ end;
//..............................................................................
-function TSQLiteDatabase.GetTable(const SQL: string): TSQLiteTable;
+function TSQLiteDatabase.GetTable(const SQL: Ansistring): TSQLiteTable;
begin
Result := TSQLiteTable.Create(Self, SQL);
end;
-function TSQLiteDatabase.GetTable(const SQL: string; const Bindings: array of const): TSQLiteTable;
+function TSQLiteDatabase.GetTable(const SQL: Ansistring; const Bindings: array of const): TSQLiteTable;
begin
Result := TSQLiteTable.Create(Self, SQL, Bindings);
end;
-function TSQLiteDatabase.GetUniTable(const SQL: string): TSQLiteUniTable;
+function TSQLiteDatabase.GetUniTable(const SQL: Ansistring): TSQLiteUniTable;
begin
Result := TSQLiteUniTable.Create(Self, SQL);
end;
-function TSQLiteDatabase.GetUniTable(const SQL: string; const Bindings: array of const): TSQLiteUniTable;
+function TSQLiteDatabase.GetUniTable(const SQL: Ansistring; const Bindings: array of const): TSQLiteUniTable;
begin
Result := TSQLiteUniTable.Create(Self, SQL, Bindings);
end;
-function TSQLiteDatabase.GetTableValue(const SQL: string): int64;
+function TSQLiteDatabase.GetTableValue(const SQL: Ansistring): int64;
begin
Result := GetTableValue(SQL, []);
end;
-function TSQLiteDatabase.GetTableValue(const SQL: string; const Bindings: array of const): int64;
+function TSQLiteDatabase.GetTableValue(const SQL: Ansistring; const Bindings: array of const): int64;
var
Table: TSQLiteUniTable;
begin
@@ -689,12 +689,12 @@ begin
end;
end;
-function TSQLiteDatabase.GetTableString(const SQL: string): String;
+function TSQLiteDatabase.GetTableString(const SQL: Ansistring): String;
begin
Result := GetTableString(SQL, []);
end;
-function TSQLiteDatabase.GetTableString(const SQL: string; const Bindings: array of const): String;
+function TSQLiteDatabase.GetTableString(const SQL: Ansistring; const Bindings: array of const): String;
var
Table: TSQLiteUniTable;
begin
@@ -708,7 +708,7 @@ begin
end;
end;
-procedure TSQLiteDatabase.GetTableStrings(const SQL: string;
+procedure TSQLiteDatabase.GetTableStrings(const SQL: Ansistring;
const Value: TStrings);
var
Table: TSQLiteUniTable;
@@ -778,12 +778,12 @@ end;
procedure TSQLiteDatabase.AddCustomCollate(name: string;
xCompare: TCollateXCompare);
begin
- sqlite3_create_collation(fdb, PChar(name), SQLITE_UTF8, nil, xCompare);
+ sqlite3_create_collation(fdb, PAnsiChar(name), SQLITE_UTF8, nil, xCompare);
end;
procedure TSQLiteDatabase.AddSystemCollate;
begin
- {$IFDEF WIN32}
+ {$IFDEF MSWINDOWS}
sqlite3_create_collation(fdb, 'SYSTEM', SQLITE_UTF16LE, nil, @SystemCollate);
{$ENDIF}
end;
@@ -850,7 +850,7 @@ begin
for n := 0 to fParams.Count - 1 do
begin
par := TSQliteParam(fParams[n]);
- i := sqlite3_bind_parameter_index(Stmt, PChar(par.name));
+ i := sqlite3_bind_parameter_index(Stmt, PAnsiChar(par.name));
if i > 0 then
begin
case par.valuetype of
@@ -859,7 +859,7 @@ begin
SQLITE_FLOAT:
sqlite3_bind_double(Stmt, i, par.valuefloat);
SQLITE_TEXT:
- sqlite3_bind_text(Stmt, i, pchar(par.valuedata),
+ sqlite3_bind_text(Stmt, i, PAnsiChar(par.valuedata),
length(par.valuedata), SQLITE_TRANSIENT);
SQLITE_NULL:
sqlite3_bind_null(Stmt, i);
@@ -887,15 +887,15 @@ end;
// TSQLiteTable
//------------------------------------------------------------------------------
-constructor TSQLiteTable.Create(DB: TSQLiteDatabase; const SQL: string);
+constructor TSQLiteTable.Create(DB: TSQLiteDatabase; const SQL: Ansistring);
begin
Create(DB, SQL, []);
end;
-constructor TSQLiteTable.Create(DB: TSQLiteDatabase; const SQL: string; const Bindings: array of const);
+constructor TSQLiteTable.Create(DB: TSQLiteDatabase; const SQL: Ansistring; const Bindings: array of const);
var
Stmt: TSQLiteStmt;
- NextSQLStatement: Pchar;
+ NextSQLStatement: PAnsiChar;
iStepResult: integer;
ptr: pointer;
iNumBytes: integer;
@@ -905,9 +905,9 @@ var
thisIntValue: pInt64;
thisColType: pInteger;
i: integer;
- DeclaredColType: Pchar;
+ DeclaredColType: PAnsiChar;
ActualColType: integer;
- ptrValue: Pchar;
+ ptrValue: PAnsiChar;
begin
inherited create;
try
@@ -915,7 +915,7 @@ begin
self.fColCount := 0;
//if there are several SQL statements in SQL, NextSQLStatment points to the
//beginning of the next one. Prepare only prepares the first SQL statement.
- if Sqlite3_Prepare_v2(DB.fDB, PChar(SQL), -1, Stmt, NextSQLStatement) <> SQLITE_OK then
+ if Sqlite3_Prepare_v2(DB.fDB, PAnsiChar(SQL), -1, Stmt, NextSQLStatement) <> SQLITE_OK then
DB.RaiseError('Error executing SQL', SQL);
if (Stmt = nil) then
DB.RaiseError('Could not prepare SQL statement', SQL);
@@ -1177,24 +1177,27 @@ end;
function TSqliteTable.FieldAsBlobText(I: cardinal): string;
var
MemStream: TMemoryStream;
- Buffer: PChar;
+ Buffer: PAnsiChar;
begin
Result := '';
MemStream := self.FieldAsBlob(I);
if MemStream <> nil then
- try
- if MemStream.Size > 0 then
+ if MemStream.Size > 0 then
begin
MemStream.position := 0;
- Buffer := stralloc(MemStream.Size + 1);
+ {$IFDEF UNICODE}
+ Buffer := AnsiStralloc(MemStream.Size + 1);
+ {$ELSE}
+ Buffer := Stralloc(MemStream.Size + 1);
+ {$ENDIF}
MemStream.readbuffer(Buffer[0], MemStream.Size);
(Buffer + MemStream.Size)^ := chr(0);
SetString(Result, Buffer, MemStream.size);
strdispose(Buffer);
end;
- finally
- MemStream.free;
- end;
+ //do not free the TMemoryStream here; it is freed when
+ //TSqliteTable is destroyed
+
end;
@@ -1308,17 +1311,15 @@ end;
{ TSQLiteUniTable }
-constructor TSQLiteUniTable.Create(DB: TSQLiteDatabase; const SQL: string);
+constructor TSQLiteUniTable.Create(DB: TSQLiteDatabase; const SQL: Ansistring);
begin
Create(DB, SQL, []);
end;
-constructor TSQLiteUniTable.Create(DB: TSQLiteDatabase; const SQL: string; const Bindings: array of const);
+constructor TSQLiteUniTable.Create(DB: TSQLiteDatabase; const SQL: Ansistring; const Bindings: array of const);
var
- NextSQLStatement: Pchar;
- thisColType: pInteger;
+ NextSQLStatement: PAnsiChar;
i: integer;
- DeclaredColType: Pchar;
begin
inherited create;
self.fDB := db;
@@ -1326,7 +1327,7 @@ begin
self.fRow := 0;
self.fColCount := 0;
self.fSQL := SQL;
- if Sqlite3_Prepare_v2(DB.fDB, PChar(SQL), -1, fStmt, NextSQLStatement) <> SQLITE_OK then
+ if Sqlite3_Prepare_v2(DB.fDB, PAnsiChar(SQL), -1, fStmt, NextSQLStatement) <> SQLITE_OK then
DB.RaiseError('Error executing SQL', SQL);
if (fStmt = nil) then
DB.RaiseError('Could not prepare SQL statement', SQL);
@@ -1344,8 +1345,6 @@ begin
end;
destructor TSQLiteUniTable.Destroy;
-var
- i: integer;
begin
if Assigned(fStmt) then
Sqlite3_Finalize(fstmt);
@@ -1378,7 +1377,7 @@ end;
function TSQLiteUniTable.FieldAsBlobText(I: cardinal): string;
var
MemStream: TMemoryStream;
- Buffer: PChar;
+ Buffer: PAnsiChar;
begin
Result := '';
MemStream := self.FieldAsBlob(I);
@@ -1387,7 +1386,11 @@ begin
if MemStream.Size > 0 then
begin
MemStream.position := 0;
- Buffer := stralloc(MemStream.Size + 1);
+ {$IFDEF UNICODE}
+ Buffer := AnsiStralloc(MemStream.Size + 1);
+ {$ELSE}
+ Buffer := Stralloc(MemStream.Size + 1);
+ {$ENDIF}
MemStream.readbuffer(Buffer[0], MemStream.Size);
(Buffer + MemStream.Size)^ := chr(0);
SetString(Result, Buffer, MemStream.size);