Skip to content
Permalink
Browse files

Issue #12: Implement TSQLiteConnection.GetCreateCode, and support squ…

…are brackets for identifier quoting
  • Loading branch information
ansgarbecker committed Jan 1, 2020
1 parent 687d1d8 commit d91da37bd16a0056b450e300239bae7899ab2365
Showing with 23 additions and 3 deletions.
  1. +23 −3 source/dbconnection.pas
@@ -599,6 +599,7 @@ TSQLiteConnection = class(TDBConnection)
property Lib: TSQLiteLib read FLib;
procedure Query(SQL: String; DoStoreResult: Boolean=False; LogCategory: TDBLogCategory=lcSQL); override;
function Ping(Reconnect: Boolean): Boolean; override;
function GetCreateCode(Obj: TDBObject): String; override;
function GetRowCount(Obj: TDBObject): Int64; override;
property LastRawResults: TSQLiteRawResults read FLastRawResults;
end;
@@ -1712,7 +1713,7 @@ constructor TSQLiteConnection.Create(AOwner: TComponent);
begin
inherited;
FQuoteChar := '"';
FQuoteChars := '"';
FQuoteChars := '"[]';
SetLength(FDatatypes, Length(SQLiteDatatypes));
for i:=0 to High(SQLiteDatatypes) do
FDatatypes[i] := SQLiteDatatypes[i];
@@ -3100,7 +3101,7 @@ function TMySQLConnection.GetCreateCode(Obj: TDBObject): String;
lntTable, lntView: Column := 1;
lntFunction, lntProcedure, lntTrigger: Column := 2;
lntEvent: Column := 3;
else Exception.CreateFmt(_('Unhandled list node type in %s.%s'), [ClassName, 'GetCreateCode']);
else raise EDbError.CreateFmt(_('Unhandled list node type in %s.%s'), [ClassName, 'GetCreateCode']);
end;
if Obj.NodeType = lntView then
Result := GetCreateViewCode(Obj.Database, Obj.Name)
@@ -3110,6 +3111,25 @@ function TMySQLConnection.GetCreateCode(Obj: TDBObject): String;
end;


function TSQLiteConnection.GetCreateCode(Obj: TDBObject): String;
begin
// PRAGMA table_info(customers):
// cid name type notnull dflt_value pk
// 0 CustomerId INTEGER 1 null 1
// 1 FirstName NVARCHAR(40) 1 null 0
case Obj.NodeType of
lntTable: begin
Result := GetVar('SELECT '+QuoteIdent('sql')+' FROM sqlite_master'+
' WHERE '+QuoteIdent('type')+'='+EscapeString('table')+
' AND name='+EscapeString(Obj.Name));
end;
else begin
raise EDbError.CreateFmt(_('Unhandled list node type in %s.%s'), [ClassName, 'GetCreateCode']);
end;
end;
end;


function TMySQLConnection.GetCreateViewCode(Database, Name: String): String;
var
ViewIS: TDBQuery;
@@ -5464,7 +5484,7 @@ function TDBConnection.ExtractIdentifier(var SQL: String): String;
i := LeftPos;
RightPos := LeftPos;
while i < Length(SQL) do begin
if SQL[i] = LeftQuote then begin
if (SQL[i] = LeftQuote) or ((LeftQuote = '[') and (SQL[i] = ']')) then begin
if SQL[i+1] = SQL[i] then // take doubled/escaped quote char into account
Inc(i)
else begin

0 comments on commit d91da37

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