mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-21 12:13:12 +02:00
fcl-db: sqldb: implemented TSQLConnection.GetSchemaNames
Added stSchemata to TSchemaType (Delphi has strange stUserNames instead) At TSQLConnection level stSchemata defaults to 'select * from INFORMATION_SCHEMA.SCHEMATA', which can be overriden in descendants. git-svn-id: trunk@23921 -
This commit is contained in:
parent
7d6717be86
commit
19132fc98d
@ -945,8 +945,7 @@ begin
|
|||||||
'from syscolumns c join sysobjects o on c.id=o.id '+
|
'from syscolumns c join sysobjects o on c.id=o.id '+
|
||||||
'where c.id=object_id(''' + SchemaObjectName + ''') '+
|
'where c.id=object_id(''' + SchemaObjectName + ''') '+
|
||||||
'order by colid';
|
'order by colid';
|
||||||
else
|
else Result := inherited;
|
||||||
DatabaseError(SMetadataUnavailable)
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -663,14 +663,14 @@ begin
|
|||||||
|
|
||||||
// prepare statement
|
// prepare statement
|
||||||
ODBCCursor.FQuery:=Buf;
|
ODBCCursor.FQuery:=Buf;
|
||||||
if ODBCCursor.FSchemaType=stNoSchema then
|
if not (ODBCCursor.FSchemaType in [stTables, stSysTables, stColumns, stProcedures]) then
|
||||||
begin
|
begin
|
||||||
ODBCCheckResult(
|
ODBCCheckResult(
|
||||||
SQLPrepare(ODBCCursor.FSTMTHandle, PChar(buf), Length(buf)),
|
SQLPrepare(ODBCCursor.FSTMTHandle, PChar(buf), Length(buf)),
|
||||||
SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not prepare statement.'
|
SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not prepare statement.'
|
||||||
);
|
);
|
||||||
end
|
end;
|
||||||
else
|
if ODBCCursor.FSchemaType <> stNoSchema then
|
||||||
ODBCCursor.FStatementType:=stSelect;
|
ODBCCursor.FStatementType:=stSelect;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -757,12 +757,11 @@ begin
|
|||||||
if Assigned(APArams) and (AParams.count > 0) then SetParameters(ODBCCursor, AParams);
|
if Assigned(APArams) and (AParams.count > 0) then SetParameters(ODBCCursor, AParams);
|
||||||
// execute the statement
|
// execute the statement
|
||||||
case ODBCCursor.FSchemaType of
|
case ODBCCursor.FSchemaType of
|
||||||
stNoSchema : Res:=SQLExecute(ODBCCursor.FSTMTHandle); //SQL_NO_DATA returns searched update or delete statement that does not affect any rows
|
|
||||||
stTables : Res:=SQLTables (ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0, TABLE_TYPE_USER, length(TABLE_TYPE_USER) );
|
stTables : Res:=SQLTables (ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0, TABLE_TYPE_USER, length(TABLE_TYPE_USER) );
|
||||||
stSysTables : Res:=SQLTables (ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0, TABLE_TYPE_SYSTEM, length(TABLE_TYPE_SYSTEM) );
|
stSysTables : Res:=SQLTables (ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0, TABLE_TYPE_SYSTEM, length(TABLE_TYPE_SYSTEM) );
|
||||||
stColumns : Res:=SQLColumns(ODBCCursor.FSTMTHandle, nil, 0, nil, 0, @ODBCCursor.FQuery[1], length(ODBCCursor.FQuery), nil, 0 );
|
stColumns : Res:=SQLColumns(ODBCCursor.FSTMTHandle, nil, 0, nil, 0, @ODBCCursor.FQuery[1], length(ODBCCursor.FQuery), nil, 0 );
|
||||||
stProcedures: Res:=SQLProcedures(ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0 );
|
stProcedures: Res:=SQLProcedures(ODBCCursor.FSTMTHandle, nil, 0, nil, 0, nil, 0 );
|
||||||
else Res:=SQL_NO_DATA;
|
else Res:=SQLExecute(ODBCCursor.FSTMTHandle); //SQL_NO_DATA returns searched update or delete statement that does not affect any rows
|
||||||
end; {case}
|
end; {case}
|
||||||
|
|
||||||
if (Res<>SQL_NO_DATA) then ODBCCheckResult( Res, SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' );
|
if (Res<>SQL_NO_DATA) then ODBCCheckResult( Res, SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.' );
|
||||||
@ -1450,12 +1449,15 @@ end;
|
|||||||
|
|
||||||
function TODBCConnection.GetSchemaInfoSQL(SchemaType: TSchemaType; SchemaObjectName, SchemaObjectPattern: string): string;
|
function TODBCConnection.GetSchemaInfoSQL(SchemaType: TSchemaType; SchemaObjectName, SchemaObjectPattern: string): string;
|
||||||
begin
|
begin
|
||||||
if SchemaObjectName<>'' then
|
if SchemaType in [stTables, stSysTables, stColumns, stProcedures] then
|
||||||
Result := SchemaObjectName
|
begin
|
||||||
|
if SchemaObjectName<>'' then
|
||||||
|
Result := SchemaObjectName
|
||||||
|
else
|
||||||
|
Result := ' ';
|
||||||
|
end
|
||||||
else
|
else
|
||||||
Result := ' ';
|
Result := inherited;
|
||||||
if not (SchemaType in [stNoSchema, stTables, stSysTables, stColumns, stProcedures]) then
|
|
||||||
DatabaseError(SMetadataUnavailable);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TODBCConnection.GetConnectionInfo(InfoType: TConnInfoType): string;
|
function TODBCConnection.GetConnectionInfo(InfoType: TConnInfoType): string;
|
||||||
|
@ -1124,7 +1124,7 @@ begin
|
|||||||
'where (a.attnum>0) and (not a.attisdropped) and (upper(c.relname)=''' + Uppercase(SchemaObjectName) + ''') '+
|
'where (a.attnum>0) and (not a.attisdropped) and (upper(c.relname)=''' + Uppercase(SchemaObjectName) + ''') '+
|
||||||
'order by a.attname';
|
'order by a.attname';
|
||||||
else
|
else
|
||||||
DatabaseError(SMetadataUnavailable)
|
s := inherited;
|
||||||
end; {case}
|
end; {case}
|
||||||
result := s;
|
result := s;
|
||||||
end;
|
end;
|
||||||
|
@ -22,7 +22,7 @@ interface
|
|||||||
|
|
||||||
uses SysUtils, Classes, DB, bufdataset, sqlscript;
|
uses SysUtils, Classes, DB, bufdataset, sqlscript;
|
||||||
|
|
||||||
type TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns, stProcedureParams, stIndexes, stPackages);
|
type TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns, stProcedureParams, stIndexes, stPackages, stSchemata);
|
||||||
TConnOption = (sqSupportParams,sqEscapeSlash,sqEscapeRepeat);
|
TConnOption = (sqSupportParams,sqEscapeSlash,sqEscapeRepeat);
|
||||||
TConnOptions= set of TConnOption;
|
TConnOptions= set of TConnOption;
|
||||||
TConnInfoType=(citAll=-1, citServerType, citServerVersion, citServerVersionString, citClientName, citClientVersion);
|
TConnInfoType=(citAll=-1, citServerType, citServerVersion, citServerVersionString, citClientName, citClientVersion);
|
||||||
@ -149,6 +149,7 @@ type
|
|||||||
procedure GetTableNames(List : TStrings; SystemTables : Boolean = false); virtual;
|
procedure GetTableNames(List : TStrings; SystemTables : Boolean = false); virtual;
|
||||||
procedure GetProcedureNames(List : TStrings); virtual;
|
procedure GetProcedureNames(List : TStrings); virtual;
|
||||||
procedure GetFieldNames(const TableName : string; List : TStrings); virtual;
|
procedure GetFieldNames(const TableName : string; List : TStrings); virtual;
|
||||||
|
procedure GetSchemaNames(List: TStrings); virtual;
|
||||||
function GetConnectionInfo(InfoType:TConnInfoType): string; virtual;
|
function GetConnectionInfo(InfoType:TConnInfoType): string; virtual;
|
||||||
procedure CreateDB; virtual;
|
procedure CreateDB; virtual;
|
||||||
procedure DropDB; virtual;
|
procedure DropDB; virtual;
|
||||||
@ -691,8 +692,10 @@ end;
|
|||||||
|
|
||||||
procedure TSQLConnection.GetTableNames(List: TStrings; SystemTables: Boolean);
|
procedure TSQLConnection.GetTableNames(List: TStrings; SystemTables: Boolean);
|
||||||
begin
|
begin
|
||||||
if not systemtables then GetDBInfo(stTables,'','table_name',List)
|
if not SystemTables then
|
||||||
else GetDBInfo(stSysTables,'','table_name',List);
|
GetDBInfo(stTables,'','table_name',List)
|
||||||
|
else
|
||||||
|
GetDBInfo(stSysTables,'','table_name',List);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLConnection.GetProcedureNames(List: TStrings);
|
procedure TSQLConnection.GetProcedureNames(List: TStrings);
|
||||||
@ -705,6 +708,11 @@ begin
|
|||||||
GetDBInfo(stColumns,TableName,'column_name',List);
|
GetDBInfo(stColumns,TableName,'column_name',List);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSQLConnection.GetSchemaNames(List: TStrings);
|
||||||
|
begin
|
||||||
|
GetDBInfo(stSchemata,'','SCHEMA_NAME',List);
|
||||||
|
end;
|
||||||
|
|
||||||
function TSQLConnection.GetConnectionInfo(InfoType: TConnInfoType): string;
|
function TSQLConnection.GetConnectionInfo(InfoType: TConnInfoType): string;
|
||||||
var i: TConnInfoType;
|
var i: TConnInfoType;
|
||||||
begin
|
begin
|
||||||
@ -791,7 +799,10 @@ end;
|
|||||||
function TSQLConnection.GetSchemaInfoSQL( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string;
|
function TSQLConnection.GetSchemaInfoSQL( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
DatabaseError(SMetadataUnavailable);
|
case SchemaType of
|
||||||
|
stSchemata: Result := 'SELECT * FROM INFORMATION_SCHEMA.SCHEMATA';
|
||||||
|
else DatabaseError(SMetadataUnavailable);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLConnection.CreateDB;
|
procedure TSQLConnection.CreateDB;
|
||||||
|
Loading…
Reference in New Issue
Block a user