mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 14:09:20 +02:00
* Moved some types to sqltypes unit so they can be reused outside of sqldb. Added GetObjectList to datadict using new types
git-svn-id: trunk@33169 -
This commit is contained in:
parent
2ab3458074
commit
67ac09b69f
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2108,6 +2108,7 @@ packages/fcl-db/src/base/fields.inc svneol=native#text/plain
|
|||||||
packages/fcl-db/src/base/fpmake.inc svneol=native#text/plain
|
packages/fcl-db/src/base/fpmake.inc svneol=native#text/plain
|
||||||
packages/fcl-db/src/base/fpmake.pp svneol=native#text/plain
|
packages/fcl-db/src/base/fpmake.pp svneol=native#text/plain
|
||||||
packages/fcl-db/src/base/sqlscript.pp svneol=native#text/plain
|
packages/fcl-db/src/base/sqlscript.pp svneol=native#text/plain
|
||||||
|
packages/fcl-db/src/base/sqltypes.pp svneol=native#text/plain
|
||||||
packages/fcl-db/src/base/xmldatapacketreader.pp svneol=native#text/plain
|
packages/fcl-db/src/base/xmldatapacketreader.pp svneol=native#text/plain
|
||||||
packages/fcl-db/src/codegen/Makefile svneol=native#text/plain
|
packages/fcl-db/src/codegen/Makefile svneol=native#text/plain
|
||||||
packages/fcl-db/src/codegen/Makefile.fpc svneol=native#text/plain
|
packages/fcl-db/src/codegen/Makefile.fpc svneol=native#text/plain
|
||||||
|
@ -131,6 +131,8 @@ begin
|
|||||||
T:=P.Targets.AddUnit('dbconst.pas');
|
T:=P.Targets.AddUnit('dbconst.pas');
|
||||||
T.ResourceStrings:=true;
|
T.ResourceStrings:=true;
|
||||||
|
|
||||||
|
T:=P.Targets.AddUnit('sqltypes.pp');
|
||||||
|
|
||||||
T:=P.Targets.AddUnit('sqlscript.pp');
|
T:=P.Targets.AddUnit('sqlscript.pp');
|
||||||
T.ResourceStrings:=true;
|
T.ResourceStrings:=true;
|
||||||
|
|
||||||
@ -500,6 +502,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
AddUnit('db');
|
AddUnit('db');
|
||||||
AddUnit('sqldb');
|
AddUnit('sqldb');
|
||||||
|
AddUnit('sqltypes');
|
||||||
AddUnit('fpdatadict');
|
AddUnit('fpdatadict');
|
||||||
end;
|
end;
|
||||||
T:=P.Targets.AddUnit('fpddsqlite3.pp', DatadictOSes);
|
T:=P.Targets.AddUnit('fpddsqlite3.pp', DatadictOSes);
|
||||||
@ -743,6 +746,7 @@ begin
|
|||||||
AddUnit('bufdataset');
|
AddUnit('bufdataset');
|
||||||
AddUnit('dbconst');
|
AddUnit('dbconst');
|
||||||
AddUnit('sqlscript');
|
AddUnit('sqlscript');
|
||||||
|
AddUnit('sqltypes');
|
||||||
end;
|
end;
|
||||||
T:=P.Targets.AddUnit('sqldblib.pp');
|
T:=P.Targets.AddUnit('sqldblib.pp');
|
||||||
with T.Dependencies do
|
with T.Dependencies do
|
||||||
|
86
packages/fcl-db/src/base/sqltypes.pp
Normal file
86
packages/fcl-db/src/base/sqltypes.pp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
unit sqltypes;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses classes, sysutils;
|
||||||
|
|
||||||
|
type
|
||||||
|
TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns, stProcedureParams, stIndexes, stPackages, stSchemata, stSequences);
|
||||||
|
|
||||||
|
|
||||||
|
type
|
||||||
|
TStatementType = (stUnknown, stSelect, stInsert, stUpdate, stDelete,
|
||||||
|
stDDL, stGetSegment, stPutSegment, stExecProcedure,
|
||||||
|
stStartTrans, stCommit, stRollback, stSelectForUpd);
|
||||||
|
|
||||||
|
TDBEventType = (detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack, detParamValue, detActualSQL);
|
||||||
|
TDBEventTypes = set of TDBEventType;
|
||||||
|
|
||||||
|
TQuoteChars = array[0..1] of char;
|
||||||
|
|
||||||
|
TSqlObjectIdentifierList = class;
|
||||||
|
|
||||||
|
{ TSqlObjectIdenfier }
|
||||||
|
|
||||||
|
TSqlObjectIdenfier = class(TCollectionItem)
|
||||||
|
private
|
||||||
|
FObjectName: String;
|
||||||
|
FSchemaName: String;
|
||||||
|
public
|
||||||
|
constructor Create(ACollection: TSqlObjectIdentifierList; Const AObjectName: String; Const ASchemaName: String = '');
|
||||||
|
property SchemaName: String read FSchemaName write FSchemaName;
|
||||||
|
property ObjectName: String read FObjectName write FObjectName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TSqlObjectIdentifierList }
|
||||||
|
|
||||||
|
TSqlObjectIdentifierList = class(TCollection)
|
||||||
|
private
|
||||||
|
function GetIdentifier(Index: integer): TSqlObjectIdenfier;
|
||||||
|
procedure SetIdentifier(Index: integer; AValue: TSqlObjectIdenfier);
|
||||||
|
public
|
||||||
|
function AddIdentifier: TSqlObjectIdenfier; overload;
|
||||||
|
function AddIdentifier(Const AObjectName: String; Const ASchemaName: String = ''): TSqlObjectIdenfier; overload;
|
||||||
|
property Identifiers[Index: integer]: TSqlObjectIdenfier read GetIdentifier write SetIdentifier; default;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TSqlObjectIdenfier }
|
||||||
|
|
||||||
|
constructor TSqlObjectIdenfier.Create(ACollection: TSqlObjectIdentifierList;
|
||||||
|
const AObjectName: String; Const ASchemaName: String = '');
|
||||||
|
begin
|
||||||
|
inherited Create(ACollection);
|
||||||
|
FSchemaName:=ASchemaName;
|
||||||
|
FObjectName:=AObjectName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TSqlObjectIdentifierList }
|
||||||
|
|
||||||
|
function TSqlObjectIdentifierList.GetIdentifier(Index: integer): TSqlObjectIdenfier;
|
||||||
|
begin
|
||||||
|
Result := Items[Index] as TSqlObjectIdenfier;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSqlObjectIdentifierList.SetIdentifier(Index: integer; AValue: TSqlObjectIdenfier);
|
||||||
|
begin
|
||||||
|
Items[Index] := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TSqlObjectIdentifierList.AddIdentifier: TSqlObjectIdenfier;
|
||||||
|
begin
|
||||||
|
Result:=Add as TSqlObjectIdenfier;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TSqlObjectIdentifierList.AddIdentifier(Const AObjectName: String;
|
||||||
|
Const ASchemaName: String = ''): TSqlObjectIdenfier;
|
||||||
|
begin
|
||||||
|
Result:=AddIdentifier();
|
||||||
|
Result.SchemaName:=ASchemaName;
|
||||||
|
Result.ObjectName:=AObjectName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
end.
|
@ -20,7 +20,7 @@ unit fpdatadict;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,inicol, inifiles, contnrs, db;
|
Classes, SysUtils,inicol, inifiles, contnrs, db, sqltypes;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
// Supported objects in this data dictionary
|
// Supported objects in this data dictionary
|
||||||
@ -577,6 +577,7 @@ Type
|
|||||||
Procedure Disconnect ; virtual; abstract;
|
Procedure Disconnect ; virtual; abstract;
|
||||||
procedure ImportDatadict (Adatadict: TFPDataDictionary; UpdateExisting : Boolean);
|
procedure ImportDatadict (Adatadict: TFPDataDictionary; UpdateExisting : Boolean);
|
||||||
Function GetTableList(List : TStrings) : Integer; virtual; abstract;
|
Function GetTableList(List : TStrings) : Integer; virtual; abstract;
|
||||||
|
Function GetObjectList(ASchemaType: TSchemaType; AList : TSqlObjectIdentifierList): Integer; virtual; abstract;
|
||||||
Function ImportTables(Tables : TDDTableDefs; List : TStrings; UpdateExisting : Boolean) : Integer;
|
Function ImportTables(Tables : TDDTableDefs; List : TStrings; UpdateExisting : Boolean) : Integer;
|
||||||
Function ImportFields(Table : TDDTableDef) : Integer; virtual; abstract;
|
Function ImportFields(Table : TDDTableDef) : Integer; virtual; abstract;
|
||||||
Function ImportIndexes(Table : TDDTableDef) : Integer; virtual; abstract;
|
Function ImportIndexes(Table : TDDTableDef) : Integer; virtual; abstract;
|
||||||
|
@ -20,7 +20,7 @@ unit fpddsqldb;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, DB, sqldb, fpdatadict;
|
Classes, SysUtils, DB, sqltypes, sqldb, fpdatadict;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ Type
|
|||||||
Function HostSupported: Boolean; virtual;
|
Function HostSupported: Boolean; virtual;
|
||||||
Function Connect(const AConnectString : String) : Boolean; override;
|
Function Connect(const AConnectString : String) : Boolean; override;
|
||||||
Function GetTableList(List : TStrings) : Integer; override;
|
Function GetTableList(List : TStrings) : Integer; override;
|
||||||
|
Function GetObjectList(ASchemaType: TSchemaType; AList : TSqlObjectIdentifierList): Integer; override;
|
||||||
Function ImportFields(Table : TDDTableDef) : Integer; override;
|
Function ImportFields(Table : TDDTableDef) : Integer; override;
|
||||||
Function ImportIndexes(Table : TDDTableDef) : Integer; override;
|
Function ImportIndexes(Table : TDDTableDef) : Integer; override;
|
||||||
Function ViewTable(Const TableName: String; DatasetOwner : TComponent) : TDataset; override;
|
Function ViewTable(Const TableName: String; DatasetOwner : TComponent) : TDataset; override;
|
||||||
@ -141,6 +142,12 @@ begin
|
|||||||
result := list.count;
|
result := list.count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function TSQLDBDDEngine.GetObjectList(ASchemaType: TSchemaType; AList : TSqlObjectIdentifierList): Integer;
|
||||||
|
begin
|
||||||
|
Result := FConn.GetObjectNames(ASchemaType, AList);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TSQLDBDDEngine.ImportFields(Table: TDDTableDef): Integer;
|
function TSQLDBDDEngine.ImportFields(Table: TDDTableDef): Integer;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
|
@ -20,23 +20,66 @@ unit sqldb;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses SysUtils, Classes, DB, bufdataset, sqlscript;
|
uses SysUtils, Classes, DB, bufdataset, sqlscript, sqltypes;
|
||||||
|
|
||||||
type
|
type
|
||||||
TSchemaType = (stNoSchema, stTables, stSysTables, stProcedures, stColumns, stProcedureParams, stIndexes, stPackages, stSchemata, stSequences);
|
TSchemaType = sqltypes.TSchemaType;
|
||||||
|
TStatementType = sqltypes.TStatementType;
|
||||||
|
TDBEventType = sqltypes.TDBEventType;
|
||||||
|
TDBEventTypes = sqltypes.TDBEventTypes;
|
||||||
|
TQuoteChars = sqltypes.TQuoteChars;
|
||||||
|
|
||||||
const
|
const
|
||||||
|
StatementTokens : Array[TStatementType] of string = ('(unknown)', 'select',
|
||||||
|
'insert', 'update', 'delete',
|
||||||
|
'create', 'get', 'put', 'execute',
|
||||||
|
'start','commit','rollback', '?'
|
||||||
|
);
|
||||||
TSchemaObjectNames: array[TSchemaType] of String = ('???', 'table_name',
|
TSchemaObjectNames: array[TSchemaType] of String = ('???', 'table_name',
|
||||||
'???', 'procedure_name', 'column_name', 'param_name',
|
'???', 'procedure_name', 'column_name', 'param_name',
|
||||||
'index_name', 'package_name', 'schema_name','sequence');
|
'index_name', 'package_name', 'schema_name','sequence');
|
||||||
|
SingleQuotes : TQuoteChars = ('''','''');
|
||||||
|
DoubleQuotes : TQuoteChars = ('"','"');
|
||||||
|
LogAllEvents = [detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack];
|
||||||
|
LogAllEventsExtra = [detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack, detParamValue,detActualSQL];
|
||||||
|
|
||||||
type
|
// Backwards compatibility alias constants.
|
||||||
|
|
||||||
|
stNoSchema = sqltypes.stNoSchema;
|
||||||
|
stTables = sqltypes.stTables;
|
||||||
|
stSysTables = sqltypes.stSysTables;
|
||||||
|
stProcedures = sqltypes.stProcedures;
|
||||||
|
stColumns = sqltypes.stColumns;
|
||||||
|
stProcedureParams = sqltypes.stProcedureParams;
|
||||||
|
stIndexes = sqltypes.stIndexes;
|
||||||
|
stPackages = sqltypes.stPackages;
|
||||||
|
stSchemata = sqltypes.stPackages;
|
||||||
|
stSequences = sqltypes.stSequences;
|
||||||
|
|
||||||
TStatementType = (stUnknown, stSelect, stInsert, stUpdate, stDelete,
|
stUnknown = sqltypes.stUnknown;
|
||||||
stDDL, stGetSegment, stPutSegment, stExecProcedure,
|
stSelect = sqltypes.stSelect;
|
||||||
stStartTrans, stCommit, stRollback, stSelectForUpd);
|
stInsert = sqltypes.stInsert;
|
||||||
|
stUpdate = sqltypes.stUpdate;
|
||||||
|
stDelete = sqltypes.stDelete;
|
||||||
|
stDDL = sqltypes.stDDL;
|
||||||
|
stGetSegment = sqltypes.stGetSegment;
|
||||||
|
stPutSegment = sqltypes.stPutSegment;
|
||||||
|
stExecProcedure = sqltypes.stExecProcedure;
|
||||||
|
stStartTrans = sqltypes.stStartTrans;
|
||||||
|
stCommit = sqltypes.stCommit;
|
||||||
|
stRollback = sqltypes.stRollback;
|
||||||
|
stSelectForUpd = sqltypes.stSelectForUpd;
|
||||||
|
|
||||||
|
detCustom = sqltypes.detCustom;
|
||||||
|
detPrepare = sqltypes.detPrepare;
|
||||||
|
detExecute = sqltypes.detExecute;
|
||||||
|
detFetch = sqltypes.detFetch;
|
||||||
|
detCommit = sqltypes.detCommit;
|
||||||
|
detRollBack = sqltypes.detRollBack;
|
||||||
|
detParamValue = sqltypes.detParamValue;
|
||||||
|
detActualSQL = sqltypes.detActualSQL;
|
||||||
|
|
||||||
|
Type
|
||||||
TRowsCount = LargeInt;
|
TRowsCount = LargeInt;
|
||||||
|
|
||||||
TSQLStatementInfo = Record
|
TSQLStatementInfo = Record
|
||||||
@ -47,7 +90,6 @@ type
|
|||||||
WhereStopPos : integer;
|
WhereStopPos : integer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
TSQLConnection = class;
|
TSQLConnection = class;
|
||||||
TSQLTransaction = class;
|
TSQLTransaction = class;
|
||||||
TCustomSQLQuery = class;
|
TCustomSQLQuery = class;
|
||||||
@ -55,11 +97,6 @@ type
|
|||||||
TSQLQuery = class;
|
TSQLQuery = class;
|
||||||
TSQLScript = class;
|
TSQLScript = class;
|
||||||
|
|
||||||
|
|
||||||
TDBEventType = (detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack, detParamValue, detActualSQL);
|
|
||||||
TDBEventTypes = set of TDBEventType;
|
|
||||||
TDBLogNotifyEvent = Procedure (Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String) of object;
|
|
||||||
|
|
||||||
TSQLHandle = Class(TObject)
|
TSQLHandle = Class(TObject)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -118,18 +155,6 @@ type
|
|||||||
Class Function ParamClass : TParamClass; override;
|
Class Function ParamClass : TParamClass; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TQuoteChars = array[0..1] of char;
|
|
||||||
|
|
||||||
const
|
|
||||||
SingleQuotes : TQuoteChars = ('''','''');
|
|
||||||
DoubleQuotes : TQuoteChars = ('"','"');
|
|
||||||
LogAllEvents = [detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack];
|
|
||||||
LogAllEventsExtra = [detCustom, detPrepare, detExecute, detFetch, detCommit, detRollBack, detParamValue,detActualSQL];
|
|
||||||
StatementTokens : Array[TStatementType] of string = ('(unknown)', 'select',
|
|
||||||
'insert', 'update', 'delete',
|
|
||||||
'create', 'get', 'put', 'execute',
|
|
||||||
'start','commit','rollback', '?'
|
|
||||||
);
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -142,36 +167,11 @@ type
|
|||||||
procedure Update; override;
|
procedure Update; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
TSqlObjectIdentifierList = class;
|
|
||||||
|
|
||||||
{ TSqlObjectIdenfier }
|
|
||||||
|
|
||||||
TSqlObjectIdenfier = class(TCollectionItem)
|
|
||||||
private
|
|
||||||
FObjectName: String;
|
|
||||||
FSchemaName: String;
|
|
||||||
public
|
|
||||||
constructor Create(ACollection: TSqlObjectIdentifierList; Const AObjectName: String; Const ASchemaName: String = '');
|
|
||||||
property SchemaName: String read FSchemaName write FSchemaName;
|
|
||||||
property ObjectName: String read FObjectName write FObjectName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TSqlObjectIdentifierList }
|
|
||||||
|
|
||||||
TSqlObjectIdentifierList = class(TCollection)
|
|
||||||
private
|
|
||||||
function GetIdentifier(Index: integer): TSqlObjectIdenfier;
|
|
||||||
procedure SetIdentifier(Index: integer; AValue: TSqlObjectIdenfier);
|
|
||||||
public
|
|
||||||
function AddIdentifier: TSqlObjectIdenfier; overload;
|
|
||||||
function AddIdentifier(Const AObjectName: String; Const ASchemaName: String = ''): TSqlObjectIdenfier; overload;
|
|
||||||
property Identifiers[Index: integer]: TSqlObjectIdenfier read GetIdentifier write SetIdentifier; default;
|
|
||||||
end;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TSQLConnection }
|
{ TSQLConnection }
|
||||||
|
|
||||||
|
TDBLogNotifyEvent = Procedure (Sender : TSQLConnection; EventType : TDBEventType; Const Msg : String) of object;
|
||||||
|
|
||||||
TConnOption = (sqSupportParams, sqSupportEmptyDatabaseName, sqEscapeSlash, sqEscapeRepeat, sqImplicitTransaction, sqLastInsertID, sqSupportReturning);
|
TConnOption = (sqSupportParams, sqSupportEmptyDatabaseName, sqEscapeSlash, sqEscapeRepeat, sqImplicitTransaction, sqLastInsertID, sqSupportReturning);
|
||||||
TConnOptions= set of TConnOption;
|
TConnOptions= set of TConnOption;
|
||||||
@ -3631,40 +3631,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TSqlObjectIdenfier }
|
|
||||||
|
|
||||||
constructor TSqlObjectIdenfier.Create(ACollection: TSqlObjectIdentifierList;
|
|
||||||
const AObjectName: String; Const ASchemaName: String = '');
|
|
||||||
begin
|
|
||||||
inherited Create(ACollection);
|
|
||||||
FSchemaName:=ASchemaName;
|
|
||||||
FObjectName:=AObjectName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TSqlObjectIdentifierList }
|
|
||||||
|
|
||||||
function TSqlObjectIdentifierList.GetIdentifier(Index: integer): TSqlObjectIdenfier;
|
|
||||||
begin
|
|
||||||
Result := Items[Index] as TSqlObjectIdenfier;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TSqlObjectIdentifierList.SetIdentifier(Index: integer; AValue: TSqlObjectIdenfier);
|
|
||||||
begin
|
|
||||||
Items[Index] := AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TSqlObjectIdentifierList.AddIdentifier: TSqlObjectIdenfier;
|
|
||||||
begin
|
|
||||||
Result:=Add as TSqlObjectIdenfier;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TSqlObjectIdentifierList.AddIdentifier(Const AObjectName: String;
|
|
||||||
Const ASchemaName: String = ''): TSqlObjectIdenfier;
|
|
||||||
begin
|
|
||||||
Result:=AddIdentifier();
|
|
||||||
Result.SchemaName:=ASchemaName;
|
|
||||||
Result.ObjectName:=AObjectName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
Initialization
|
Initialization
|
||||||
|
Loading…
Reference in New Issue
Block a user