mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-15 18:49:16 +02:00
Change variables from PChar to PAnsiChar
Change FileName to UTF8String git-svn-id: trunk@29374 -
This commit is contained in:
parent
cc537a2e76
commit
d0c8c121ab
@ -45,15 +45,12 @@ const
|
|||||||
DefaultStringSize = 255;
|
DefaultStringSize = 255;
|
||||||
|
|
||||||
type
|
type
|
||||||
{$if defined(ver2_6_0) or defined(ver2_4)}
|
|
||||||
TRecordBuffer = PAnsiChar;
|
|
||||||
{$endif}
|
|
||||||
TCustomSqliteDataset = class;
|
TCustomSqliteDataset = class;
|
||||||
|
|
||||||
PDataRecord = ^DataRecord;
|
PDataRecord = ^DataRecord;
|
||||||
PPDataRecord = ^PDataRecord;
|
PPDataRecord = ^PDataRecord;
|
||||||
DataRecord = record
|
DataRecord = record
|
||||||
Row: PPChar;
|
Row: PPAnsiChar;
|
||||||
BookmarkFlag: TBookmarkFlag;
|
BookmarkFlag: TBookmarkFlag;
|
||||||
Next: PDataRecord;
|
Next: PDataRecord;
|
||||||
Previous: PDataRecord;
|
Previous: PDataRecord;
|
||||||
@ -65,7 +62,7 @@ type
|
|||||||
private
|
private
|
||||||
FEditItem: PDataRecord;
|
FEditItem: PDataRecord;
|
||||||
FDataset: TCustomSqliteDataset;
|
FDataset: TCustomSqliteDataset;
|
||||||
FFieldRow: PChar;
|
FFieldRow: PAnsiChar;
|
||||||
FField: TField;
|
FField: TField;
|
||||||
FFieldOffset: Integer;
|
FFieldOffset: Integer;
|
||||||
FRowSize: Int64;
|
FRowSize: Int64;
|
||||||
@ -84,8 +81,8 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
//callback types
|
//callback types
|
||||||
TSqliteCdeclCallback = function(UserData: Pointer; Count: LongInt; Values: PPChar; Names: PPChar): LongInt; cdecl;
|
TSqliteCdeclCallback = function(UserData: Pointer; Count: LongInt; Values: PPAnsiChar; Names: PPAnsiChar): LongInt; cdecl;
|
||||||
TSqliteCallback = function(UserData: Pointer; Count: LongInt; Values: PPChar; Names: PPChar): LongInt of object;
|
TSqliteCallback = function(UserData: Pointer; Count: LongInt; Values: PPAnsiChar; Names: PPAnsiChar): LongInt of object;
|
||||||
TCallbackInfo = record
|
TCallbackInfo = record
|
||||||
Proc: TSqliteCallback;
|
Proc: TSqliteCallback;
|
||||||
Data: Pointer;
|
Data: Pointer;
|
||||||
@ -94,9 +91,9 @@ type
|
|||||||
|
|
||||||
TRecordState = (rsAdded, rsDeleted, rsUpdated);
|
TRecordState = (rsAdded, rsDeleted, rsUpdated);
|
||||||
TRecordStateSet = set of TRecordState;
|
TRecordStateSet = set of TRecordState;
|
||||||
TQueryUpdatesCallback = procedure(UserData: Pointer; Values: PPChar; ABookmark: TBookmark; RecordState: TRecordState) of object;
|
TQueryUpdatesCallback = procedure(UserData: Pointer; Values: PPAnsiChar; ABookmark: TBookmark; RecordState: TRecordState) of object;
|
||||||
|
|
||||||
TGetSqlStrFunction = function(APChar: PChar): String;
|
TGetSqlStrFunction = function(APChar: PAnsiChar): String;
|
||||||
|
|
||||||
TSqliteOption = (soWildcardKey);
|
TSqliteOption = (soWildcardKey);
|
||||||
TSqliteOptions = set of TSqliteOption;
|
TSqliteOptions = set of TSqliteOption;
|
||||||
@ -132,7 +129,7 @@ type
|
|||||||
protected
|
protected
|
||||||
FPrimaryKey: String;
|
FPrimaryKey: String;
|
||||||
FPrimaryKeyNo: Integer;
|
FPrimaryKeyNo: Integer;
|
||||||
FFileName: String;
|
FFileName: UTF8String;
|
||||||
FSQL: String;
|
FSQL: String;
|
||||||
FEffectiveSQL: String;
|
FEffectiveSQL: String;
|
||||||
FTableName: String;
|
FTableName: String;
|
||||||
@ -156,7 +153,7 @@ type
|
|||||||
FSaveOnRefetch: Boolean;
|
FSaveOnRefetch: Boolean;
|
||||||
FAutoIncrementKey: Boolean;
|
FAutoIncrementKey: Boolean;
|
||||||
FDataAllocated: Boolean;
|
FDataAllocated: Boolean;
|
||||||
function SqliteExec(Sql: PChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer; virtual; abstract;
|
function SqliteExec(Sql: PAnsiChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer; virtual; abstract;
|
||||||
procedure InternalCloseHandle; virtual; abstract;
|
procedure InternalCloseHandle; virtual; abstract;
|
||||||
function InternalGetHandle: Pointer; virtual; abstract;
|
function InternalGetHandle: Pointer; virtual; abstract;
|
||||||
function FieldDefsStored: Boolean;
|
function FieldDefsStored: Boolean;
|
||||||
@ -171,7 +168,7 @@ type
|
|||||||
function GetMasterFields: String;
|
function GetMasterFields: String;
|
||||||
procedure SetMasterSource(Value: TDataSource);
|
procedure SetMasterSource(Value: TDataSource);
|
||||||
function GetMasterSource: TDataSource;
|
function GetMasterSource: TDataSource;
|
||||||
procedure SetFileName(const Value: String);
|
procedure SetFileName(const Value: UTF8String);
|
||||||
function GetRowsAffected: Integer; virtual; abstract;
|
function GetRowsAffected: Integer; virtual; abstract;
|
||||||
procedure RetrieveFieldDefs; virtual; abstract;
|
procedure RetrieveFieldDefs; virtual; abstract;
|
||||||
//TDataSet overrides
|
//TDataSet overrides
|
||||||
@ -231,7 +228,7 @@ type
|
|||||||
procedure ExecSQL(ASqlList: TStrings);
|
procedure ExecSQL(ASqlList: TStrings);
|
||||||
procedure ExecSQLList;
|
procedure ExecSQLList;
|
||||||
procedure ExecuteDirect(const ASql: String); virtual; abstract;
|
procedure ExecuteDirect(const ASql: String); virtual; abstract;
|
||||||
function GetSQLValue(Values: PPChar; FieldIndex: Integer): String;
|
function GetSQLValue(Values: PPAnsiChar; FieldIndex: Integer): String;
|
||||||
procedure QueryUpdates(RecordStates: TRecordStateSet; Callback: TQueryUpdatesCallback; UserData: Pointer = nil);
|
procedure QueryUpdates(RecordStates: TRecordStateSet; Callback: TQueryUpdatesCallback; UserData: Pointer = nil);
|
||||||
function QuickQuery(const ASql: String):String;overload;
|
function QuickQuery(const ASql: String):String;overload;
|
||||||
function QuickQuery(const ASql: String; const AStrList: TStrings): String; overload;
|
function QuickQuery(const ASql: String; const AStrList: TStrings): String; overload;
|
||||||
@ -258,7 +255,7 @@ type
|
|||||||
published
|
published
|
||||||
property AutoIncrementKey: Boolean read FAutoIncrementKey write FAutoIncrementKey default False;
|
property AutoIncrementKey: Boolean read FAutoIncrementKey write FAutoIncrementKey default False;
|
||||||
property IndexFieldNames: string read FIndexFieldNames write FIndexFieldNames;
|
property IndexFieldNames: string read FIndexFieldNames write FIndexFieldNames;
|
||||||
property FileName: String read FFileName write SetFileName;
|
property FileName: UTF8String read FFileName write SetFileName;
|
||||||
property OnCallback: TSqliteCallback read FOnCallback write FOnCallback;
|
property OnCallback: TSqliteCallback read FOnCallback write FOnCallback;
|
||||||
property OnGetHandle: TDataSetNotifyEvent read FOnGetHandle write FOnGetHandle;
|
property OnGetHandle: TDataSetNotifyEvent read FOnGetHandle write FOnGetHandle;
|
||||||
property Options: TSqliteOptions read FOptions write SetOptions default [];
|
property Options: TSqliteOptions read FOptions write SetOptions default [];
|
||||||
@ -299,8 +296,8 @@ type
|
|||||||
property OnPostError;
|
property OnPostError;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Num2SQLStr(APChar: PChar): String;
|
function Num2SQLStr(APChar: PAnsiChar): String;
|
||||||
function Char2SQLStr(APChar: PChar): String;
|
function Char2SQLStr(APChar: PAnsiChar): String;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -316,13 +313,13 @@ const
|
|||||||
NullString = 'NULL';
|
NullString = 'NULL';
|
||||||
|
|
||||||
|
|
||||||
function CallbackDispatcher(UserData: Pointer; Count: LongInt; Values: PPchar; Names: PPchar): LongInt; cdecl;
|
function CallbackDispatcher(UserData: Pointer; Count: LongInt; Values: PPAnsiChar; Names: PPAnsiChar): LongInt; cdecl;
|
||||||
begin
|
begin
|
||||||
with PCallbackInfo(UserData)^ do
|
with PCallbackInfo(UserData)^ do
|
||||||
Result:= Proc(Data, Count, Values, Names);
|
Result:= Proc(Data, Count, Values, Names);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Num2SQLStr(APChar: PChar): String;
|
function Num2SQLStr(APChar: PAnsiChar): String;
|
||||||
begin
|
begin
|
||||||
if APChar = nil then
|
if APChar = nil then
|
||||||
begin
|
begin
|
||||||
@ -332,14 +329,14 @@ begin
|
|||||||
Result := String(APChar);
|
Result := String(APChar);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Char2SQLStr(APChar: PChar): String;
|
function Char2SQLStr(APChar: PAnsiChar): String;
|
||||||
begin
|
begin
|
||||||
if APChar = nil then
|
if APChar = nil then
|
||||||
begin
|
begin
|
||||||
Result := NullString;
|
Result := NullString;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
//todo: create custom routine to directly transform PChar -> SQL str
|
//todo: create custom routine to directly transform PAnsiChar -> SQL str
|
||||||
Result := String(APChar);
|
Result := String(APChar);
|
||||||
if Pos('''', Result) > 0 then
|
if Pos('''', Result) > 0 then
|
||||||
Result := AnsiReplaceStr(Result, '''', '''''');
|
Result := AnsiReplaceStr(Result, '''', '''''');
|
||||||
@ -394,7 +391,7 @@ end;
|
|||||||
|
|
||||||
function TDSStream.Write(const Buffer; Count: LongInt): LongInt;
|
function TDSStream.Write(const Buffer; Count: LongInt): LongInt;
|
||||||
var
|
var
|
||||||
NewRow: PChar;
|
NewRow: PAnsiChar;
|
||||||
begin
|
begin
|
||||||
Result := Count;
|
Result := Count;
|
||||||
if Count > 0 then
|
if Count > 0 then
|
||||||
@ -703,7 +700,7 @@ function TCustomSqliteDataset.GetFieldData(Field: TField; Buffer: Pointer;
|
|||||||
NativeFormat: Boolean): Boolean;
|
NativeFormat: Boolean): Boolean;
|
||||||
var
|
var
|
||||||
ValError: Word;
|
ValError: Word;
|
||||||
FieldRow: PChar;
|
FieldRow: PAnsiChar;
|
||||||
FieldOffset: Integer;
|
FieldOffset: Integer;
|
||||||
begin
|
begin
|
||||||
if Field.FieldNo >= 0 then
|
if Field.FieldNo >= 0 then
|
||||||
@ -722,7 +719,7 @@ begin
|
|||||||
case Field.Datatype of
|
case Field.Datatype of
|
||||||
ftString:
|
ftString:
|
||||||
begin
|
begin
|
||||||
Move(FieldRow^, PChar(Buffer)^, StrLen(FieldRow) + 1);
|
Move(FieldRow^, PAnsiChar(Buffer)^, StrLen(FieldRow) + 1);
|
||||||
end;
|
end;
|
||||||
ftInteger, ftAutoInc:
|
ftInteger, ftAutoInc:
|
||||||
begin
|
begin
|
||||||
@ -1023,7 +1020,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
TLocateCompareFunction = function (Value: PChar; const Key: String): Boolean;
|
TLocateCompareFunction = function (Value: PAnsiChar; const Key: String): Boolean;
|
||||||
|
|
||||||
TLocateFieldInfo = record
|
TLocateFieldInfo = record
|
||||||
Index: Integer;
|
Index: Integer;
|
||||||
@ -1031,7 +1028,7 @@ type
|
|||||||
CompFunction: TLocateCompareFunction;
|
CompFunction: TLocateCompareFunction;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompInsensitivePartial(UTF8Value: PChar; const AnsiKey: String): Boolean;
|
function CompInsensitivePartial(UTF8Value: PAnsiChar; const AnsiKey: String): Boolean;
|
||||||
var
|
var
|
||||||
AnsiValue: AnsiString;
|
AnsiValue: AnsiString;
|
||||||
begin
|
begin
|
||||||
@ -1039,21 +1036,21 @@ begin
|
|||||||
if UTF8Value <> nil then
|
if UTF8Value <> nil then
|
||||||
begin
|
begin
|
||||||
AnsiValue := UTF8Decode(UTF8Value);
|
AnsiValue := UTF8Decode(UTF8Value);
|
||||||
Result := AnsiStrLIComp(PChar(AnsiValue), PChar(AnsiKey), Length(AnsiKey)) = 0;
|
Result := AnsiStrLIComp(PAnsiChar(AnsiValue), PAnsiChar(AnsiKey), Length(AnsiKey)) = 0;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompSensitivePartial(UTF8Value: PChar; const UTF8Key: String): Boolean;
|
function CompSensitivePartial(UTF8Value: PAnsiChar; const UTF8Key: String): Boolean;
|
||||||
begin
|
begin
|
||||||
if UTF8Value <> nil then
|
if UTF8Value <> nil then
|
||||||
Result := StrLComp(UTF8Value, PChar(UTF8Key), Length(UTF8Key)) = 0
|
Result := StrLComp(UTF8Value, PAnsiChar(UTF8Key), Length(UTF8Key)) = 0
|
||||||
else
|
else
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompInsensitive(UTF8Value: PChar; const AnsiKey: String): Boolean;
|
function CompInsensitive(UTF8Value: PAnsiChar; const AnsiKey: String): Boolean;
|
||||||
begin
|
begin
|
||||||
//fpc does not provide a function to compare UTF8 directly, so convert the
|
//fpc does not provide a function to compare UTF8 directly, so convert the
|
||||||
//UTF8Value string to ansi through a temporary widestring and compare with the
|
//UTF8Value string to ansi through a temporary widestring and compare with the
|
||||||
@ -1067,15 +1064,15 @@ begin
|
|||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompSensitive(UTF8Value: PChar; const UTF8Key: String): Boolean;
|
function CompSensitive(UTF8Value: PAnsiChar; const UTF8Key: String): Boolean;
|
||||||
begin
|
begin
|
||||||
if UTF8Value <> nil then
|
if UTF8Value <> nil then
|
||||||
Result := StrComp(UTF8Value, PChar(UTF8Key)) = 0
|
Result := StrComp(UTF8Value, PAnsiChar(UTF8Key)) = 0
|
||||||
else
|
else
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompSensitiveWild(UTF8Value: PChar; const UTF8Key: String): Boolean;
|
function CompSensitiveWild(UTF8Value: PAnsiChar; const UTF8Key: String): Boolean;
|
||||||
begin
|
begin
|
||||||
if UTF8Value <> nil then
|
if UTF8Value <> nil then
|
||||||
Result := IsWild(String(UTF8Value), UTF8Key, False)
|
Result := IsWild(String(UTF8Value), UTF8Key, False)
|
||||||
@ -1083,7 +1080,7 @@ begin
|
|||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompDouble(UTF8Value: PChar; const UTF8Key: String): Boolean;
|
function CompDouble(UTF8Value: PAnsiChar; const UTF8Key: String): Boolean;
|
||||||
var e1,e2:double;
|
var e1,e2:double;
|
||||||
begin
|
begin
|
||||||
if UTF8Value <> nil then
|
if UTF8Value <> nil then
|
||||||
@ -1096,7 +1093,7 @@ begin
|
|||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompInsensitiveWild(UTF8Value: PChar; const AnsiKey: String): Boolean;
|
function CompInsensitiveWild(UTF8Value: PAnsiChar; const AnsiKey: String): Boolean;
|
||||||
begin
|
begin
|
||||||
//IsWild does not work with UTF8 encoded strings for case insensitive searches,
|
//IsWild does not work with UTF8 encoded strings for case insensitive searches,
|
||||||
//so convert UTF8Value to the system ansi encoding before passing to IsWild.
|
//so convert UTF8Value to the system ansi encoding before passing to IsWild.
|
||||||
@ -1363,13 +1360,13 @@ begin
|
|||||||
case Field.Datatype of
|
case Field.Datatype of
|
||||||
ftString:
|
ftString:
|
||||||
begin
|
begin
|
||||||
EditItem^.Row[FieldOffset] := StrNew(PChar(Buffer));
|
EditItem^.Row[FieldOffset] := StrNew(PAnsiChar(Buffer));
|
||||||
end;
|
end;
|
||||||
ftInteger:
|
ftInteger:
|
||||||
begin
|
begin
|
||||||
Str(LongInt(Buffer^), TempStr);
|
Str(LongInt(Buffer^), TempStr);
|
||||||
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
||||||
Move(PChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
Move(PAnsiChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
||||||
end;
|
end;
|
||||||
ftBoolean, ftWord:
|
ftBoolean, ftWord:
|
||||||
begin
|
begin
|
||||||
@ -1379,19 +1376,19 @@ begin
|
|||||||
else
|
else
|
||||||
Str(Word(Buffer^), TempStr);
|
Str(Word(Buffer^), TempStr);
|
||||||
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
||||||
Move(PChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
Move(PAnsiChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
||||||
end;
|
end;
|
||||||
ftFloat, ftDateTime, ftDate, ftTime, ftCurrency:
|
ftFloat, ftDateTime, ftDate, ftTime, ftCurrency:
|
||||||
begin
|
begin
|
||||||
Str(Double(Buffer^), TempStr);
|
Str(Double(Buffer^), TempStr);
|
||||||
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
||||||
Move(PChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
Move(PAnsiChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
||||||
end;
|
end;
|
||||||
ftLargeInt:
|
ftLargeInt:
|
||||||
begin
|
begin
|
||||||
Str(Int64(Buffer^), TempStr);
|
Str(Int64(Buffer^), TempStr);
|
||||||
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
EditItem^.Row[FieldOffset] := StrAlloc(Length(TempStr) + 1);
|
||||||
Move(PChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
Move(PAnsiChar(TempStr)^, (EditItem^.Row[FieldOffset])^, Length(TempStr) + 1);
|
||||||
end;
|
end;
|
||||||
end;// case
|
end;// case
|
||||||
end//if
|
end//if
|
||||||
@ -1517,7 +1514,7 @@ begin
|
|||||||
Result := FMasterLink.DataSource;
|
Result := FMasterLink.DataSource;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomSqliteDataset.SetFileName(const Value: String);
|
procedure TCustomSqliteDataset.SetFileName(const Value: UTF8String);
|
||||||
begin
|
begin
|
||||||
if Value <> FFileName then
|
if Value <> FFileName then
|
||||||
begin
|
begin
|
||||||
@ -1545,7 +1542,7 @@ procedure TCustomSqliteDataset.ExecSQL(ASqlList: TStrings);
|
|||||||
begin
|
begin
|
||||||
if FSqliteHandle = nil then
|
if FSqliteHandle = nil then
|
||||||
GetSqliteHandle;
|
GetSqliteHandle;
|
||||||
FReturnCode := SqliteExec(PChar(ASQLList.Text), nil, nil);
|
FReturnCode := SqliteExec(PAnsiChar(ASQLList.Text), nil, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
end;
|
end;
|
||||||
@ -1555,7 +1552,7 @@ begin
|
|||||||
ExecSQL(SQLList);
|
ExecSQL(SQLList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomSqliteDataset.GetSQLValue(Values: PPChar; FieldIndex: Integer): String;
|
function TCustomSqliteDataset.GetSQLValue(Values: PPAnsiChar; FieldIndex: Integer): String;
|
||||||
begin
|
begin
|
||||||
if (State = dsInactive) or (FieldIndex < 0) or (FieldIndex >= FieldDefs.Count) then
|
if (State = dsInactive) or (FieldIndex < 0) or (FieldIndex >= FieldDefs.Count) then
|
||||||
DatabaseError('Error retrieving SQL value: dataset inactive or field out of range', Self);
|
DatabaseError('Error retrieving SQL value: dataset inactive or field out of range', Self);
|
||||||
@ -1615,7 +1612,7 @@ begin
|
|||||||
if StatementsCounter = 400 then
|
if StatementsCounter = 400 then
|
||||||
begin
|
begin
|
||||||
SQLTemp := SQLTemp + 'COMMIT;';
|
SQLTemp := SQLTemp + 'COMMIT;';
|
||||||
FReturnCode := SqliteExec(PChar(SQLTemp), nil, nil);
|
FReturnCode := SqliteExec(PAnsiChar(SQLTemp), nil, nil);
|
||||||
StatementsCounter := 0;
|
StatementsCounter := 0;
|
||||||
SQLTemp := 'BEGIN;';
|
SQLTemp := 'BEGIN;';
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
@ -1649,7 +1646,7 @@ begin
|
|||||||
if StatementsCounter = 400 then
|
if StatementsCounter = 400 then
|
||||||
begin
|
begin
|
||||||
SQLTemp := SQLTemp + 'COMMIT;';
|
SQLTemp := SQLTemp + 'COMMIT;';
|
||||||
FReturnCode := SqliteExec(PChar(SQLTemp), nil, nil);
|
FReturnCode := SqliteExec(PAnsiChar(SQLTemp), nil, nil);
|
||||||
StatementsCounter := 0;
|
StatementsCounter := 0;
|
||||||
SQLTemp := 'BEGIN;';
|
SQLTemp := 'BEGIN;';
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
@ -1681,7 +1678,7 @@ begin
|
|||||||
if StatementsCounter = 400 then
|
if StatementsCounter = 400 then
|
||||||
begin
|
begin
|
||||||
SQLTemp := SQLTemp + 'COMMIT;';
|
SQLTemp := SQLTemp + 'COMMIT;';
|
||||||
FReturnCode := SqliteExec(PChar(SQLTemp), nil, nil);
|
FReturnCode := SqliteExec(PAnsiChar(SQLTemp), nil, nil);
|
||||||
StatementsCounter := 0;
|
StatementsCounter := 0;
|
||||||
SQLTemp := 'BEGIN;';
|
SQLTemp := 'BEGIN;';
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
@ -1698,7 +1695,7 @@ begin
|
|||||||
if FReturnCode = SQLITE_OK then
|
if FReturnCode = SQLITE_OK then
|
||||||
begin
|
begin
|
||||||
SQLTemp := SQLTemp + 'COMMIT;';
|
SQLTemp := SQLTemp + 'COMMIT;';
|
||||||
FReturnCode := SqliteExec(PChar(SQLTemp), nil, nil);
|
FReturnCode := SqliteExec(PAnsiChar(SQLTemp), nil, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
SqliteExec('ROLLBACK;', nil, nil);
|
SqliteExec('ROLLBACK;', nil, nil);
|
||||||
end;
|
end;
|
||||||
@ -1802,7 +1799,7 @@ begin
|
|||||||
GetSqliteHandle;
|
GetSqliteHandle;
|
||||||
CallbackInfo.Data := UserData;
|
CallbackInfo.Data := UserData;
|
||||||
CallbackInfo.Proc := FOnCallback;
|
CallbackInfo.Proc := FOnCallback;
|
||||||
SqliteExec(PChar(ASQL), @CallbackDispatcher, @CallbackInfo);
|
SqliteExec(PAnsiChar(ASQL), @CallbackDispatcher, @CallbackInfo);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ type
|
|||||||
procedure InternalCloseHandle; override;
|
procedure InternalCloseHandle; override;
|
||||||
function InternalGetHandle: Pointer; override;
|
function InternalGetHandle: Pointer; override;
|
||||||
procedure RetrieveFieldDefs; override;
|
procedure RetrieveFieldDefs; override;
|
||||||
function SqliteExec(ASQL: PChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer; override;
|
function SqliteExec(ASQL: PAnsiChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer; override;
|
||||||
public
|
public
|
||||||
procedure ExecuteDirect(const ASQL: String); override;
|
procedure ExecuteDirect(const ASQL: String); override;
|
||||||
function QuickQuery(const ASQL: String; const AStrList: TStrings; FillObjects: Boolean): String; override;
|
function QuickQuery(const ASQL: String; const AStrList: TStrings; FillObjects: Boolean): String; override;
|
||||||
@ -101,7 +101,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetAutoIncValue(NextValue: Pointer; Columns: Integer; ColumnValues: PPChar; ColumnNames: PPChar): Integer; cdecl;
|
function GetAutoIncValue(NextValue: Pointer; Columns: Integer; ColumnValues: PPAnsiChar; ColumnNames: PPAnsiChar): Integer; cdecl;
|
||||||
var
|
var
|
||||||
CodeError, TempInt: Integer;
|
CodeError, TempInt: Integer;
|
||||||
begin
|
begin
|
||||||
@ -118,7 +118,7 @@ end;
|
|||||||
|
|
||||||
{ TSqlite3Dataset }
|
{ TSqlite3Dataset }
|
||||||
|
|
||||||
function TSqlite3Dataset.SqliteExec(ASQL: PChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer;
|
function TSqlite3Dataset.SqliteExec(ASQL: PAnsiChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := sqlite3_exec(FSqliteHandle, ASQL, ACallback, Data, nil);
|
Result := sqlite3_exec(FSqliteHandle, ASQL, ACallback, Data, nil);
|
||||||
end;
|
end;
|
||||||
@ -138,7 +138,7 @@ var
|
|||||||
vm: Pointer;
|
vm: Pointer;
|
||||||
ErrorStr: String;
|
ErrorStr: String;
|
||||||
begin
|
begin
|
||||||
sqlite3_open(PChar(FFileName), @Result);
|
sqlite3_open(PAnsiChar(FFileName), @Result);
|
||||||
//sqlite3_open returns SQLITE_OK even for invalid files
|
//sqlite3_open returns SQLITE_OK even for invalid files
|
||||||
//do additional check here
|
//do additional check here
|
||||||
FReturnCode := sqlite3_prepare(Result, CheckFileSql, -1, @vm, nil);
|
FReturnCode := sqlite3_prepare(Result, CheckFileSql, -1, @vm, nil);
|
||||||
@ -163,7 +163,7 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
FAutoIncFieldNo := -1;
|
FAutoIncFieldNo := -1;
|
||||||
FieldDefs.Clear;
|
FieldDefs.Clear;
|
||||||
FReturnCode := sqlite3_prepare(FSqliteHandle, PChar(FEffectiveSQL), -1, @vm, nil);
|
FReturnCode := sqlite3_prepare(FSqliteHandle, PAnsiChar(FEffectiveSQL), -1, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
sqlite3_step(vm);
|
sqlite3_step(vm);
|
||||||
@ -263,7 +263,7 @@ procedure TSqlite3Dataset.ExecuteDirect(const ASQL: String);
|
|||||||
var
|
var
|
||||||
vm: Pointer;
|
vm: Pointer;
|
||||||
begin
|
begin
|
||||||
FReturnCode := sqlite3_prepare(FSqliteHandle, Pchar(ASQL), -1, @vm, nil);
|
FReturnCode := sqlite3_prepare(FSqliteHandle, PAnsiChar(ASQL), -1, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
FReturnCode := sqlite3_step(vm);
|
FReturnCode := sqlite3_step(vm);
|
||||||
@ -278,10 +278,10 @@ var
|
|||||||
begin
|
begin
|
||||||
//Get AutoInc Field initial value
|
//Get AutoInc Field initial value
|
||||||
if FAutoIncFieldNo <> -1 then
|
if FAutoIncFieldNo <> -1 then
|
||||||
sqlite3_exec(FSqliteHandle, PChar('Select Max(' + FieldDefs[FAutoIncFieldNo].Name +
|
sqlite3_exec(FSqliteHandle, PAnsiChar('Select Max(' + FieldDefs[FAutoIncFieldNo].Name +
|
||||||
') from ' + FTableName), @GetAutoIncValue, @FNextAutoInc, nil);
|
') from ' + FTableName), @GetAutoIncValue, @FNextAutoInc, nil);
|
||||||
|
|
||||||
FReturnCode := sqlite3_prepare(FSqliteHandle, PChar(FEffectiveSQL), -1, @vm, nil);
|
FReturnCode := sqlite3_prepare(FSqliteHandle, PAnsiChar(FEffectiveSQL), -1, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
|
|
||||||
@ -294,7 +294,7 @@ begin
|
|||||||
//add extra rows for calculated fields
|
//add extra rows for calculated fields
|
||||||
if FCalcFieldList <> nil then
|
if FCalcFieldList <> nil then
|
||||||
Inc(FRowCount, FCalcFieldList.Count);
|
Inc(FRowCount, FCalcFieldList.Count);
|
||||||
FRowBufferSize := (SizeOf(PPChar) * FRowCount);
|
FRowBufferSize := (SizeOf(PPAnsiChar) * FRowCount);
|
||||||
FReturnCode := sqlite3_step(vm);
|
FReturnCode := sqlite3_step(vm);
|
||||||
while FReturnCode = SQLITE_ROW do
|
while FReturnCode = SQLITE_ROW do
|
||||||
begin
|
begin
|
||||||
@ -367,7 +367,7 @@ begin
|
|||||||
if FSqliteHandle = nil then
|
if FSqliteHandle = nil then
|
||||||
GetSqliteHandle;
|
GetSqliteHandle;
|
||||||
Result := '';
|
Result := '';
|
||||||
FReturnCode := sqlite3_prepare(FSqliteHandle,Pchar(ASQL), -1, @vm, nil);
|
FReturnCode := sqlite3_prepare(FSqliteHandle,PAnsiChar(ASQL), -1, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ type
|
|||||||
function InternalGetHandle: Pointer; override;
|
function InternalGetHandle: Pointer; override;
|
||||||
procedure InternalCloseHandle; override;
|
procedure InternalCloseHandle; override;
|
||||||
procedure RetrieveFieldDefs; override;
|
procedure RetrieveFieldDefs; override;
|
||||||
function SqliteExec(ASQL: PChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer; override;
|
function SqliteExec(ASQL: PAnsiChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer; override;
|
||||||
public
|
public
|
||||||
procedure ExecuteDirect(const ASQL: String); override;
|
procedure ExecuteDirect(const ASQL: String); override;
|
||||||
function QuickQuery(const ASQL: String; const AStrList: TStrings; FillObjects: Boolean): String; override;
|
function QuickQuery(const ASQL: String; const AStrList: TStrings; FillObjects: Boolean): String; override;
|
||||||
@ -69,7 +69,7 @@ uses
|
|||||||
|
|
||||||
//function sqlite_last_statement_changes(dbhandle:Pointer):longint;cdecl;external 'sqlite' name 'sqlite_last_statement_changes';
|
//function sqlite_last_statement_changes(dbhandle:Pointer):longint;cdecl;external 'sqlite' name 'sqlite_last_statement_changes';
|
||||||
|
|
||||||
function GetAutoIncValue(NextValue: Pointer; Columns: Integer; ColumnValues: PPChar; ColumnNames: PPChar): Integer; cdecl;
|
function GetAutoIncValue(NextValue: Pointer; Columns: Integer; ColumnValues: PPAnsiChar; ColumnNames: PPAnsiChar): Integer; cdecl;
|
||||||
var
|
var
|
||||||
CodeError, TempInt: Integer;
|
CodeError, TempInt: Integer;
|
||||||
begin
|
begin
|
||||||
@ -86,7 +86,7 @@ end;
|
|||||||
|
|
||||||
{ TSqliteDataset }
|
{ TSqliteDataset }
|
||||||
|
|
||||||
function TSqliteDataset.SqliteExec(ASQL: PChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer;
|
function TSqliteDataset.SqliteExec(ASQL: PAnsiChar; ACallback: TSqliteCdeclCallback; Data: Pointer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := sqlite_exec(FSqliteHandle, ASQL, ACallback, Data, nil);
|
Result := sqlite_exec(FSqliteHandle, ASQL, ACallback, Data, nil);
|
||||||
end;
|
end;
|
||||||
@ -99,9 +99,9 @@ end;
|
|||||||
|
|
||||||
function TSqliteDataset.InternalGetHandle: Pointer;
|
function TSqliteDataset.InternalGetHandle: Pointer;
|
||||||
var
|
var
|
||||||
ErrorStr: PChar;
|
ErrorStr: PAnsiChar;
|
||||||
begin
|
begin
|
||||||
Result := sqlite_open(PChar(FFileName), 0, @ErrorStr);
|
Result := sqlite_open(PAnsiChar(FFileName), 0, @ErrorStr);
|
||||||
if Result = nil then
|
if Result = nil then
|
||||||
begin
|
begin
|
||||||
DatabaseError('Error opening "' + FFileName + '": ' + String(ErrorStr));
|
DatabaseError('Error opening "' + FFileName + '": ' + String(ErrorStr));
|
||||||
@ -114,12 +114,12 @@ var
|
|||||||
ColumnCount, i, DataSize:Integer;
|
ColumnCount, i, DataSize:Integer;
|
||||||
AType: TFieldType;
|
AType: TFieldType;
|
||||||
vm: Pointer;
|
vm: Pointer;
|
||||||
ColumnNames, ColumnValues:PPChar;
|
ColumnNames, ColumnValues:PPAnsiChar;
|
||||||
ColumnStr: String;
|
ColumnStr: String;
|
||||||
begin
|
begin
|
||||||
FieldDefs.Clear;
|
FieldDefs.Clear;
|
||||||
FAutoIncFieldNo := -1;
|
FAutoIncFieldNo := -1;
|
||||||
FReturnCode := sqlite_compile(FSqliteHandle, PChar(FEffectiveSQL), nil, @vm, nil);
|
FReturnCode := sqlite_compile(FSqliteHandle, PAnsiChar(FEffectiveSQL), nil, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
sqlite_step(vm, @ColumnCount, @ColumnValues, @ColumnNames);
|
sqlite_step(vm, @ColumnCount, @ColumnValues, @ColumnNames);
|
||||||
@ -207,10 +207,10 @@ end;
|
|||||||
procedure TSqliteDataset.ExecuteDirect(const ASQL: String);
|
procedure TSqliteDataset.ExecuteDirect(const ASQL: String);
|
||||||
var
|
var
|
||||||
vm: Pointer;
|
vm: Pointer;
|
||||||
ColumnNames, ColumnValues: PPChar;
|
ColumnNames, ColumnValues: PPAnsiChar;
|
||||||
ColCount: Integer;
|
ColCount: Integer;
|
||||||
begin
|
begin
|
||||||
FReturnCode := sqlite_compile(FSqliteHandle, Pchar(ASQL), nil, @vm, nil);
|
FReturnCode := sqlite_compile(FSqliteHandle, PAnsiChar(ASQL), nil, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString,Self);
|
DatabaseError(ReturnString,Self);
|
||||||
|
|
||||||
@ -223,15 +223,15 @@ procedure TSqliteDataset.BuildLinkedList;
|
|||||||
var
|
var
|
||||||
TempItem: PDataRecord;
|
TempItem: PDataRecord;
|
||||||
vm: Pointer;
|
vm: Pointer;
|
||||||
ColumnNames, ColumnValues: PPChar;
|
ColumnNames, ColumnValues: PPAnsiChar;
|
||||||
Counter, ColumnCount: Integer;
|
Counter, ColumnCount: Integer;
|
||||||
begin
|
begin
|
||||||
//Get AutoInc Field initial value
|
//Get AutoInc Field initial value
|
||||||
if FAutoIncFieldNo <> -1 then
|
if FAutoIncFieldNo <> -1 then
|
||||||
sqlite_exec(FSqliteHandle, PChar('Select Max(' + FieldDefs[FAutoIncFieldNo].Name + ') from ' + FTableName),
|
sqlite_exec(FSqliteHandle, PAnsiChar('Select Max(' + FieldDefs[FAutoIncFieldNo].Name + ') from ' + FTableName),
|
||||||
@GetAutoIncValue, @FNextAutoInc, nil);
|
@GetAutoIncValue, @FNextAutoInc, nil);
|
||||||
|
|
||||||
FReturnCode := sqlite_compile(FSqliteHandle, PChar(FEffectiveSQL), nil, @vm, nil);
|
FReturnCode := sqlite_compile(FSqliteHandle, PAnsiChar(FEffectiveSQL), nil, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString, Self);
|
DatabaseError(ReturnString, Self);
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ begin
|
|||||||
//add extra rows for calculated fields
|
//add extra rows for calculated fields
|
||||||
if FCalcFieldList <> nil then
|
if FCalcFieldList <> nil then
|
||||||
Inc(FRowCount, FCalcFieldList.Count);
|
Inc(FRowCount, FCalcFieldList.Count);
|
||||||
FRowBufferSize := (SizeOf(PPChar) * FRowCount);
|
FRowBufferSize := (SizeOf(PPAnsiChar) * FRowCount);
|
||||||
|
|
||||||
while FReturnCode = SQLITE_ROW do
|
while FReturnCode = SQLITE_ROW do
|
||||||
begin
|
begin
|
||||||
@ -339,7 +339,7 @@ end;
|
|||||||
function TSqliteDataset.QuickQuery(const ASQL: String; const AStrList: TStrings; FillObjects: Boolean): String;
|
function TSqliteDataset.QuickQuery(const ASQL: String; const AStrList: TStrings; FillObjects: Boolean): String;
|
||||||
var
|
var
|
||||||
vm: Pointer;
|
vm: Pointer;
|
||||||
ColumnNames, ColumnValues: PPChar;
|
ColumnNames, ColumnValues: PPAnsiChar;
|
||||||
ColCount: Integer;
|
ColCount: Integer;
|
||||||
|
|
||||||
procedure FillStrings;
|
procedure FillStrings;
|
||||||
@ -364,7 +364,7 @@ begin
|
|||||||
if FSqliteHandle = nil then
|
if FSqliteHandle = nil then
|
||||||
GetSqliteHandle;
|
GetSqliteHandle;
|
||||||
Result := '';
|
Result := '';
|
||||||
FReturnCode := sqlite_compile(FSqliteHandle, PChar(ASQL), nil, @vm, nil);
|
FReturnCode := sqlite_compile(FSqliteHandle, PAnsiChar(ASQL), nil, @vm, nil);
|
||||||
if FReturnCode <> SQLITE_OK then
|
if FReturnCode <> SQLITE_OK then
|
||||||
DatabaseError(ReturnString,Self);
|
DatabaseError(ReturnString,Self);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user