mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 07:09:29 +02:00
* Removed unused BlobsCached function
* Implemented GetSchemaInfoSQL * Add support for pragma-statements * Map empty field-types to ftString types * Implemented BLOB-support git-svn-id: trunk@10845 -
This commit is contained in:
parent
596f8f5bbb
commit
545e44ff11
@ -48,7 +48,6 @@ type
|
||||
private
|
||||
fhandle: psqlite3;
|
||||
foptions: TSQLiteOptions;
|
||||
function blobscached: boolean;
|
||||
procedure setoptions(const avalue: tsqliteoptions);
|
||||
protected
|
||||
function stringquery(const asql: string): TStringArray;
|
||||
@ -86,8 +85,11 @@ type
|
||||
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs; const TableName : string); // Differs from SQLDB.
|
||||
function getprimarykeyfield(const atablename: string; const acursor: tsqlcursor): string;
|
||||
function RowsAffected(cursor: TSQLCursor): TRowsCount; override;
|
||||
function GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string; override;
|
||||
function StrToStatementType(s : string) : TStatementType; override;
|
||||
public
|
||||
function GetInsertID: int64;
|
||||
procedure GetFieldNames(const TableName : string; List : TStrings); override;
|
||||
published
|
||||
property Options: TSqliteOptions read FOptions write SetOptions;
|
||||
end;
|
||||
@ -251,25 +253,20 @@ end;
|
||||
procedure TSQLite3Connection.LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField; cursor: TSQLCursor; ATransaction : TSQLTransaction);
|
||||
|
||||
var
|
||||
blobid: integer;
|
||||
int1,int2: integer;
|
||||
str1: string;
|
||||
bo1: boolean;
|
||||
int1: integer;
|
||||
st: psqlite3_stmt;
|
||||
fnum: integer;
|
||||
|
||||
begin
|
||||
{$WARNING TSQLite3Connection.LoadBlobIntoBuffer not implemented !}
|
||||
{ if (mode = bmwrite) and (field.dataset is tmsesqlquery) then begin
|
||||
result:= tmsebufdataset(field.dataset).createblobbuffer(field);
|
||||
end
|
||||
else begin
|
||||
result:= nil;
|
||||
if mode = bmread then begin
|
||||
if field.getData(@blobId) then begin
|
||||
result:= acursor.getcachedblob(blobid);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
}
|
||||
|
||||
st:=TSQLite3Cursor(cursor).fstatement;
|
||||
fnum:= FieldDef.fieldno - 1;
|
||||
|
||||
int1:= sqlite3_column_bytes(st,fnum);
|
||||
|
||||
ReAllocMem(ABlobBuf^.BlobBuffer^.Buffer,int1);
|
||||
if int1 > 0 then
|
||||
move(sqlite3_column_text(st,fnum)^,ABlobBuf^.BlobBuffer^.Buffer^,int1);
|
||||
ABlobBuf^.BlobBuffer^.Size := int1;
|
||||
end;
|
||||
|
||||
function TSQLite3Connection.AllocateTransactionHandle: TSQLHandle;
|
||||
@ -334,7 +331,7 @@ Const
|
||||
(n:'DECIMAL'; t: ftBCD),
|
||||
(n:'TEXT'; t: ftmemo),
|
||||
(n:'BLOB'; t: ftBlob)
|
||||
{ Template:
|
||||
{ Template:
|
||||
(n:''; t: ft)
|
||||
}
|
||||
);
|
||||
@ -363,6 +360,9 @@ begin
|
||||
ft1:=FieldMap[fi].t;
|
||||
break;
|
||||
end;
|
||||
// Empty field types are allowed and used in calculated columns (aggregates)
|
||||
// and by pragma-statements
|
||||
if FD='' then ft1 := ftString;
|
||||
// handle some specials.
|
||||
size1:=0;
|
||||
case ft1 of
|
||||
@ -515,13 +515,7 @@ begin
|
||||
move(sqlite3_column_text(st,fnum)^,buffer^,int1);
|
||||
end;
|
||||
ftMemo,
|
||||
ftBlob: begin
|
||||
CreateBlob:=True;
|
||||
int2:= sqlite3_column_bytes(st,fnum);
|
||||
{$WARNING Blob data not handled correctly }
|
||||
// int1:= addblobdata(sqlite3_column_text(st,fnum),int2);
|
||||
move(int1,buffer^,sizeof(int1)); //save id
|
||||
end;
|
||||
ftBlob: CreateBlob:=True;
|
||||
else { Case }
|
||||
result:= false; // unknown
|
||||
end; { Case }
|
||||
@ -631,11 +625,6 @@ begin
|
||||
databaseerror(str1);
|
||||
end;
|
||||
|
||||
function TSQLite3Connection.blobscached: boolean;
|
||||
begin
|
||||
result:= true;
|
||||
end;
|
||||
|
||||
function execcallback(adata: pointer; ncols: longint; //adata = PStringArray
|
||||
avalues: PPchar; anames: PPchar):longint; cdecl;
|
||||
var
|
||||
@ -711,6 +700,25 @@ begin
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
function TSQLite3Connection.GetSchemaInfoSQL(SchemaType: TSchemaType;
|
||||
SchemaObjectName, SchemaPattern: string): string;
|
||||
|
||||
begin
|
||||
case SchemaType of
|
||||
stTables : result := 'select name as table_name from sqlite_master where type = ''table''';
|
||||
stColumns : result := 'pragma table_info(''' + (SchemaObjectName) + ''')';
|
||||
else
|
||||
DatabaseError(SMetadataUnavailable)
|
||||
end; {case}
|
||||
end;
|
||||
|
||||
function TSQLite3Connection.StrToStatementType(s: string): TStatementType;
|
||||
begin
|
||||
S:=Lowercase(s);
|
||||
if s = 'pragma' then exit(stSelect);
|
||||
result := inherited StrToStatementType(s);
|
||||
end;
|
||||
|
||||
procedure TSQLite3Connection.UpdateIndexDefs(var IndexDefs: TIndexDefs;
|
||||
const TableName: string);
|
||||
var
|
||||
@ -746,6 +754,12 @@ begin
|
||||
result:= sqlite3_last_insert_rowid(fhandle);
|
||||
end;
|
||||
|
||||
procedure TSQLite3Connection.GetFieldNames(const TableName: string;
|
||||
List: TStrings);
|
||||
begin
|
||||
GetDBInfo(stColumns,TableName,'name',List);
|
||||
end;
|
||||
|
||||
procedure TSQLite3Connection.setoptions(const avalue: tsqliteoptions);
|
||||
begin
|
||||
if avalue <> foptions then
|
||||
|
Loading…
Reference in New Issue
Block a user