mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 06:39:34 +02:00
* Result all indexes on UpdateIndexDefs, not only the PK. Patch from Ladislav Karrach, bug #16493
git-svn-id: trunk@15325 -
This commit is contained in:
parent
0ca44b1a7e
commit
73df2c730d
@ -82,7 +82,6 @@ type
|
|||||||
// New methods
|
// New methods
|
||||||
procedure execsql(const asql: string);
|
procedure execsql(const asql: string);
|
||||||
procedure UpdateIndexDefs(IndexDefs : TIndexDefs;TableName : string); override; // Differs from SQLDB.
|
procedure UpdateIndexDefs(IndexDefs : TIndexDefs;TableName : string); override; // Differs from SQLDB.
|
||||||
function getprimarykeyfield(const atablename: string; const acursor: tsqlcursor): string;
|
|
||||||
function RowsAffected(cursor: TSQLCursor): TRowsCount; override;
|
function RowsAffected(cursor: TSQLCursor): TRowsCount; override;
|
||||||
function GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string; override;
|
function GetSchemaInfoSQL(SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string; override;
|
||||||
function StrToStatementType(s : string) : TStatementType; override;
|
function StrToStatementType(s : string) : TStatementType; override;
|
||||||
@ -663,29 +662,6 @@ begin
|
|||||||
checkerror(sqlite3_exec(fhandle,pchar(asql),@execscallback,@result,nil));
|
checkerror(sqlite3_exec(fhandle,pchar(asql),@execscallback,@result,nil));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSQLite3Connection.getprimarykeyfield(const atablename: string;
|
|
||||||
const acursor: tsqlcursor): string;
|
|
||||||
var
|
|
||||||
int1,int2: integer;
|
|
||||||
ar1: TArrayStringArray;
|
|
||||||
str1: string;
|
|
||||||
|
|
||||||
begin
|
|
||||||
result:= '';
|
|
||||||
if atablename <> '' then
|
|
||||||
begin
|
|
||||||
ar1:= stringsquery('PRAGMA table_info('+atablename+');');
|
|
||||||
for int1:= 0 to high(ar1) do
|
|
||||||
begin
|
|
||||||
if (high(ar1[int1]) >= 5) and (ar1[int1][5] <> '0') then
|
|
||||||
begin
|
|
||||||
if result<>'' then result := result+';';
|
|
||||||
result:= result+ar1[int1][1];
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TSQLite3Connection.RowsAffected(cursor: TSQLCursor): TRowsCount;
|
function TSQLite3Connection.RowsAffected(cursor: TSQLCursor): TRowsCount;
|
||||||
begin
|
begin
|
||||||
if assigned(cursor) then
|
if assigned(cursor) then
|
||||||
@ -722,32 +698,58 @@ end;
|
|||||||
|
|
||||||
procedure TSQLite3Connection.UpdateIndexDefs(IndexDefs: TIndexDefs; TableName: string);
|
procedure TSQLite3Connection.UpdateIndexDefs(IndexDefs: TIndexDefs; TableName: string);
|
||||||
var
|
var
|
||||||
str1: string;
|
artableinfo, arindexlist, arindexinfo: TArrayStringArray;
|
||||||
|
il,ii: integer;
|
||||||
|
IndexName: string;
|
||||||
|
IndexOptions: TIndexOptions;
|
||||||
|
PKFields, IXFields: TStrings;
|
||||||
|
l: boolean;
|
||||||
|
|
||||||
|
function CheckPKFields:boolean;
|
||||||
|
var i: integer;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if IXFields.Count<>PKFields.Count then Exit;
|
||||||
|
for i:=0 to IXFields.Count-1 do
|
||||||
|
if PKFields.IndexOf(IXFields[i])<0 then Exit;
|
||||||
|
Result:=true;
|
||||||
|
PKFields.Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
str1:= getprimarykeyfield(tablename,nil);
|
PKFields:=TStringList.Create;
|
||||||
if str1 <> '' then
|
IXFields:=TStringList.Create;
|
||||||
|
IXFields.Delimiter:=';';
|
||||||
|
|
||||||
|
//primary key fields
|
||||||
|
artableinfo := stringsquery('PRAGMA table_info('+TableName+');');
|
||||||
|
for ii:=low(artableinfo) to high(artableinfo) do
|
||||||
|
if (high(artableinfo[ii]) >= 5) and (artableinfo[ii][5] = '1') then
|
||||||
|
PKFields.Add(artableinfo[ii][1]);
|
||||||
|
|
||||||
|
//list of all table indexes
|
||||||
|
arindexlist:=stringsquery('PRAGMA index_list('+TableName+');');
|
||||||
|
for il:=low(arindexlist) to high(arindexlist) do
|
||||||
begin
|
begin
|
||||||
indexdefs.add('$PRIMARY_KEY$',str1,[ixPrimary,ixUnique]);
|
IndexName:=arindexlist[il][1];
|
||||||
|
if arindexlist[il][2]='1' then
|
||||||
|
IndexOptions:=[ixUnique]
|
||||||
|
else
|
||||||
|
IndexOptions:=[];
|
||||||
|
//list of columns in given index
|
||||||
|
arindexinfo:=stringsquery('PRAGMA index_info('+IndexName+');');
|
||||||
|
IXFields.Clear;
|
||||||
|
for ii:=low(arindexinfo) to high(arindexinfo) do
|
||||||
|
IXFields.Add(arindexinfo[ii][2]);
|
||||||
|
|
||||||
|
if CheckPKFields then IndexOptions:=IndexOptions+[ixPrimary];
|
||||||
|
|
||||||
|
IndexDefs.Add(IndexName, IXFields.DelimitedText, IndexOptions);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
PKFields.Free;
|
||||||
|
IXFields.Free;
|
||||||
end;
|
end;
|
||||||
{
|
|
||||||
procedure TSQLite3Connection.UpdateIndexDefs(var IndexDefs: TIndexDefs;
|
|
||||||
const TableName: string);
|
|
||||||
var
|
|
||||||
int1,int2: integer;
|
|
||||||
ar1: TArrayStringArray;
|
|
||||||
str1: string;
|
|
||||||
begin
|
|
||||||
ar1:= stringsquery('PRAGMA table_info('+tablename+');');
|
|
||||||
for int1:= 0 to high(ar1) do begin
|
|
||||||
if (high(ar1[int1]) >= 5) and (ar1[int1][5] <> '0') then begin
|
|
||||||
indexdefs.add('$PRIMARY_KEY$',ar1[int1][1],[ixPrimary,ixUnique]);
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
|
|
||||||
function TSQLite3Connection.getinsertid: int64;
|
function TSQLite3Connection.getinsertid: int64;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user