Skip to content
Permalink
Browse files

Issue #12:

* define and use SQLite column datatypes, at least the few groups (int, text, real, blob, date)
* TSQLiteConnection.GetThreadId now returns the application process id, as there is no connection pid in SQLite
  • Loading branch information
ansgarbecker committed Dec 25, 2019
1 parent e67ab11 commit ed89b54b287e0e8ffa267fbb7c38da2875af9d82
Showing with 99 additions and 6 deletions.
  1. +9 −6 source/dbconnection.pas
  2. +90 −0 source/dbstructures.pas
@@ -1708,9 +1708,9 @@ constructor TSQLiteConnection.Create(AOwner: TComponent);
inherited;
FQuoteChar := '"';
FQuoteChars := '"';
SetLength(FDatatypes, Length(PostGreSQLDatatypes));
for i:=0 to High(PostGreSQLDatatypes) do
FDatatypes[i] := PostGreSQLDatatypes[i];
SetLength(FDatatypes, Length(SQLiteDatatypes));
for i:=0 to High(SQLiteDatatypes) do
FDatatypes[i] := SQLiteDatatypes[i];
end;


@@ -2988,6 +2988,7 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
NativeSQL: AnsiString;
i: Integer;
Col: TTableColumn;
DataTypeStr: String;
begin
if (FLockedByThread <> nil) and (FLockedByThread.ThreadID <> GetCurrentThreadID) then begin
Log(lcDebug, _('Waiting for running query to finish ...'));
@@ -3028,6 +3029,8 @@ procedure TSQLiteConnection.Query(SQL: String; DoStoreResult: Boolean=False; Log
for i:=0 to FLib.sqlite3_column_count(Statement)-1 do begin
Col := TTableColumn.Create(Self);
Col.Name := DecodeAPIString(FLib.sqlite3_column_name(Statement, i));
DataTypeStr := DecodeAPIString(FLib.sqlite3_column_decltype(Statement, i));
Col.DataType := GetDatatypeByName(DataTypeStr, False);
Rows.Columns.Add(Col);
end;
StepStatus := FLib.sqlite3_step(Statement);
@@ -3657,8 +3660,8 @@ function TSQLiteConnection.GetThreadId: Int64;
begin
if FThreadId = 0 then begin
Ping(False);
if FActive then
FThreadID := 123; // Todo!
if FActive then // We return the application process id, as there is no connection pid in SQLite
FThreadID := Windows.GetCurrentProcessId;
end;
Result := FThreadID;
end;
@@ -5388,7 +5391,7 @@ procedure TSQLiteConnection.FetchDbObjects(db: String; var Cache: TDBObjectList)
obj: TDBObject;
Results: TDBQuery;
begin
// Tables
// Tables, views and procedures
Results := nil;
try
Results := GetResults('SELECT * FROM sqlite_master WHERE type='+EscapeString('table')+' AND name NOT LIKE '+EscapeString('sqlite_%'));
@@ -518,6 +518,7 @@ TSQLiteLib = class(TDbLib)
sqlite3_column_text: function(pStmt: Psqlite3_stmt; iCol: Integer): PAnsiChar; cdecl;
sqlite3_column_count: function(pStmt: Psqlite3_stmt): Integer; cdecl;
sqlite3_column_name: function(pStmt: Psqlite3_stmt; N: Integer): PAnsiChar; cdecl;
sqlite3_column_decltype: function(pStmt: Psqlite3_stmt; N: Integer): PAnsiChar; cdecl;
private
procedure AssignProcedures; override;
end;
@@ -2037,6 +2038,94 @@ TSQLiteLib = class(TDbLib)
)
);

SQLiteDatatypes: Array[0..6] of TDBDatatype =
(
(
Index: dtUnknown;
NativeTypes: '99999';
Name: 'UNKNOWN';
Description: 'Unknown data type';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: False;
LoadPart: False;
Category: dtcOther;
),
(
Index: dtInt;
Name: 'INTEGER';
Names: 'INTEGER|INT|TINYINT|SMALLINT|MEDIUMINT|BIGINT|UNSIGNED BIG INT|INT2|INT8|BOOLEAN';
Description: '';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: False;
LoadPart: False;
ValueMustMatch: '^\d{1,10}$';
Category: dtcInteger;
),
(
Index: dtText;
Name: 'TEXT';
Names: 'CHARACTER|VARCHAR|VARYING CHARACTER|NCHAR|NATIVE CHARACTER|NVARCHAR|TEXT|CLOB';
Description: '';
HasLength: True;
RequiresLength: True;
HasBinary: False;
HasDefault: True;
LoadPart: True;
DefLengthSet: '50';
Category: dtcText;
),
(
Index: dtBlob;
Name: 'BLOB';
Description: '';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: False;
LoadPart: True;
Category: dtcBinary;
),
(
Index: dtReal;
Name: 'REAL';
Names: 'REAL|DOUBLE|DOUBLE PRECISION|FLOAT|NUMERIC|DECIMAL';
Description: '';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: False;
LoadPart: False;
Category: dtcReal;
),
(
Index: dtDate;
Name: 'DATE';
Description: '';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: True;
LoadPart: False;
Category: dtcTemporal;
),
(
Index: dtDatetime;
Name: 'DATETIME';
Description: '';
HasLength: False;
RequiresLength: False;
HasBinary: False;
HasDefault: False;
LoadPart: False;
Category: dtcTemporal;
)
);


MySqlFunctions: Array [0..254] of TMysqlFunction =
(
// Function nr. 1
@@ -7704,6 +7793,7 @@ procedure TSQLiteLib.AssignProcedures;
AssignProc(@sqlite3_column_text, 'sqlite3_column_text');
AssignProc(@sqlite3_column_count, 'sqlite3_column_count');
AssignProc(@sqlite3_column_name, 'sqlite3_column_name');
AssignProc(@sqlite3_column_decltype, 'sqlite3_column_decltype');
end;


0 comments on commit ed89b54

Please sign in to comment.
You can’t perform that action at this time.