00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Database Connectivity Interfaces }
00005 { }
00006 { Originally written by Sergey Seroukhov }
00007 { }
00008 {*********************************************************}
00009
00010 {@********************************************************}
00011 { Copyright (c) 1999-2006 Zeos Development Group }
00012 { }
00013 { License Agreement: }
00014 { }
00015 { This library is distributed in the hope that it will be }
00016 { useful, but WITHOUT ANY WARRANTY; without even the }
00017 { implied warranty of MERCHANTABILITY or FITNESS FOR }
00018 { A PARTICULAR PURPOSE. See the GNU Lesser General }
00019 { Public License for more details. }
00020 { }
00021 { The source code of the ZEOS Libraries and packages are }
00022 { distributed under the Library GNU General Public }
00023 { License (see the file COPYING / COPYING.ZEOS) }
00024 { with the following modification: }
00025 { As a special exception, the copyright holders of this }
00026 { library give you permission to link this library with }
00027 { independent modules to produce an executable, }
00028 { regardless of the license terms of these independent }
00029 { modules, and to copy and distribute the resulting }
00030 { executable under terms of your choice, provided that }
00031 { you also meet, for each linked independent module, }
00032 { the terms and conditions of the license of that module. }
00033 { An independent module is a module which is not derived }
00034 { from or based on this library. If you modify this }
00035 { library, you may extend this exception to your version }
00036 { of the library, but you are not obligated to do so. }
00037 { If you do not wish to do so, delete this exception }
00038 { statement from your version. }
00039 { }
00040 { }
00041 { The project web site is located on: }
00042 { http:
00043 { http:
00044 { svn:
00045 { }
00046 { http:
00047 { http:
00048 { }
00049 { }
00050 { }
00051 { Zeos Development Group. }
00052 {********************************************************@}
00053
00054 unit ZDbcIntfs;
00055
00056 interface
00057
00058 {$I ZDbc.inc}
00059
00060 uses
00061 {$IFNDEF VER130BELOW}
00062 Types,
00063 {$ENDIF}
00064 Classes, SysUtils, ZClasses, ZCollections, ZSysUtils, ZCompatibility,
00065 ZTokenizer, ZSelectSchema, ZGenericSqlAnalyser, ZDbcLogging, ZVariant;
00066
00067 const
00068 { Constants from JDBC DatabaseMetadata }
00069 TypeSearchable = 3;
00070 ProcedureReturnsResult = 2;
00071
00072
00073 type
00074
00075 {** Abstract SQL exception. }
00076 EZSQLThrowable = class(Exception)
00077 private
00078 FErrorCode: Integer;
00079 FStatusCode: String;
00080 public
00081 constructor Create(const Msg: string);
00082 constructor CreateWithCode(const ErrorCode: Integer; const Msg: string);
00083 constructor CreateWithStatus(const StatusCode: String; const Msg: string);
00084 constructor CreateClone(const E:EZSQLThrowable);
00085
00086 property ErrorCode: Integer read FErrorCode;
00087 property StatusCode: string read FStatuscode;
00088 end;
00089
00090 {** Generic SQL exception. }
00091 EZSQLException = class(EZSQLThrowable);
00092
00093 {** Generic SQL warning. }
00094 EZSQLWarning = class(EZSQLThrowable);
00095
00096
00097 type
00098 {** Defines supported SQL types. }
00099 TZSQLType = (stUnknown, stBoolean, stByte, stShort, stInteger, stLong, stFloat,
00100 stDouble, stBigDecimal, stString, stUnicodeString, stBytes, stDate, stTime,
00101 stTimestamp, stAsciiStream, stUnicodeStream, stBinaryStream);
00102
00103 {** Defines a transaction isolation level. }
00104 TZTransactIsolationLevel = (tiNone, tiReadUncommitted, tiReadCommitted,
00105 tiRepeatableRead, tiSerializable);
00106
00107 {** Defines a resultset fetch direction. }
00108 TZFetchDirection = (fdForward, fdReverse, fdUnknown);
00109
00110 {** Defines a type of result set. }
00111 TZResultSetType = (rtForwardOnly, rtScrollInsensitive, rtScrollSensitive);
00112
00113 {** Defines a result set concurrency type. }
00114 TZResultSetConcurrency = (rcReadOnly, rcUpdatable);
00115
00116 {** Defines a nullable type for the column. }
00117 TZColumnNullableType = (ntNoNulls, ntNullable, ntNullableUnknown);
00118
00119 {** Defines a result type for the procedures. }
00120 TZProcedureResultType = (prtUnknown, prtNoResult, prtReturnsResult);
00121
00122 {** Defines a column type for the procedures. }
00123 TZProcedureColumnType = (pctUnknown, pctIn, pctInOut, pctOut, pctReturn,
00124 pctResultSet);
00125
00126 {** Defines a best row identifier. }
00127 TZBestRowIdentifier = (brUnknown, brNotPseudo, brPseudo);
00128
00129 {** Defines a scope best row identifier. }
00130 TZScopeBestRowIdentifier = (sbrTemporary, sbrTransaction, sbrSession);
00131
00132 {** Defines a version column. }
00133 TZVersionColumn = (vcUnknown, vcNotPseudo, vcPseudo);
00134
00135 {** }
00136 TZImportedKey = (ikCascade, ikRestrict, ikSetNull, ikNoAction, ikSetDefault,
00137 ikInitiallyDeferred, ikInitiallyImmediate, ikNotDeferrable);
00138
00139 TZTableIndex = (tiStatistic, tiClustered, tiHashed, tiOther);
00140
00141 {** Defines a post update mode. }
00142 TZPostUpdatesMode = (poColumnsAll, poColumnsChanged);
00143
00144 {** Defines a locate mode. }
00145 TZLocateUpdatesMode = (loWhereAll, loWhereChanged, loWhereKeyOnly);
00146
00147
00148 type
00149
00150
00151 IZDriverManager = interface;
00152 IZDriver = interface;
00153 IZConnection = interface;
00154 IZDatabaseMetadata = interface;
00155 IZStatement = interface;
00156 IZPreparedStatement = interface;
00157 IZCallableStatement = interface;
00158 IZResultSet = interface;
00159 IZResultSetMetadata = interface;
00160 IZBlob = interface;
00161 IZNotification = interface;
00162 IZSequence = interface;
00163
00164 {** Driver Manager interface. }
00165 IZDriverManager = interface(IZInterface)
00166 ['{8874B9AA-068A-4C0C-AE75-9DB1EA9E3720}']
00167
00168 function GetConnection(const Url: string): IZConnection;
00169 function GetConnectionWithParams(const Url: string; Info: TStrings): IZConnection;
00170 function GetConnectionWithLogin(const Url: string; const User: string;
00171 const Password: string): IZConnection;
00172
00173 function GetDriver(const Url: string): IZDriver;
00174 function GetClientVersion(const Url: string): Integer;
00175 procedure RegisterDriver(Driver: IZDriver);
00176 procedure DeregisterDriver(Driver: IZDriver);
00177
00178 function GetDrivers: IZCollection;
00179
00180 function GetLoginTimeout: Integer;
00181 procedure SetLoginTimeout(Seconds: Integer);
00182
00183 procedure AddLoggingListener(Listener: IZLoggingListener);
00184 procedure RemoveLoggingListener(Listener: IZLoggingListener);
00185
00186 procedure LogMessage(Category: TZLoggingCategory; const Protocol: string;
00187 const Msg: string);
00188 procedure LogError(Category: TZLoggingCategory; const Protocol: string;
00189 const Msg: string; ErrorCode: Integer; const Error: string);
00190 end;
00191
00192 {** Database Driver interface. }
00193 IZDriver = interface(IZInterface)
00194 ['{2157710E-FBD8-417C-8541-753B585332E2}']
00195
00196 function GetSupportedProtocols: TStringDynArray;
00197 function Connect(const Url: string; Info: TStrings): IZConnection;
00198 function GetClientVersion(const Url: string): Integer;
00199 function AcceptsURL(const Url: string): Boolean;
00200
00201 function GetPropertyInfo(const Url: string; Info: TStrings): TStrings;
00202 function GetMajorVersion: Integer;
00203 function GetMinorVersion: Integer;
00204 function GetSubVersion: Integer;
00205 function GetTokenizer: IZTokenizer;
00206 function GetStatementAnalyser: IZStatementAnalyser;
00207 end;
00208
00209 {** Database Connection interface. }
00210 IZConnection = interface(IZInterface)
00211 ['{8EEBBD1A-56D1-4EC0-B3BD-42B60591457F}']
00212
00213 function CreateStatement: IZStatement;
00214 function PrepareStatement(const SQL: string): IZPreparedStatement;
00215 function PrepareCall(const SQL: string): IZCallableStatement;
00216
00217 function CreateStatementWithParams(Info: TStrings): IZStatement;
00218 function PrepareStatementWithParams(const SQL: string; Info: TStrings):
00219 IZPreparedStatement;
00220 function PrepareCallWithParams(const SQL: string; Info: TStrings):
00221 IZCallableStatement;
00222
00223 function CreateNotification(const Event: string): IZNotification;
00224 function CreateSequence(const Sequence: string; BlockSize: Integer): IZSequence;
00225
00226 function NativeSQL(const SQL: string): string;
00227
00228 procedure SetAutoCommit(Value: Boolean);
00229 function GetAutoCommit: Boolean;
00230
00231 procedure Commit;
00232 procedure Rollback;
00233
00234
00235 procedure PrepareTransaction(const transactionid: string);
00236 procedure CommitPrepared(const transactionid: string);
00237 procedure RollbackPrepared(const transactionid: string);
00238
00239
00240
00241
00242 function PingServer: Integer;
00243 function EscapeString(Value : String) : String;
00244
00245
00246 procedure Open;
00247 procedure Close;
00248 function IsClosed: Boolean;
00249
00250 function GetDriver: IZDriver;
00251 function GetMetadata: IZDatabaseMetadata;
00252 function GetParameters: TStrings;
00253 function GetClientVersion: Integer;
00254 function GetHostVersion: Integer;
00255
00256 procedure SetReadOnly(Value: Boolean);
00257 function IsReadOnly: Boolean;
00258
00259 procedure SetCatalog(const Value: string);
00260 function GetCatalog: string;
00261
00262 procedure SetTransactionIsolation(Value: TZTransactIsolationLevel);
00263 function GetTransactionIsolation: TZTransactIsolationLevel;
00264
00265 function GetWarnings: EZSQLWarning;
00266 procedure ClearWarnings;
00267 end;
00268
00269 {** Database metadata interface. }
00270 IZDatabaseMetadata = interface(IZInterface)
00271 ['{FE331C2D-0664-464E-A981-B4F65B85D1A8}']
00272
00273 function AllProceduresAreCallable: Boolean;
00274 function AllTablesAreSelectable: Boolean;
00275 function GetURL: string;
00276 function GetUserName: string;
00277 function IsReadOnly: Boolean;
00278 function NullsAreSortedHigh: Boolean;
00279 function NullsAreSortedLow: Boolean;
00280 function NullsAreSortedAtStart: Boolean;
00281 function NullsAreSortedAtEnd: Boolean;
00282 function GetDatabaseProductName: string;
00283 function GetDatabaseProductVersion: string;
00284 function GetDriverName: string;
00285 function GetDriverVersion: string;
00286 function GetDriverMajorVersion: Integer;
00287 function GetDriverMinorVersion: Integer;
00288 function UsesLocalFiles: Boolean;
00289 function UsesLocalFilePerTable: Boolean;
00290 function SupportsMixedCaseIdentifiers: Boolean;
00291 function StoresUpperCaseIdentifiers: Boolean;
00292 function StoresLowerCaseIdentifiers: Boolean;
00293 function StoresMixedCaseIdentifiers: Boolean;
00294 function SupportsMixedCaseQuotedIdentifiers: Boolean;
00295 function StoresUpperCaseQuotedIdentifiers: Boolean;
00296 function StoresLowerCaseQuotedIdentifiers: Boolean;
00297 function StoresMixedCaseQuotedIdentifiers: Boolean;
00298 function GetIdentifierQuoteString: string;
00299 function GetSQLKeywords: string;
00300 function GetNumericFunctions: string;
00301 function GetStringFunctions: string;
00302 function GetSystemFunctions: string;
00303 function GetTimeDateFunctions: string;
00304 function GetSearchStringEscape: string;
00305 function GetExtraNameCharacters: string;
00306
00307 function SupportsAlterTableWithAddColumn: Boolean;
00308 function SupportsAlterTableWithDropColumn: Boolean;
00309 function SupportsColumnAliasing: Boolean;
00310 function NullPlusNonNullIsNull: Boolean;
00311 function SupportsConvert: Boolean;
00312 function SupportsConvertForTypes(FromType: TZSQLType; ToType: TZSQLType):
00313 Boolean;
00314 function SupportsTableCorrelationNames: Boolean;
00315 function SupportsDifferentTableCorrelationNames: Boolean;
00316 function SupportsExpressionsInOrderBy: Boolean;
00317 function SupportsOrderByUnrelated: Boolean;
00318 function SupportsGroupBy: Boolean;
00319 function SupportsGroupByUnrelated: Boolean;
00320 function SupportsGroupByBeyondSelect: Boolean;
00321 function SupportsLikeEscapeClause: Boolean;
00322 function SupportsMultipleResultSets: Boolean;
00323 function SupportsMultipleTransactions: Boolean;
00324 function SupportsNonNullableColumns: Boolean;
00325 function SupportsMinimumSQLGrammar: Boolean;
00326 function SupportsCoreSQLGrammar: Boolean;
00327 function SupportsExtendedSQLGrammar: Boolean;
00328 function SupportsANSI92EntryLevelSQL: Boolean;
00329 function SupportsANSI92IntermediateSQL: Boolean;
00330 function SupportsANSI92FullSQL: Boolean;
00331 function SupportsIntegrityEnhancementFacility: Boolean;
00332 function SupportsOuterJoins: Boolean;
00333 function SupportsFullOuterJoins: Boolean;
00334 function SupportsLimitedOuterJoins: Boolean;
00335 function GetSchemaTerm: string;
00336 function GetProcedureTerm: string;
00337 function GetCatalogTerm: string;
00338 function IsCatalogAtStart: Boolean;
00339 function GetCatalogSeparator: string;
00340 function SupportsSchemasInDataManipulation: Boolean;
00341 function SupportsSchemasInProcedureCalls: Boolean;
00342 function SupportsSchemasInTableDefinitions: Boolean;
00343 function SupportsSchemasInIndexDefinitions: Boolean;
00344 function SupportsSchemasInPrivilegeDefinitions: Boolean;
00345 function SupportsCatalogsInDataManipulation: Boolean;
00346 function SupportsCatalogsInProcedureCalls: Boolean;
00347 function SupportsCatalogsInTableDefinitions: Boolean;
00348 function SupportsCatalogsInIndexDefinitions: Boolean;
00349 function SupportsCatalogsInPrivilegeDefinitions: Boolean;
00350 function SupportsPositionedDelete: Boolean;
00351 function SupportsPositionedUpdate: Boolean;
00352 function SupportsSelectForUpdate: Boolean;
00353 function SupportsStoredProcedures: Boolean;
00354 function SupportsSubqueriesInComparisons: Boolean;
00355 function SupportsSubqueriesInExists: Boolean;
00356 function SupportsSubqueriesInIns: Boolean;
00357 function SupportsSubqueriesInQuantifieds: Boolean;
00358 function SupportsCorrelatedSubqueries: Boolean;
00359 function SupportsUnion: Boolean;
00360 function SupportsUnionAll: Boolean;
00361 function SupportsOpenCursorsAcrossCommit: Boolean;
00362 function SupportsOpenCursorsAcrossRollback: Boolean;
00363 function SupportsOpenStatementsAcrossCommit: Boolean;
00364 function SupportsOpenStatementsAcrossRollback: Boolean;
00365
00366 function GetMaxBinaryLiteralLength: Integer;
00367 function GetMaxCharLiteralLength: Integer;
00368 function GetMaxColumnNameLength: Integer;
00369 function GetMaxColumnsInGroupBy: Integer;
00370 function GetMaxColumnsInIndex: Integer;
00371 function GetMaxColumnsInOrderBy: Integer;
00372 function GetMaxColumnsInSelect: Integer;
00373 function GetMaxColumnsInTable: Integer;
00374 function GetMaxConnections: Integer;
00375 function GetMaxCursorNameLength: Integer;
00376 function GetMaxIndexLength: Integer;
00377 function GetMaxSchemaNameLength: Integer;
00378 function GetMaxProcedureNameLength: Integer;
00379 function GetMaxCatalogNameLength: Integer;
00380 function GetMaxRowSize: Integer;
00381 function DoesMaxRowSizeIncludeBlobs: Boolean;
00382 function GetMaxStatementLength: Integer;
00383 function GetMaxStatements: Integer;
00384 function GetMaxTableNameLength: Integer;
00385 function GetMaxTablesInSelect: Integer;
00386 function GetMaxUserNameLength: Integer;
00387
00388 function GetDefaultTransactionIsolation: TZTransactIsolationLevel;
00389 function SupportsTransactions: Boolean;
00390 function SupportsTransactionIsolationLevel(Level: TZTransactIsolationLevel):
00391 Boolean;
00392 function SupportsDataDefinitionAndDataManipulationTransactions: Boolean;
00393 function SupportsDataManipulationTransactionsOnly: Boolean;
00394 function DataDefinitionCausesTransactionCommit: Boolean;
00395 function DataDefinitionIgnoredInTransactions: Boolean;
00396
00397 function GetProcedures(const Catalog: string; const SchemaPattern: string;
00398 const ProcedureNamePattern: string): IZResultSet;
00399 function GetProcedureColumns(const Catalog: string; const SchemaPattern: string;
00400 const ProcedureNamePattern: string; const ColumnNamePattern: string): IZResultSet;
00401
00402 function GetTables(const Catalog: string; const SchemaPattern: string;
00403 const TableNamePattern: string; const Types: TStringDynArray): IZResultSet;
00404 function GetSchemas: IZResultSet;
00405 function GetCatalogs: IZResultSet;
00406 function GetTableTypes: IZResultSet;
00407 function GetColumns(const Catalog: string; const SchemaPattern: string;
00408 const TableNamePattern: string; const ColumnNamePattern: string): IZResultSet;
00409 function GetColumnPrivileges(const Catalog: string; const Schema: string;
00410 const Table: string; const ColumnNamePattern: string): IZResultSet;
00411
00412 function GetTablePrivileges(const Catalog: string; const SchemaPattern: string;
00413 const TableNamePattern: string): IZResultSet;
00414 function GetBestRowIdentifier(const Catalog: string; const Schema: string;
00415 const Table: string; Scope: Integer; Nullable: Boolean): IZResultSet;
00416 function GetVersionColumns(const Catalog: string; const Schema: string;
00417 const Table: string): IZResultSet;
00418
00419 function GetPrimaryKeys(const Catalog: string; const Schema: string;
00420 const Table: string): IZResultSet;
00421 function GetImportedKeys(const Catalog: string; const Schema: string;
00422 const Table: string): IZResultSet;
00423 function GetExportedKeys(const Catalog: string; const Schema: string;
00424 const Table: string): IZResultSet;
00425 function GetCrossReference(const PrimaryCatalog: string; const PrimarySchema: string;
00426 const PrimaryTable: string; const ForeignCatalog: string; const ForeignSchema: string;
00427 const ForeignTable: string): IZResultSet;
00428
00429 function GetTypeInfo: IZResultSet;
00430
00431 function GetIndexInfo(const Catalog: string; const Schema: string; const Table: string;
00432 Unique: Boolean; Approximate: Boolean): IZResultSet;
00433
00434 function GetSequences(const Catalog: string; const SchemaPattern: string;
00435 const SequenceNamePattern: string): IZResultSet;
00436
00437 function SupportsResultSetType(_Type: TZResultSetType): Boolean;
00438 function SupportsResultSetConcurrency(_Type: TZResultSetType;
00439 Concurrency: TZResultSetConcurrency): Boolean;
00440 function SupportsBatchUpdates: Boolean;
00441
00442 function GetUDTs(const Catalog: string; const SchemaPattern: string;
00443 const TypeNamePattern: string; const Types: TIntegerDynArray): IZResultSet;
00444
00445 function GetConnection: IZConnection;
00446 function GetIdentifierConvertor: IZIdentifierConvertor;
00447
00448 procedure ClearCache;overload;
00449 procedure ClearCache(const Key: string);overload;
00450
00451 function AddEscapeCharToWildcards(const Pattern:string): string;
00452 end;
00453
00454 {** Generic SQL statement interface. }
00455 IZStatement = interface(IZInterface)
00456 ['{22CEFA7E-6A6D-48EC-BB9B-EE66056E90F1}']
00457
00458 function ExecuteQuery(const SQL: string): IZResultSet;
00459 function ExecuteUpdate(const SQL: string): Integer;
00460 procedure Close;
00461
00462 function GetMaxFieldSize: Integer;
00463 procedure SetMaxFieldSize(Value: Integer);
00464 function GetMaxRows: Integer;
00465 procedure SetMaxRows(Value: Integer);
00466 procedure SetEscapeProcessing(Value: Boolean);
00467 function GetQueryTimeout: Integer;
00468 procedure SetQueryTimeout(Value: Integer);
00469 procedure Cancel;
00470 procedure SetCursorName(const Value: string);
00471
00472 function Execute(const SQL: string): Boolean;
00473 function GetResultSet: IZResultSet;
00474 function GetUpdateCount: Integer;
00475 function GetMoreResults: Boolean;
00476
00477 procedure SetFetchDirection(Value: TZFetchDirection);
00478 function GetFetchDirection: TZFetchDirection;
00479 procedure SetFetchSize(Value: Integer);
00480 function GetFetchSize: Integer;
00481
00482 procedure SetResultSetConcurrency(Value: TZResultSetConcurrency);
00483 function GetResultSetConcurrency: TZResultSetConcurrency;
00484 procedure SetResultSetType(Value: TZResultSetType);
00485 function GetResultSetType: TZResultSetType;
00486
00487 procedure SetPostUpdates(Value: TZPostUpdatesMode);
00488 function GetPostUpdates: TZPostUpdatesMode;
00489 procedure SetLocateUpdates(Value: TZLocateUpdatesMode);
00490 function GetLocateUpdates: TZLocateUpdatesMode;
00491
00492 procedure AddBatch(const SQL: string);
00493 procedure ClearBatch;
00494 function ExecuteBatch: TIntegerDynArray;
00495
00496 function GetConnection: IZConnection;
00497 function GetParameters: TStrings;
00498
00499 function GetWarnings: EZSQLWarning;
00500 procedure ClearWarnings;
00501 end;
00502
00503 {** Prepared SQL statement interface. }
00504 IZPreparedStatement = interface(IZStatement)
00505 ['{990B8477-AF11-4090-8821-5B7AFEA9DD70}']
00506
00507 function ExecuteQueryPrepared: IZResultSet;
00508 function ExecuteUpdatePrepared: Integer;
00509 function ExecutePrepared: Boolean;
00510
00511 procedure SetDefaultValue(ParameterIndex: Integer; const Value: string);
00512
00513 procedure SetNull(ParameterIndex: Integer; SQLType: TZSQLType);
00514 procedure SetBoolean(ParameterIndex: Integer; Value: Boolean);
00515 procedure SetByte(ParameterIndex: Integer; Value: ShortInt);
00516 procedure SetShort(ParameterIndex: Integer; Value: SmallInt);
00517 procedure SetInt(ParameterIndex: Integer; Value: Integer);
00518 procedure SetLong(ParameterIndex: Integer; Value: Int64);
00519 procedure SetFloat(ParameterIndex: Integer; Value: Single);
00520 procedure SetDouble(ParameterIndex: Integer; Value: Double);
00521 procedure SetBigDecimal(ParameterIndex: Integer; Value: Extended);
00522 procedure SetPChar(ParameterIndex: Integer; Value: PChar);
00523 procedure SetString(ParameterIndex: Integer; const Value: string);
00524 procedure SetUnicodeString(ParameterIndex: Integer; const Value: WideString);
00525 procedure SetBytes(ParameterIndex: Integer; const Value: TByteDynArray);
00526 procedure SetDate(ParameterIndex: Integer; Value: TDateTime);
00527 procedure SetTime(ParameterIndex: Integer; Value: TDateTime);
00528 procedure SetTimestamp(ParameterIndex: Integer; Value: TDateTime);
00529 procedure SetAsciiStream(ParameterIndex: Integer; Value: TStream);
00530 procedure SetUnicodeStream(ParameterIndex: Integer; Value: TStream);
00531 procedure SetBinaryStream(ParameterIndex: Integer; Value: TStream);
00532 procedure SetBlob(ParameterIndex: Integer; SQLType: TZSQLType;
00533 Value: IZBlob);
00534 procedure SetValue(ParameterIndex: Integer; const Value: TZVariant);
00535
00536 procedure ClearParameters;
00537
00538 procedure AddBatchPrepared;
00539 function GetMetadata: IZResultSetMetadata;
00540 end;
00541
00542 {** Callable SQL statement interface. }
00543 IZCallableStatement = interface(IZPreparedStatement)
00544 ['{E6FA6C18-C764-4C05-8FCB-0582BDD1EF40}']
00545
00546 procedure RegisterOutParameter(ParameterIndex: Integer; SQLType: Integer);
00547 function WasNull: Boolean;
00548
00549 function IsNull(ParameterIndex: Integer): Boolean;
00550 function GetPChar(ParameterIndex: Integer): PChar;
00551 function GetString(ParameterIndex: Integer): string;
00552 function GetUnicodeString(ParameterIndex: Integer): WideString;
00553 function GetBoolean(ParameterIndex: Integer): Boolean;
00554 function GetByte(ParameterIndex: Integer): ShortInt;
00555 function GetShort(ParameterIndex: Integer): SmallInt;
00556 function GetInt(ParameterIndex: Integer): Integer;
00557 function GetLong(ParameterIndex: Integer): Int64;
00558 function GetFloat(ParameterIndex: Integer): Single;
00559 function GetDouble(ParameterIndex: Integer): Double;
00560 function GetBigDecimal(ParameterIndex: Integer): Extended;
00561 function GetBytes(ParameterIndex: Integer): TByteDynArray;
00562 function GetDate(ParameterIndex: Integer): TDateTime;
00563 function GetTime(ParameterIndex: Integer): TDateTime;
00564 function GetTimestamp(ParameterIndex: Integer): TDateTime;
00565 function GetValue(ParameterIndex: Integer): TZVariant;
00566 end;
00567
00568 {** Rows returned by SQL query. }
00569 IZResultSet = interface(IZInterface)
00570 ['{8F4C4D10-2425-409E-96A9-7142007CC1B2}']
00571
00572 function Next: Boolean;
00573 procedure Close;
00574 function WasNull: Boolean;
00575
00576
00577
00578
00579
00580 function IsNull(ColumnIndex: Integer): Boolean;
00581 function GetPChar(ColumnIndex: Integer): PChar;
00582 function GetString(ColumnIndex: Integer): string;
00583 function GetUnicodeString(ColumnIndex: Integer): WideString;
00584 function GetBoolean(ColumnIndex: Integer): Boolean;
00585 function GetByte(ColumnIndex: Integer): ShortInt;
00586 function GetShort(ColumnIndex: Integer): SmallInt;
00587 function GetInt(ColumnIndex: Integer): Integer;
00588 function GetLong(ColumnIndex: Integer): Int64;
00589 function GetFloat(ColumnIndex: Integer): Single;
00590 function GetDouble(ColumnIndex: Integer): Double;
00591 function GetBigDecimal(ColumnIndex: Integer): Extended;
00592 function GetBytes(ColumnIndex: Integer): TByteDynArray;
00593 function GetDate(ColumnIndex: Integer): TDateTime;
00594 function GetTime(ColumnIndex: Integer): TDateTime;
00595 function GetTimestamp(ColumnIndex: Integer): TDateTime;
00596 function GetAsciiStream(ColumnIndex: Integer): TStream;
00597 function GetUnicodeStream(ColumnIndex: Integer): TStream;
00598 function GetBinaryStream(ColumnIndex: Integer): TStream;
00599 function GetBlob(ColumnIndex: Integer): IZBlob;
00600 function GetValue(ColumnIndex: Integer): TZVariant;
00601
00602
00603
00604
00605
00606 function IsNullByName(const ColumnName: string): Boolean;
00607 function GetPCharByName(const ColumnName: string): PChar;
00608 function GetStringByName(const ColumnName: string): string;
00609 function GetUnicodeStringByName(const ColumnName: string): WideString;
00610 function GetBooleanByName(const ColumnName: string): Boolean;
00611 function GetByteByName(const ColumnName: string): ShortInt;
00612 function GetShortByName(const ColumnName: string): SmallInt;
00613 function GetIntByName(const ColumnName: string): Integer;
00614 function GetLongByName(const ColumnName: string): Int64;
00615 function GetFloatByName(const ColumnName: string): Single;
00616 function GetDoubleByName(const ColumnName: string): Double;
00617 function GetBigDecimalByName(const ColumnName: string): Extended;
00618 function GetBytesByName(const ColumnName: string): TByteDynArray;
00619 function GetDateByName(const ColumnName: string): TDateTime;
00620 function GetTimeByName(const ColumnName: string): TDateTime;
00621 function GetTimestampByName(const ColumnName: string): TDateTime;
00622 function GetAsciiStreamByName(const ColumnName: string): TStream;
00623 function GetUnicodeStreamByName(const ColumnName: string): TStream;
00624 function GetBinaryStreamByName(const ColumnName: string): TStream;
00625 function GetBlobByName(const ColumnName: string): IZBlob;
00626 function GetValueByName(const ColumnName: string): TZVariant;
00627
00628
00629
00630
00631
00632 function GetWarnings: EZSQLWarning;
00633 procedure ClearWarnings;
00634
00635 function GetCursorName: string;
00636 function GetMetadata: IZResultSetMetadata;
00637 function FindColumn(const ColumnName: string): Integer;
00638
00639
00640
00641
00642
00643 function IsBeforeFirst: Boolean;
00644 function IsAfterLast: Boolean;
00645 function IsFirst: Boolean;
00646 function IsLast: Boolean;
00647 procedure BeforeFirst;
00648 procedure AfterLast;
00649 function First: Boolean;
00650 function Last: Boolean;
00651 function GetRow: Integer;
00652 function MoveAbsolute(Row: Integer): Boolean;
00653 function MoveRelative(Rows: Integer): Boolean;
00654 function Previous: Boolean;
00655
00656
00657
00658
00659
00660 procedure SetFetchDirection(Value: TZFetchDirection);
00661 function GetFetchDirection: TZFetchDirection;
00662
00663 procedure SetFetchSize(Value: Integer);
00664 function GetFetchSize: Integer;
00665
00666 function GetType: TZResultSetType;
00667 function GetConcurrency: TZResultSetConcurrency;
00668
00669 function GetPostUpdates: TZPostUpdatesMode;
00670 function GetLocateUpdates: TZLocateUpdatesMode;
00671
00672
00673
00674
00675
00676 function RowUpdated: Boolean;
00677 function RowInserted: Boolean;
00678 function RowDeleted: Boolean;
00679
00680 procedure UpdateNull(ColumnIndex: Integer);
00681 procedure UpdateBoolean(ColumnIndex: Integer; Value: Boolean);
00682 procedure UpdateByte(ColumnIndex: Integer; Value: ShortInt);
00683 procedure UpdateShort(ColumnIndex: Integer; Value: SmallInt);
00684 procedure UpdateInt(ColumnIndex: Integer; Value: Integer);
00685 procedure UpdateLong(ColumnIndex: Integer; Value: Int64);
00686 procedure UpdateFloat(ColumnIndex: Integer; Value: Single);
00687 procedure UpdateDouble(ColumnIndex: Integer; Value: Double);
00688 procedure UpdateBigDecimal(ColumnIndex: Integer; Value: Extended);
00689 procedure UpdatePChar(ColumnIndex: Integer; Value: PChar);
00690 procedure UpdateString(ColumnIndex: Integer; const Value: string);
00691 procedure UpdateUnicodeString(ColumnIndex: Integer; const Value: WideString);
00692 procedure UpdateBytes(ColumnIndex: Integer; const Value: TByteDynArray);
00693 procedure UpdateDate(ColumnIndex: Integer; Value: TDateTime);
00694 procedure UpdateTime(ColumnIndex: Integer; Value: TDateTime);
00695 procedure UpdateTimestamp(ColumnIndex: Integer; Value: TDateTime);
00696 procedure UpdateAsciiStream(ColumnIndex: Integer; Value: TStream);
00697 procedure UpdateUnicodeStream(ColumnIndex: Integer; Value: TStream);
00698 procedure UpdateBinaryStream(ColumnIndex: Integer; Value: TStream);
00699 procedure UpdateValue(ColumnIndex: Integer; const Value: TZVariant);
00700
00701
00702
00703
00704
00705 procedure UpdateNullByName(const ColumnName: string);
00706 procedure UpdateBooleanByName(const ColumnName: string; Value: Boolean);
00707 procedure UpdateByteByName(const ColumnName: string; Value: ShortInt);
00708 procedure UpdateShortByName(const ColumnName: string; Value: SmallInt);
00709 procedure UpdateIntByName(const ColumnName: string; Value: Integer);
00710 procedure UpdateLongByName(const ColumnName: string; Value: Int64);
00711 procedure UpdateFloatByName(const ColumnName: string; Value: Single);
00712 procedure UpdateDoubleByName(const ColumnName: string; Value: Double);
00713 procedure UpdateBigDecimalByName(const ColumnName: string; Value: Extended);
00714 procedure UpdatePCharByName(const ColumnName: string; Value: PChar);
00715 procedure UpdateStringByName(const ColumnName: string; const Value: string);
00716 procedure UpdateUnicodeStringByName(const ColumnName: string; const Value: WideString);
00717 procedure UpdateBytesByName(const ColumnName: string; const Value: TByteDynArray);
00718 procedure UpdateDateByName(const ColumnName: string; Value: TDateTime);
00719 procedure UpdateTimeByName(const ColumnName: string; Value: TDateTime);
00720 procedure UpdateTimestampByName(const ColumnName: string; Value: TDateTime);
00721 procedure UpdateAsciiStreamByName(const ColumnName: string; Value: TStream);
00722 procedure UpdateUnicodeStreamByName(const ColumnName: string; Value: TStream);
00723 procedure UpdateBinaryStreamByName(const ColumnName: string; Value: TStream);
00724 procedure UpdateValueByName(const ColumnName: string; const Value: TZVariant);
00725
00726 procedure InsertRow;
00727 procedure UpdateRow;
00728 procedure DeleteRow;
00729 procedure RefreshRow;
00730 procedure CancelRowUpdates;
00731 procedure MoveToInsertRow;
00732 procedure MoveToCurrentRow;
00733
00734
00735
00736
00737
00738
00739 function CompareRows(Row1, Row2: Integer; const ColumnIndices: TIntegerDynArray;
00740 const ColumnDirs: TBooleanDynArray): Integer;
00741
00742 function GetStatement: IZStatement;
00743 end;
00744
00745 {** ResultSet metadata interface. }
00746 IZResultSetMetadata = interface(IZInterface)
00747 ['{47CA2144-2EA7-42C4-8444-F5154369B2D7}']
00748
00749 function GetColumnCount: Integer;
00750 function IsAutoIncrement(Column: Integer): Boolean;
00751 function IsCaseSensitive(Column: Integer): Boolean;
00752 function IsSearchable(Column: Integer): Boolean;
00753 function IsCurrency(Column: Integer): Boolean;
00754 function IsNullable(Column: Integer): TZColumnNullableType;
00755
00756 function IsSigned(Column: Integer): Boolean;
00757 function GetColumnDisplaySize(Column: Integer): Integer;
00758 function GetColumnLabel(Column: Integer): string;
00759 function GetColumnName(Column: Integer): string;
00760 function GetSchemaName(Column: Integer): string;
00761 function GetPrecision(Column: Integer): Integer;
00762 function GetScale(Column: Integer): Integer;
00763 function GetTableName(Column: Integer): string;
00764 function GetCatalogName(Column: Integer): string;
00765 function GetColumnType(Column: Integer): TZSQLType;
00766 function GetColumnTypeName(Column: Integer): string;
00767 function IsReadOnly(Column: Integer): Boolean;
00768 function IsWritable(Column: Integer): Boolean;
00769 function IsDefinitelyWritable(Column: Integer): Boolean;
00770 function GetDefaultValue(Column: Integer): string;
00771 function HasDefaultValue(Column: Integer): Boolean;
00772 end;
00773
00774 {** External or internal blob wrapper object. }
00775 IZBlob = interface(IZInterface)
00776 ['{47D209F1-D065-49DD-A156-EFD1E523F6BF}']
00777
00778 function IsEmpty: Boolean;
00779 function IsUpdated: Boolean;
00780 function Length: LongInt;
00781
00782 function GetString: string;
00783 procedure SetString(const Value: string);
00784 function GetUnicodeString: WideString;
00785 procedure SetUnicodeString(const Value: WideString);
00786 function GetBytes: TByteDynArray;
00787 procedure SetBytes(const Value: TByteDynArray);
00788 function GetStream: TStream;
00789 procedure SetStream(Value: TStream);
00790
00791 procedure Clear;
00792 function Clone: IZBlob;
00793 end;
00794
00795 {** Database notification interface. }
00796 IZNotification = interface(IZInterface)
00797 ['{BF785C71-EBE9-4145-8DAE-40674E45EF6F}']
00798
00799 function GetEvent: string;
00800 procedure Listen;
00801 procedure Unlisten;
00802 procedure DoNotify;
00803 function CheckEvents: string;
00804
00805 function GetConnection: IZConnection;
00806 end;
00807
00808 {** Database sequence generator interface. }
00809 IZSequence = interface(IZInterface)
00810 ['{A9A54FE5-0DBE-492F-8DA6-04AC5FCE779C}']
00811 function GetName: string;
00812 function GetBlockSize: Integer;
00813 procedure SetName(const Value: string);
00814 procedure SetBlockSize(const Value: Integer);
00815 function GetCurrentValue: Int64;
00816 function GetNextValue: Int64;
00817 function GetCurrentValueSQL: string;
00818 function GetNextValueSQL: string;
00819 function GetConnection: IZConnection;
00820 end;
00821
00822 var
00823 {** The common driver manager object. }
00824 DriverManager: IZDriverManager;
00825
00826 implementation
00827
00828 uses ZMessages;
00829
00830 type
00831 {** Driver Manager interface. }
00832 TZDriverManager = class(TInterfacedObject, IZDriverManager)
00833 private
00834 FDrivers: IZCollection;
00835 FLoginTimeout: Integer;
00836 FLoggingListeners: IZCollection;
00837 public
00838 constructor Create;
00839 destructor Destroy; override;
00840
00841 function GetConnection(const Url: string): IZConnection;
00842 function GetConnectionWithParams(const Url: string; Info: TStrings): IZConnection;
00843 function GetConnectionWithLogin(const Url: string; const User: string;
00844 const Password: string): IZConnection;
00845
00846 function GetDriver(const Url: string): IZDriver;
00847 procedure RegisterDriver(Driver: IZDriver);
00848 procedure DeregisterDriver(Driver: IZDriver);
00849
00850 function GetDrivers: IZCollection;
00851
00852 function GetClientVersion(const Url: string): Integer;
00853
00854 function GetLoginTimeout: Integer;
00855 procedure SetLoginTimeout(Value: Integer);
00856
00857 procedure AddLoggingListener(Listener: IZLoggingListener);
00858 procedure RemoveLoggingListener(Listener: IZLoggingListener);
00859
00860 procedure LogMessage(Category: TZLoggingCategory; const Protocol: string;
00861 const Msg: string);
00862 procedure LogError(Category: TZLoggingCategory; const Protocol: string;
00863 const Msg: string; ErrorCode: Integer; const Error: string);
00864 end;
00865
00866 { TZDriverManager }
00867
00868 {**
00869 Constructs this object with default properties.
00870 }
00871 constructor TZDriverManager.Create;
00872 begin
00873 FDrivers := TZCollection.Create;
00874 FLoginTimeout := 0;
00875 FLoggingListeners := TZCollection.Create;
00876 end;
00877
00878 {**
00879 Destroys this object and cleanups the memory.
00880 }
00881 destructor TZDriverManager.Destroy;
00882 begin
00883 FDrivers := nil;
00884 FLoggingListeners := nil;
00885 inherited Destroy;
00886 end;
00887
00888 {**
00889 Gets a collection of registered drivers.
00890 @return an unmodifiable collection with registered drivers.
00891 }
00892 function TZDriverManager.GetDrivers: IZCollection;
00893 begin
00894 Result := TZUnmodifiableCollection.Create(FDrivers);
00895 end;
00896
00897 {**
00898 Gets a login timeout value.
00899 @return a login timeout.
00900 }
00901 function TZDriverManager.GetLoginTimeout: Integer;
00902 begin
00903 Result := FLoginTimeout;
00904 end;
00905
00906 {**
00907 Sets a new login timeout value.
00908 @param Seconds a new login timeout in seconds.
00909 }
00910 procedure TZDriverManager.SetLoginTimeout(Value: Integer);
00911 begin
00912 FLoginTimeout := Value;
00913 end;
00914
00915 {**
00916 Registers a driver for specific database.
00917 @param Driver a driver to be registered.
00918 }
00919 procedure TZDriverManager.RegisterDriver(Driver: IZDriver);
00920 begin
00921 if not FDrivers.Contains(Driver) then
00922 FDrivers.Add(Driver);
00923 end;
00924
00925 {**
00926 Unregisters a driver for specific database.
00927 @param Driver a driver to be unregistered.
00928 }
00929 procedure TZDriverManager.DeregisterDriver(Driver: IZDriver);
00930 begin
00931 FDrivers.Remove(Driver);
00932 end;
00933
00934 {**
00935 Gets a driver which accepts the specified url.
00936 @param Url a database connection url.
00937 @return a found driver or <code>null</code> otherwise.
00938 }
00939 function TZDriverManager.GetDriver(const Url: string): IZDriver;
00940 var
00941 I: Integer;
00942 Current: IZDriver;
00943 begin
00944 Result := nil;
00945 for I := 0 to FDrivers.Count - 1 do
00946 begin
00947 Current := FDrivers[I] as IZDriver;
00948 if Current.AcceptsURL(Url) then
00949 begin
00950 Result := Current;
00951 Break;
00952 end;
00953 end;
00954 end;
00955
00956 {**
00957 Locates a required driver and opens a connection to the specified database.
00958 @param Url a database connection Url.
00959 @param Info an extra connection parameters.
00960 @return an opened connection.
00961 }
00962 function TZDriverManager.GetConnectionWithParams(const Url: string; Info: TStrings):
00963 IZConnection;
00964 var
00965 Driver: IZDriver;
00966 begin
00967 Driver := GetDriver(Url);
00968 if Driver = nil then
00969 raise EZSQLException.Create(SDriverWasNotFound);
00970 Result := Driver.Connect(Url, Info);
00971 end;
00972
00973 {**
00974 Locates a required driver and returns the client library version number.
00975 @param Url a database connection Url.
00976 @return client library version number.
00977 }
00978 function TZDriverManager.GetClientVersion(const Url: string): Integer;
00979 var
00980 Driver: IZDriver;
00981 begin
00982 Driver := GetDriver(Url);
00983 if Driver = nil then
00984 raise EZSQLException.Create(SDriverWasNotFound);
00985 Result := Driver.GetClientVersion(Url);
00986 end;
00987
00988 {**
00989 Locates a required driver and opens a connection to the specified database.
00990 @param Url a database connection Url.
00991 @param User a user's name.
00992 @param Password a user's password.
00993 @return an opened connection.
00994 }
00995 function TZDriverManager.GetConnectionWithLogin(const Url: string; const User: string;
00996 const Password: string): IZConnection;
00997 var
00998 Info: TStrings;
00999 begin
01000 Info := TStringList.Create;
01001 try
01002 Info.Add('username=' + User);
01003 Info.Add('password=' + Password);
01004 Result := GetConnectionWithParams(Url, Info);
01005 finally
01006 Info.Free;
01007 end;
01008 end;
01009
01010 {**
01011 Locates a required driver and opens a connection to the specified database.
01012 @param Url a database connection Url.
01013 @return an opened connection.
01014 }
01015 function TZDriverManager.GetConnection(const Url: string): IZConnection;
01016 begin
01017 Result := GetConnectionWithParams(Url, nil);
01018 end;
01019
01020 {**
01021 Adds a logging listener to log SQL events.
01022 @param Listener a logging interface to be added.
01023 }
01024 procedure TZDriverManager.AddLoggingListener(Listener: IZLoggingListener);
01025 begin
01026 FLoggingListeners.Add(Listener);
01027 end;
01028
01029 {**
01030 Removes a logging listener from the list.
01031 @param Listener a logging interface to be removed.
01032 }
01033 procedure TZDriverManager.RemoveLoggingListener(Listener: IZLoggingListener);
01034 begin
01035 FLoggingListeners.Remove(Listener);
01036 end;
01037
01038 {**
01039 Logs a message about event with error result code.
01040 @param Category a category of the message.
01041 @param Protocol a name of the protocol.
01042 @param Msg a description message.
01043 @param ErrorCode an error code.
01044 @param Error an error message.
01045 }
01046 procedure TZDriverManager.LogError(Category: TZLoggingCategory;
01047 const Protocol: string; const Msg: string; ErrorCode: Integer; const Error: string);
01048 var
01049 I: Integer;
01050 Listener: IZLoggingListener;
01051 Event: TZLoggingEvent;
01052 begin
01053 if FLoggingListeners.Count = 0 then Exit;
01054 Event := TZLoggingEvent.Create(Category, Protocol, Msg, ErrorCode, Error);
01055 try
01056 for I := 0 to FLoggingListeners.Count - 1 do
01057 begin
01058 Listener := FLoggingListeners[I] as IZLoggingListener;
01059 try
01060 Listener.LogEvent(Event);
01061 except
01062 end;
01063 end;
01064 finally
01065 Event.Destroy;
01066 end;
01067 end;
01068
01069 {**
01070 Logs a message about event with normal result code.
01071 @param Category a category of the message.
01072 @param Protocol a name of the protocol.
01073 @param Msg a description message.
01074 }
01075 procedure TZDriverManager.LogMessage(Category: TZLoggingCategory;
01076 const Protocol: string; const Msg: string);
01077 begin
01078 if FLoggingListeners.Count = 0 then Exit;
01079 LogError(Category, Protocol, Msg, 0, '');
01080 end;
01081
01082 { EZSQLThrowable }
01083
01084 {**
01085 Creates an exception with message string.
01086 @param Msg a error description.
01087 }
01088 constructor EZSQLThrowable.CreateClone(const E: EZSQLThrowable);
01089 begin
01090 inherited Create(E.Message);
01091 FErrorCode:=E.ErrorCode;
01092 FStatusCode:=E.Statuscode;
01093 end;
01094
01095 constructor EZSQLThrowable.Create(const Msg: string);
01096 begin
01097 inherited Create(Msg);
01098 FErrorCode := -1;
01099 end;
01100
01101 {**
01102 Creates an exception with message string.
01103 @param Msg a error description.
01104 @param ErrorCode a native server error code.
01105 }
01106 constructor EZSQLThrowable.CreateWithCode(const ErrorCode: Integer;
01107 const Msg: string);
01108 begin
01109 inherited Create(Msg);
01110 FErrorCode := ErrorCode;
01111 end;
01112
01113 constructor EZSQLThrowable.CreateWithStatus(const StatusCode, Msg: string);
01114 begin
01115 inherited Create(Msg);
01116 FStatusCode := StatusCode;
01117 end;
01118
01119 initialization
01120 DriverManager := TZDriverManager.Create;
01121 finalization
01122 DriverManager := nil;
01123 end.
01124