zeoslib  UNKNOWN
 All Files
ZDbcIntfs.pas
Go to the documentation of this file.
1 {*********************************************************}
2 { }
3 { Zeos Database Objects }
4 { Database Connectivity Interfaces }
5 { }
6 { Originally written by Sergey Seroukhov }
7 { }
8 {*********************************************************}
9 
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
12 { }
13 { License Agreement: }
14 { }
15 { This library is distributed in the hope that it will be }
16 { useful, but WITHOUT ANY WARRANTY; without even the }
17 { implied warranty of MERCHANTABILITY or FITNESS FOR }
18 { A PARTICULAR PURPOSE. See the GNU Lesser General }
19 { Public License for more details. }
20 { }
21 { The source code of the ZEOS Libraries and packages are }
22 { distributed under the Library GNU General Public }
23 { License (see the file COPYING / COPYING.ZEOS) }
24 { with the following modification: }
25 { As a special exception, the copyright holders of this }
26 { library give you permission to link this library with }
27 { independent modules to produce an executable, }
28 { regardless of the license terms of these independent }
29 { modules, and to copy and distribute the resulting }
30 { executable under terms of your choice, provided that }
31 { you also meet, for each linked independent module, }
32 { the terms and conditions of the license of that module. }
33 { An independent module is a module which is not derived }
34 { from or based on this library. If you modify this }
35 { library, you may extend this exception to your version }
36 { of the library, but you are not obligated to do so. }
37 { If you do not wish to do so, delete this exception }
38 { statement from your version. }
39 { }
40 { }
41 { The project web site is located on: }
42 { http://zeos.firmos.at (FORUM) }
43 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
44 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
45 { }
46 { http://www.sourceforge.net/projects/zeoslib. }
47 { }
48 { }
49 { Zeos Development Group. }
50 {********************************************************@}
51 
52 unit ZDbcIntfs;
53 
54 interface
55 
56 {$I ZDbc.inc}
57 
58 uses
59  Types, Classes, {$IFDEF MSEgui}mclasses, mdb{$ELSE}DB{$ENDIF}, SysUtils,
60  ZClasses, ZCollections, ZCompatibility, ZTokenizer, ZSelectSchema,
61  ZGenericSqlAnalyser, ZDbcLogging, ZVariant, ZPlainDriver, ZURL;
62 
63 const
64  { Constants from JDBC DatabaseMetadata }
65  TypeSearchable = 3;
66  ProcedureReturnsResult = 2;
67 
68 // Exceptions
69 type
70 
71  {** Abstract SQL exception. }
72  EZSQLThrowable = class(Exception)
73  private
74  FErrorCode: Integer;
75  FStatusCode: String;
76  public
77  constructor Create(const Msg: string);
78  constructor CreateWithCode(const ErrorCode: Integer; const Msg: string);
79  constructor CreateWithStatus(const StatusCode: String; const Msg: string);
80  constructor CreateClone(const E:EZSQLThrowable);
81 
82  property ErrorCode: Integer read FErrorCode;
83  property StatusCode: string read FStatuscode; // The "String" Errocode // FirmOS
84  end;
85 
86  {** Generic SQL exception. }
87  EZSQLException = class(EZSQLThrowable);
88 
89  {** Generic SQL warning. }
90  EZSQLWarning = class(EZSQLThrowable);
91 
92 // Data types
93 type
94  {** Defines supported SQL types. }
95  TZSQLType = (stUnknown, stBoolean, stByte, stShort, stInteger, stLong,
96  stFloat, stDouble, stBigDecimal, stString, stUnicodeString, stBytes,
97  stDate, stTime, stTimestamp, stDataSet, stGUID,
98  stAsciiStream, stUnicodeStream, stBinaryStream);
99 
100  {** Defines a transaction isolation level. }
101  TZTransactIsolationLevel = (tiNone, tiReadUncommitted, tiReadCommitted,
102  tiRepeatableRead, tiSerializable);
103 
104  {** Defines a resultset fetch direction. }
105  TZFetchDirection = (fdForward, fdReverse, fdUnknown);
106 
107  {** Defines a type of result set. }
108  TZResultSetType = (rtForwardOnly, rtScrollInsensitive, rtScrollSensitive);
109 
110  {** Defines a result set concurrency type. }
111  TZResultSetConcurrency = (rcReadOnly, rcUpdatable);
112 
113  {** Defines a nullable type for the column. }
114  TZColumnNullableType = (ntNoNulls, ntNullable, ntNullableUnknown);
115 
116  {** Defines a result type for the procedures. }
117  TZProcedureResultType = (prtUnknown, prtNoResult, prtReturnsResult);
118 
119  {** Defines a column type for the procedures. }
120  TZProcedureColumnType = (pctUnknown, pctIn, pctInOut, pctOut, pctReturn,
121  pctResultSet);
122 
123  {** Defines a best row identifier. }
124  TZBestRowIdentifier = (brUnknown, brNotPseudo, brPseudo);
125 
126  {** Defines a scope best row identifier. }
127  TZScopeBestRowIdentifier = (sbrTemporary, sbrTransaction, sbrSession);
128 
129  {** Defines a version column. }
130  TZVersionColumn = (vcUnknown, vcNotPseudo, vcPseudo);
131 
132  {** }
133  TZImportedKey = (ikCascade, ikRestrict, ikSetNull, ikNoAction, ikSetDefault,
134  ikInitiallyDeferred, ikInitiallyImmediate, ikNotDeferrable);
135 
136  TZTableIndex = (tiStatistic, tiClustered, tiHashed, tiOther);
137 
138  {** Defines a post update mode. }
139  TZPostUpdatesMode = (poColumnsAll, poColumnsChanged);
140 
141  {** Defines a locate mode. }
142  TZLocateUpdatesMode = (loWhereAll, loWhereChanged, loWhereKeyOnly);
143 
144 // Interfaces
145 type
146 
147  // Forward declarations
148  IZDriverManager = interface;
149  IZDriver = interface;
150  IZConnection = interface;
151  IZDatabaseMetadata = interface;
152  IZDatabaseInfo = interface;
153  IZStatement = interface;
154  IZPreparedStatement = interface;
155  IZCallableStatement = interface;
156  IZResultSet = interface;
157  IZResultSetMetadata = interface;
158  IZBlob = interface;
159  IZNotification = interface;
160  IZSequence = interface;
161  IZDataSet = interface;
162 
163  {** Driver Manager interface. }
164  IZDriverManager = interface(IZInterface)
165  ['{8874B9AA-068A-4C0C-AE75-9DB1EA9E3720}']
166 
167  function GetConnection(const Url: string): IZConnection;
168  function GetConnectionWithParams(const Url: string; Info: TStrings): IZConnection;
169  function GetConnectionWithLogin(const Url: string; const User: string;
170  const Password: string): IZConnection;
171 
172  function GetDriver(const Url: string): IZDriver;
173  function GetClientVersion(const Url: string): Integer;
174  procedure RegisterDriver(Driver: IZDriver);
175  procedure DeregisterDriver(Driver: IZDriver);
176 
177  function GetDrivers: IZCollection;
178 
179  function GetLoginTimeout: Integer;
180  procedure SetLoginTimeout(Seconds: Integer);
181 
182  procedure AddLoggingListener(Listener: IZLoggingListener);
183  procedure RemoveLoggingListener(Listener: IZLoggingListener);
184 
185  procedure LogMessage(Category: TZLoggingCategory; const Protocol: string;
186  const Msg: string);
187  procedure LogError(Category: TZLoggingCategory; const Protocol: string;
188  const Msg: string; ErrorCode: Integer; const Error: string);
189  function ConstructURL(const Protocol, HostName, Database,
190  UserName, Password: String; const Port: Integer;
191  const Properties: TStrings = nil; const LibLocation: String = ''): String;
192  procedure ResolveDatabaseUrl(const Url: string; out HostName: string;
193  out Port: Integer; out Database: string; out UserName: string;
194  out Password: string; ResultInfo: TStrings = nil); overload;
195  procedure ResolveDatabaseUrl(const Url: string; out Database: string); overload;
196  end;
197 
198  {** Database Driver interface. }
199  IZDriver = interface(IZInterface)
200  ['{2157710E-FBD8-417C-8541-753B585332E2}']
201 
202  function GetSupportedProtocols: TStringDynArray;
203  function GetSupportedClientCodePages(const Url: TZURL;
204  Const {$IFNDEF UNICODE}AutoEncode,{$ENDIF} SupportedsOnly: Boolean;
205  CtrlsCPType: TZControlsCodePage = cCP_UTF16): TStringDynArray;
206  function Connect(const Url: string; Info: TStrings): IZConnection; overload;
207  function Connect(const Url: TZURL): IZConnection; overload;
208  function GetClientVersion(const Url: string): Integer;
209  function AcceptsURL(const Url: string): Boolean;
210  function GetPlainDriver(const Url: TZURL; const InitDriver: Boolean = True): IZPlainDriver;
211 
212  function GetPropertyInfo(const Url: string; Info: TStrings): TStrings;
213  function GetMajorVersion: Integer;
214  function GetMinorVersion: Integer;
215  function GetSubVersion: Integer;
216  function GetTokenizer: IZTokenizer;
217  function GetStatementAnalyser: IZStatementAnalyser;
218  end;
219 
220  {** Database Connection interface. }
221  IZConnection = interface(IZInterface)
222  ['{8EEBBD1A-56D1-4EC0-B3BD-42B60591457F}']
223 
224  function CreateStatement: IZStatement;
225  function PrepareStatement(const SQL: string): IZPreparedStatement;
226  function PrepareCall(const SQL: string): IZCallableStatement;
227 
228  function CreateStatementWithParams(Info: TStrings): IZStatement;
229  function PrepareStatementWithParams(const SQL: string; Info: TStrings):
230  IZPreparedStatement;
231  function PrepareCallWithParams(const SQL: string; Info: TStrings):
232  IZCallableStatement;
233 
234  function CreateNotification(const Event: string): IZNotification;
235  function CreateSequence(const Sequence: string; BlockSize: Integer): IZSequence;
236 
237  function NativeSQL(const SQL: string): string;
238 
239  procedure SetAutoCommit(Value: Boolean);
240  function GetAutoCommit: Boolean;
241 
242  procedure Commit;
243  procedure Rollback;
244 
245  //2Phase Commit Support initially for PostgresSQL (firmos) 21022006
246  procedure PrepareTransaction(const transactionid: string);
247  procedure CommitPrepared(const transactionid: string);
248  procedure RollbackPrepared(const transactionid: string);
249 
250 
251  //Ping Server Support (firmos) 27032006
252 
253  function PingServer: Integer;
254  function EscapeString(Value: RawByteString): RawByteString;
255 
256  procedure Open;
257  procedure Close;
258  function IsClosed: Boolean;
259 
260  function GetDriver: IZDriver;
261  function GetIZPlainDriver: IZPlainDriver;
262  function GetMetadata: IZDatabaseMetadata;
263  function GetParameters: TStrings;
264  function GetClientVersion: Integer;
265  function GetHostVersion: Integer;
266 
267  procedure SetReadOnly(Value: Boolean);
268  function IsReadOnly: Boolean;
269 
270  procedure SetCatalog(const Value: string);
271  function GetCatalog: string;
272 
273  procedure SetTransactionIsolation(Value: TZTransactIsolationLevel);
274  function GetTransactionIsolation: TZTransactIsolationLevel;
275 
276  function GetWarnings: EZSQLWarning;
277  procedure ClearWarnings;
278 
279  function UseMetadata: boolean;
280  procedure SetUseMetadata(Value: Boolean);
281  //EgonHugeist
282  function GetBinaryEscapeString(const Value: RawByteString): String; overload;
283  function GetBinaryEscapeString(const Value: TByteDynArray): String; overload;
284  function GetEscapeString(const Value: ZWideString): ZWideString; overload;
285  function GetEscapeString(const Value: RawByteString): RawByteString; overload;
286  function GetClientCodePageInformations: PZCodePage;
287  function GetAutoEncodeStrings: Boolean;
288  procedure SetAutoEncodeStrings(const Value: Boolean);
289  property AutoEncodeStrings: Boolean read GetAutoEncodeStrings write SetAutoEncodeStrings;
290  function GetEncoding: TZCharEncoding;
291  function GetConSettings: PZConSettings;
292 
293  {$IFDEF ZEOS_TEST_ONLY}
294  function GetTestMode : Byte;
295  procedure SetTestMode(Mode: Byte);
296  {$ENDIF}
297  end;
298 
299  {** Database metadata interface. }
300  IZDatabaseMetadata = interface(IZInterface)
301  ['{FE331C2D-0664-464E-A981-B4F65B85D1A8}']
302 
303  function GetURL: string;
304  function GetUserName: string;
305 
306  function GetDatabaseInfo: IZDatabaseInfo;
307  function GetTriggers(const Catalog: string; const SchemaPattern: string;
308  const TableNamePattern: string; const TriggerNamePattern: string): IZResultSet; //EgonHugeist 30.03.2011
309  function GetCollationAndCharSet(const Catalog, Schema, TableName, ColumnName: String): IZResultSet; //EgonHugeist 10.01.2012
310  function GetCharacterSets: IZResultSet; //EgonHugeist 19.01.2012
311  function GetProcedures(const Catalog: string; const SchemaPattern: string;
312  const ProcedureNamePattern: string): IZResultSet;
313  function GetProcedureColumns(const Catalog: string; const SchemaPattern: string;
314  const ProcedureNamePattern: string; const ColumnNamePattern: string): IZResultSet;
315 
316  function GetTables(const Catalog: string; const SchemaPattern: string;
317  const TableNamePattern: string; const Types: TStringDynArray): IZResultSet;
318  function GetSchemas: IZResultSet;
319  function GetCatalogs: IZResultSet;
320  function GetTableTypes: IZResultSet;
321  function GetColumns(const Catalog: string; const SchemaPattern: string;
322  const TableNamePattern: string; const ColumnNamePattern: string): IZResultSet;
323  function GetColumnPrivileges(const Catalog: string; const Schema: string;
324  const Table: string; const ColumnNamePattern: string): IZResultSet;
325 
326  function GetTablePrivileges(const Catalog: string; const SchemaPattern: string;
327  const TableNamePattern: string): IZResultSet;
328  function GetBestRowIdentifier(const Catalog: string; const Schema: string;
329  const Table: string; Scope: Integer; Nullable: Boolean): IZResultSet;
330  function GetVersionColumns(const Catalog: string; const Schema: string;
331  const Table: string): IZResultSet;
332 
333  function GetPrimaryKeys(const Catalog: string; const Schema: string;
334  const Table: string): IZResultSet;
335  function GetImportedKeys(const Catalog: string; const Schema: string;
336  const Table: string): IZResultSet;
337  function GetExportedKeys(const Catalog: string; const Schema: string;
338  const Table: string): IZResultSet;
339  function GetCrossReference(const PrimaryCatalog: string; const PrimarySchema: string;
340  const PrimaryTable: string; const ForeignCatalog: string; const ForeignSchema: string;
341  const ForeignTable: string): IZResultSet;
342 
343  function GetTypeInfo: IZResultSet;
344 
345  function GetIndexInfo(const Catalog: string; const Schema: string; const Table: string;
346  Unique: Boolean; Approximate: Boolean): IZResultSet;
347 
348  function GetSequences(const Catalog: string; const SchemaPattern: string;
349  const SequenceNamePattern: string): IZResultSet;
350 
351  function GetUDTs(const Catalog: string; const SchemaPattern: string;
352  const TypeNamePattern: string; const Types: TIntegerDynArray): IZResultSet;
353 
354  function GetConnection: IZConnection;
355  function GetIdentifierConvertor: IZIdentifierConvertor;
356 
357  procedure ClearCache;overload;
358  procedure ClearCache(const Key: string);overload;
359 
360  function AddEscapeCharToWildcards(const Pattern:string): string;
361  function NormalizePatternCase(Pattern:String): string;
362  end;
363 
364  {**
365  Database information interface. Used to describe the database as a whole
366  (version, capabilities, policies, etc).
367  } // technobot 2008-06-24
368  IZDatabaseInfo = interface(IZInterface)
369  ['{107CA354-F594-48F9-8E08-CD797F151EA0}']
370 
371  // database/driver/server info:
372  function GetDatabaseProductName: string;
373  function GetDatabaseProductVersion: string;
374  function GetDriverName: string;
375  function GetDriverVersion: string;
376  function GetDriverMajorVersion: Integer;
377  function GetDriverMinorVersion: Integer;
378  function GetServerVersion: string;
379 
380  // capabilities (what it can/cannot do):
381  function AllProceduresAreCallable: Boolean;
382  function AllTablesAreSelectable: Boolean;
383  function SupportsMixedCaseIdentifiers: Boolean;
384  function SupportsMixedCaseQuotedIdentifiers: Boolean;
385  function SupportsAlterTableWithAddColumn: Boolean;
386  function SupportsAlterTableWithDropColumn: Boolean;
387  function SupportsColumnAliasing: Boolean;
388  function SupportsConvert: Boolean;
389  function SupportsConvertForTypes(FromType: TZSQLType; ToType: TZSQLType):
390  Boolean;
391  function SupportsTableCorrelationNames: Boolean;
392  function SupportsDifferentTableCorrelationNames: Boolean;
393  function SupportsExpressionsInOrderBy: Boolean;
394  function SupportsOrderByUnrelated: Boolean;
395  function SupportsGroupBy: Boolean;
396  function SupportsGroupByUnrelated: Boolean;
397  function SupportsGroupByBeyondSelect: Boolean;
398  function SupportsLikeEscapeClause: Boolean;
399  function SupportsMultipleResultSets: Boolean;
400  function SupportsMultipleTransactions: Boolean;
401  function SupportsNonNullableColumns: Boolean;
402  function SupportsMinimumSQLGrammar: Boolean;
403  function SupportsCoreSQLGrammar: Boolean;
404  function SupportsExtendedSQLGrammar: Boolean;
405  function SupportsANSI92EntryLevelSQL: Boolean;
406  function SupportsANSI92IntermediateSQL: Boolean;
407  function SupportsANSI92FullSQL: Boolean;
408  function SupportsIntegrityEnhancementFacility: Boolean;
409  function SupportsOuterJoins: Boolean;
410  function SupportsFullOuterJoins: Boolean;
411  function SupportsLimitedOuterJoins: Boolean;
412  function SupportsSchemasInDataManipulation: Boolean;
413  function SupportsSchemasInProcedureCalls: Boolean;
414  function SupportsSchemasInTableDefinitions: Boolean;
415  function SupportsSchemasInIndexDefinitions: Boolean;
416  function SupportsSchemasInPrivilegeDefinitions: Boolean;
417  function SupportsCatalogsInDataManipulation: Boolean;
418  function SupportsCatalogsInProcedureCalls: Boolean;
419  function SupportsCatalogsInTableDefinitions: Boolean;
420  function SupportsCatalogsInIndexDefinitions: Boolean;
421  function SupportsCatalogsInPrivilegeDefinitions: Boolean;
422  function SupportsOverloadPrefixInStoredProcedureName: Boolean;
423  function SupportsPositionedDelete: Boolean;
424  function SupportsPositionedUpdate: Boolean;
425  function SupportsSelectForUpdate: Boolean;
426  function SupportsStoredProcedures: Boolean;
427  function SupportsSubqueriesInComparisons: Boolean;
428  function SupportsSubqueriesInExists: Boolean;
429  function SupportsSubqueriesInIns: Boolean;
430  function SupportsSubqueriesInQuantifieds: Boolean;
431  function SupportsCorrelatedSubqueries: Boolean;
432  function SupportsUnion: Boolean;
433  function SupportsUnionAll: Boolean;
434  function SupportsOpenCursorsAcrossCommit: Boolean;
435  function SupportsOpenCursorsAcrossRollback: Boolean;
436  function SupportsOpenStatementsAcrossCommit: Boolean;
437  function SupportsOpenStatementsAcrossRollback: Boolean;
438  function SupportsTransactions: Boolean;
439  function SupportsTransactionIsolationLevel(Level: TZTransactIsolationLevel):
440  Boolean;
441  function SupportsDataDefinitionAndDataManipulationTransactions: Boolean;
442  function SupportsDataManipulationTransactionsOnly: Boolean;
443  function SupportsResultSetType(_Type: TZResultSetType): Boolean;
444  function SupportsResultSetConcurrency(_Type: TZResultSetType;
445  Concurrency: TZResultSetConcurrency): Boolean;
446  function SupportsBatchUpdates: Boolean;
447  function SupportsNonEscapedSearchStrings: Boolean;
448  function SupportsUpdateAutoIncrementFields: Boolean;
449 
450  // maxima:
451  function GetMaxBinaryLiteralLength: Integer;
452  function GetMaxCharLiteralLength: Integer;
453  function GetMaxColumnNameLength: Integer;
454  function GetMaxColumnsInGroupBy: Integer;
455  function GetMaxColumnsInIndex: Integer;
456  function GetMaxColumnsInOrderBy: Integer;
457  function GetMaxColumnsInSelect: Integer;
458  function GetMaxColumnsInTable: Integer;
459  function GetMaxConnections: Integer;
460  function GetMaxCursorNameLength: Integer;
461  function GetMaxIndexLength: Integer;
462  function GetMaxSchemaNameLength: Integer;
463  function GetMaxProcedureNameLength: Integer;
464  function GetMaxCatalogNameLength: Integer;
465  function GetMaxRowSize: Integer;
466  function GetMaxStatementLength: Integer;
467  function GetMaxStatements: Integer;
468  function GetMaxTableNameLength: Integer;
469  function GetMaxTablesInSelect: Integer;
470  function GetMaxUserNameLength: Integer;
471 
472  // policies (how are various data and operations handled):
473  function IsReadOnly: Boolean;
474  function IsCatalogAtStart: Boolean;
475  function DoesMaxRowSizeIncludeBlobs: Boolean;
476  function NullsAreSortedHigh: Boolean;
477  function NullsAreSortedLow: Boolean;
478  function NullsAreSortedAtStart: Boolean;
479  function NullsAreSortedAtEnd: Boolean;
480  function NullPlusNonNullIsNull: Boolean;
481  function UsesLocalFiles: Boolean;
482  function UsesLocalFilePerTable: Boolean;
483  function StoresUpperCaseIdentifiers: Boolean;
484  function StoresLowerCaseIdentifiers: Boolean;
485  function StoresMixedCaseIdentifiers: Boolean;
486  function StoresUpperCaseQuotedIdentifiers: Boolean;
487  function StoresLowerCaseQuotedIdentifiers: Boolean;
488  function StoresMixedCaseQuotedIdentifiers: Boolean;
489  function GetDefaultTransactionIsolation: TZTransactIsolationLevel;
490  function DataDefinitionCausesTransactionCommit: Boolean;
491  function DataDefinitionIgnoredInTransactions: Boolean;
492 
493  // interface details (terms, keywords, etc):
494  function GetIdentifierQuoteString: string;
495  function GetSchemaTerm: string;
496  function GetProcedureTerm: string;
497  function GetCatalogTerm: string;
498  function GetCatalogSeparator: string;
499  function GetSQLKeywords: string;
500  function GetNumericFunctions: string;
501  function GetStringFunctions: string;
502  function GetSystemFunctions: string;
503  function GetTimeDateFunctions: string;
504  function GetSearchStringEscape: string;
505  function GetExtraNameCharacters: string;
506  end;
507 
508  {** Generic SQL statement interface. }
509  IZStatement = interface(IZInterface)
510  ['{22CEFA7E-6A6D-48EC-BB9B-EE66056E90F1}']
511 
512  function ExecuteQuery(const SQL: ZWideString): IZResultSet; overload;
513  function ExecuteUpdate(const SQL: ZWideString): Integer; overload;
514  function Execute(const SQL: ZWideString): Boolean; overload;
515  function ExecuteQuery(const SQL: RawByteString): IZResultSet; overload;
516  function ExecuteUpdate(const SQL: RawByteString): Integer; overload;
517  function Execute(const SQL: RawByteString): Boolean; overload;
518  procedure Close;
519 
520  function GetMaxFieldSize: Integer;
521  procedure SetMaxFieldSize(Value: Integer);
522  function GetMaxRows: Integer;
523  procedure SetMaxRows(Value: Integer);
524  procedure SetEscapeProcessing(Value: Boolean);
525  function GetQueryTimeout: Integer;
526  procedure SetQueryTimeout(Value: Integer);
527  procedure Cancel;
528  procedure SetCursorName(const Value: AnsiString);
529 
530  function GetResultSet: IZResultSet;
531  function GetUpdateCount: Integer;
532  function GetMoreResults: Boolean;
533 
534  procedure SetFetchDirection(Value: TZFetchDirection);
535  function GetFetchDirection: TZFetchDirection;
536  procedure SetFetchSize(Value: Integer);
537  function GetFetchSize: Integer;
538 
539  procedure SetResultSetConcurrency(Value: TZResultSetConcurrency);
540  function GetResultSetConcurrency: TZResultSetConcurrency;
541  procedure SetResultSetType(Value: TZResultSetType);
542  function GetResultSetType: TZResultSetType;
543 
544  procedure SetPostUpdates(Value: TZPostUpdatesMode);
545  function GetPostUpdates: TZPostUpdatesMode;
546  procedure SetLocateUpdates(Value: TZLocateUpdatesMode);
547  function GetLocateUpdates: TZLocateUpdatesMode;
548 
549  procedure AddBatch(const SQL: string);
550  procedure ClearBatch;
551  function ExecuteBatch: TIntegerDynArray;
552 
553  function GetConnection: IZConnection;
554  function GetParameters: TStrings;
555  function GetChunkSize: Integer;
556 
557  function GetWarnings: EZSQLWarning;
558  procedure ClearWarnings;
559 
560  function GetEncodedSQL(const SQL: {$IF defined(FPC) and defined(WITH_RAWBYTESTRING)}RawByteString{$ELSE}String{$IFEND}): RawByteString;
561  end;
562 
563  {** Prepared SQL statement interface. }
564  IZPreparedStatement = interface(IZStatement)
565  ['{990B8477-AF11-4090-8821-5B7AFEA9DD70}']
566 
567  function ExecuteQueryPrepared: IZResultSet;
568  function ExecuteUpdatePrepared: Integer;
569  function ExecutePrepared: Boolean;
570 
571  function GetSQL : String;
572 // procedure Prepare;
573 // procedure Unprepare;
574 // function IsPrepared: Boolean;
575 
576  procedure SetDefaultValue(ParameterIndex: Integer; const Value: string);
577 
578  procedure SetNull(ParameterIndex: Integer; SQLType: TZSQLType);
579  procedure SetBoolean(ParameterIndex: Integer; Value: Boolean);
580  procedure SetByte(ParameterIndex: Integer; Value: Byte);
581  procedure SetShort(ParameterIndex: Integer; Value: SmallInt);
582  procedure SetInt(ParameterIndex: Integer; Value: Integer);
583  procedure SetLong(ParameterIndex: Integer; Value: Int64);
584  procedure SetFloat(ParameterIndex: Integer; Value: Single);
585  procedure SetDouble(ParameterIndex: Integer; Value: Double);
586  procedure SetBigDecimal(ParameterIndex: Integer; Value: Extended);
587  procedure SetPChar(ParameterIndex: Integer; Value: PChar);
588  procedure SetString(ParameterIndex: Integer; const Value: String);
589  procedure SetUnicodeString(ParameterIndex: Integer; const Value: ZWideString); //AVZ
590  procedure SetBytes(ParameterIndex: Integer; const Value: TByteDynArray);
591  procedure SetDate(ParameterIndex: Integer; Value: TDateTime);
592  procedure SetTime(ParameterIndex: Integer; Value: TDateTime);
593  procedure SetTimestamp(ParameterIndex: Integer; Value: TDateTime);
594  procedure SetAsciiStream(ParameterIndex: Integer; Value: TStream);
595  procedure SetUnicodeStream(ParameterIndex: Integer; Value: TStream);
596  procedure SetBinaryStream(ParameterIndex: Integer; Value: TStream);
597  procedure SetBlob(ParameterIndex: Integer; SQLType: TZSQLType;
598  Value: IZBlob);
599  procedure SetValue(ParameterIndex: Integer; const Value: TZVariant);
600 
601  procedure ClearParameters;
602 
603  procedure AddBatchPrepared;
604  function GetMetadata: IZResultSetMetadata;
605  end;
606 
607  {** Callable SQL statement interface. }
608  IZCallableStatement = interface(IZPreparedStatement)
609  ['{E6FA6C18-C764-4C05-8FCB-0582BDD1EF40}']
610  function IsFunction: Boolean;
611  { Multiple ResultSet support API }
612  function HasMoreResultSets: Boolean;
613  function GetFirstResultSet: IZResultSet;
614  function GetPreviousResultSet: IZResultSet;
615  function GetNextResultSet: IZResultSet;
616  function GetLastResultSet: IZResultSet;
617  function BOR: Boolean;
618  function EOR: Boolean;
619  function GetResultSetByIndex(const Index: Integer): IZResultSet;
620  function GetResultSetCount: Integer;
621 
622  procedure RegisterOutParameter(ParameterIndex: Integer; SQLType: Integer);
623  procedure RegisterParamType(ParameterIndex:integer;ParamType:Integer);
624  function WasNull: Boolean;
625 
626  function IsNull(ParameterIndex: Integer): Boolean;
627  function GetPChar(ParameterIndex: Integer): PChar;
628  function GetString(ParameterIndex: Integer): String;
629  function GetUnicodeString(ParameterIndex: Integer): WideString;
630  function GetBoolean(ParameterIndex: Integer): Boolean;
631  function GetByte(ParameterIndex: Integer): Byte;
632  function GetShort(ParameterIndex: Integer): SmallInt;
633  function GetInt(ParameterIndex: Integer): Integer;
634  function GetLong(ParameterIndex: Integer): Int64;
635  function GetFloat(ParameterIndex: Integer): Single;
636  function GetDouble(ParameterIndex: Integer): Double;
637  function GetBigDecimal(ParameterIndex: Integer): Extended;
638  function GetBytes(ParameterIndex: Integer): TByteDynArray;
639  function GetDate(ParameterIndex: Integer): TDateTime;
640  function GetTime(ParameterIndex: Integer): TDateTime;
641  function GetTimestamp(ParameterIndex: Integer): TDateTime;
642  function GetValue(ParameterIndex: Integer): TZVariant;
643  end;
644 
645  IZParamNamedCallableStatement = interface(IZCallableStatement)
646  ['{99882891-81B2-4F3E-A3D7-35B6DCAA7136}']
647  procedure RegisterParamTypeAndName(const ParameterIndex:integer;
648  const ParamTypeName, ParamName: String; Const ColumnSize, Precision: Integer);
649  end;
650 
651  {** Rows returned by SQL query. }
652  IZResultSet = interface(IZInterface)
653  ['{8F4C4D10-2425-409E-96A9-7142007CC1B2}']
654 
655  function Next: Boolean;
656  procedure Close;
657  function WasNull: Boolean;
658 
659  //======================================================================
660  // Methods for accessing results by column index
661  //======================================================================
662 
663  function IsNull(ColumnIndex: Integer): Boolean;
664  function GetPChar(ColumnIndex: Integer): PChar;
665  function GetString(ColumnIndex: Integer): String;
666  function GetBinaryString(ColumnIndex: Integer): RawByteString;
667  function GetUnicodeString(ColumnIndex: Integer): WideString;
668  function GetBoolean(ColumnIndex: Integer): Boolean;
669  function GetByte(ColumnIndex: Integer): Byte;
670  function GetShort(ColumnIndex: Integer): SmallInt;
671  function GetInt(ColumnIndex: Integer): Integer;
672  function GetLong(ColumnIndex: Integer): Int64;
673  function GetFloat(ColumnIndex: Integer): Single;
674  function GetDouble(ColumnIndex: Integer): Double;
675  function GetBigDecimal(ColumnIndex: Integer): Extended;
676  function GetBytes(ColumnIndex: Integer): TByteDynArray;
677  function GetDate(ColumnIndex: Integer): TDateTime;
678  function GetTime(ColumnIndex: Integer): TDateTime;
679  function GetTimestamp(ColumnIndex: Integer): TDateTime;
680  function GetAsciiStream(ColumnIndex: Integer): TStream;
681  function GetUnicodeStream(ColumnIndex: Integer): TStream;
682  function GetBinaryStream(ColumnIndex: Integer): TStream;
683  function GetBlob(ColumnIndex: Integer): IZBlob;
684  function GetDataSet(ColumnIndex: Integer): IZDataSet;
685  function GetValue(ColumnIndex: Integer): TZVariant;
686  function GetDefaultExpression(ColumnIndex: Integer): string;
687 
688  //======================================================================
689  // Methods for accessing results by column name
690  //======================================================================
691 
692  function IsNullByName(const ColumnName: string): Boolean;
693  function GetPCharByName(const ColumnName: string): PChar;
694  function GetStringByName(const ColumnName: string): String;
695  function GetBinaryStringByName(const ColumnName: string): RawByteString;
696  function GetUnicodeStringByName(const ColumnName: string): WideString;
697  function GetBooleanByName(const ColumnName: string): Boolean;
698  function GetByteByName(const ColumnName: string): Byte;
699  function GetShortByName(const ColumnName: string): SmallInt;
700  function GetIntByName(const ColumnName: string): Integer;
701  function GetLongByName(const ColumnName: string): Int64;
702  function GetFloatByName(const ColumnName: string): Single;
703  function GetDoubleByName(const ColumnName: string): Double;
704  function GetBigDecimalByName(const ColumnName: string): Extended;
705  function GetBytesByName(const ColumnName: string): TByteDynArray;
706  function GetDateByName(const ColumnName: string): TDateTime;
707  function GetTimeByName(const ColumnName: string): TDateTime;
708  function GetTimestampByName(const ColumnName: string): TDateTime;
709  function GetAsciiStreamByName(const ColumnName: string): TStream;
710  function GetUnicodeStreamByName(const ColumnName: string): TStream;
711  function GetBinaryStreamByName(const ColumnName: string): TStream;
712  function GetBlobByName(const ColumnName: string): IZBlob;
713  function GetDataSetByName(const ColumnName: String): IZDataSet;
714  function GetValueByName(const ColumnName: string): TZVariant;
715 
716  //=====================================================================
717  // Advanced features:
718  //=====================================================================
719 
720  function GetWarnings: EZSQLWarning;
721  procedure ClearWarnings;
722 
723  function GetCursorName: AnsiString;
724  function GetMetadata: IZResultSetMetadata;
725  function FindColumn(const ColumnName: string): Integer;
726 
727  //---------------------------------------------------------------------
728  // Traversal/Positioning
729  //---------------------------------------------------------------------
730 
731  function IsBeforeFirst: Boolean;
732  function IsAfterLast: Boolean;
733  function IsFirst: Boolean;
734  function IsLast: Boolean;
735  procedure BeforeFirst;
736  procedure AfterLast;
737  function First: Boolean;
738  function Last: Boolean;
739  function GetRow: Integer;
740  function MoveAbsolute(Row: Integer): Boolean;
741  function MoveRelative(Rows: Integer): Boolean;
742  function Previous: Boolean;
743 
744  //---------------------------------------------------------------------
745  // Properties
746  //---------------------------------------------------------------------
747 
748  procedure SetFetchDirection(Value: TZFetchDirection);
749  function GetFetchDirection: TZFetchDirection;
750 
751  procedure SetFetchSize(Value: Integer);
752  function GetFetchSize: Integer;
753 
754  function GetType: TZResultSetType;
755  function GetConcurrency: TZResultSetConcurrency;
756 
757  function GetPostUpdates: TZPostUpdatesMode;
758  function GetLocateUpdates: TZLocateUpdatesMode;
759 
760  //---------------------------------------------------------------------
761  // Updates
762  //---------------------------------------------------------------------
763 
764  function RowUpdated: Boolean;
765  function RowInserted: Boolean;
766  function RowDeleted: Boolean;
767 
768  procedure UpdateNull(ColumnIndex: Integer);
769  procedure UpdateBoolean(ColumnIndex: Integer; Value: Boolean);
770  procedure UpdateByte(ColumnIndex: Integer; Value: ShortInt);
771  procedure UpdateShort(ColumnIndex: Integer; Value: SmallInt);
772  procedure UpdateInt(ColumnIndex: Integer; Value: Integer);
773  procedure UpdateLong(ColumnIndex: Integer; Value: Int64);
774  procedure UpdateFloat(ColumnIndex: Integer; Value: Single);
775  procedure UpdateDouble(ColumnIndex: Integer; Value: Double);
776  procedure UpdateBigDecimal(ColumnIndex: Integer; Value: Extended);
777  procedure UpdatePChar(ColumnIndex: Integer; Value: PChar);
778  procedure UpdateString(ColumnIndex: Integer; const Value: String);
779  procedure UpdateBinaryString(ColumnIndex: Integer; const Value: RawByteString);
780  procedure UpdateUnicodeString(ColumnIndex: Integer; const Value: WideString);
781  procedure UpdateBytes(ColumnIndex: Integer; const Value: TByteDynArray);
782  procedure UpdateDate(ColumnIndex: Integer; Value: TDateTime);
783  procedure UpdateTime(ColumnIndex: Integer; Value: TDateTime);
784  procedure UpdateTimestamp(ColumnIndex: Integer; Value: TDateTime);
785  procedure UpdateAsciiStream(ColumnIndex: Integer; Value: TStream);
786  procedure UpdateUnicodeStream(ColumnIndex: Integer; Value: TStream);
787  procedure UpdateBinaryStream(ColumnIndex: Integer; Value: TStream);
788  procedure UpdateDataSet(ColumnIndex: Integer; Value: IZDataSet);
789  procedure UpdateValue(ColumnIndex: Integer; const Value: TZVariant);
790  procedure UpdateDefaultExpression(ColumnIndex: Integer; const Value: string);
791 
792  //======================================================================
793  // Methods for accessing results by column name
794  //======================================================================
795 
796  procedure UpdateNullByName(const ColumnName: string);
797  procedure UpdateBooleanByName(const ColumnName: string; Value: Boolean);
798  procedure UpdateByteByName(const ColumnName: string; Value: ShortInt);
799  procedure UpdateShortByName(const ColumnName: string; Value: SmallInt);
800  procedure UpdateIntByName(const ColumnName: string; Value: Integer);
801  procedure UpdateLongByName(const ColumnName: string; Value: Int64);
802  procedure UpdateFloatByName(const ColumnName: string; Value: Single);
803  procedure UpdateDoubleByName(const ColumnName: string; Value: Double);
804  procedure UpdateBigDecimalByName(const ColumnName: string; Value: Extended);
805  procedure UpdatePCharByName(const ColumnName: string; Value: PChar);
806  procedure UpdateStringByName(const ColumnName: string; const Value: String);
807  procedure UpdateBinaryStringByName(const ColumnName: string; const Value: RawByteString);
808  procedure UpdateUnicodeStringByName(const ColumnName: string; const Value: WideString);
809  procedure UpdateBytesByName(const ColumnName: string; const Value: TByteDynArray);
810  procedure UpdateDateByName(const ColumnName: string; Value: TDateTime);
811  procedure UpdateTimeByName(const ColumnName: string; Value: TDateTime);
812  procedure UpdateTimestampByName(const ColumnName: string; Value: TDateTime);
813  procedure UpdateAsciiStreamByName(const ColumnName: string; Value: TStream);
814  procedure UpdateUnicodeStreamByName(const ColumnName: string; Value: TStream);
815  procedure UpdateBinaryStreamByName(const ColumnName: string; Value: TStream);
816  procedure UpdateDataSetByName(const ColumnName: string; Value: IZDataSet);
817  procedure UpdateValueByName(const ColumnName: string; const Value: TZVariant);
818 
819  procedure InsertRow;
820  procedure UpdateRow;
821  procedure DeleteRow;
822  procedure RefreshRow;
823  procedure CancelRowUpdates;
824  procedure MoveToInsertRow;
825  procedure MoveToCurrentRow;
826 // procedure MoveToSearchRow;
827 
828 // function Search(CaseInsensitive, PartialKey: Boolean): Boolean;
829 // function Compare(Row: Integer; CaseInsensitive, PartialKey: Boolean):
830 // Boolean;
831 
832  function CompareRows(Row1, Row2: Integer; const ColumnIndices: TIntegerDynArray;
833  const ColumnDirs: TBooleanDynArray): Integer;
834 
835  function GetStatement: IZStatement;
836  function GetConSettings: PZConsettings;
837  end;
838 
839  {** TDataSet interface}
840  IZDataSet = interface(IZInterface)
841  ['{DBC24011-EF26-4FD8-AC8B-C3E01619494A}']
842  function GetDataSet: TDataSet;
843  function IsEmpty: Boolean;
844  end;
845 
846  {** ResultSet metadata interface. }
847  IZResultSetMetadata = interface(IZInterface)
848  ['{47CA2144-2EA7-42C4-8444-F5154369B2D7}']
849 
850  function GetColumnCount: Integer;
851  function IsAutoIncrement(Column: Integer): Boolean;
852  function IsCaseSensitive(Column: Integer): Boolean;
853  function IsSearchable(Column: Integer): Boolean;
854  function IsCurrency(Column: Integer): Boolean;
855  function IsNullable(Column: Integer): TZColumnNullableType;
856 
857  function IsSigned(Column: Integer): Boolean;
858  function GetColumnDisplaySize(Column: Integer): Integer;
859  function GetColumnLabel(Column: Integer): string;
860  function GetColumnName(Column: Integer): string;
861  function GetSchemaName(Column: Integer): string;
862  function GetPrecision(Column: Integer): Integer;
863  function GetScale(Column: Integer): Integer;
864  function GetTableName(Column: Integer): string;
865  function GetCatalogName(Column: Integer): string;
866  function GetColumnType(Column: Integer): TZSQLType;
867  function GetColumnTypeName(Column: Integer): string;
868  function IsReadOnly(Column: Integer): Boolean;
869  function IsWritable(Column: Integer): Boolean;
870  function IsDefinitelyWritable(Column: Integer): Boolean;
871  function GetDefaultValue(Column: Integer): string;
872  function HasDefaultValue(Column: Integer): Boolean;
873  end;
874 
875  {** External or internal blob wrapper object. }
876  IZBlob = interface(IZInterface)
877  ['{47D209F1-D065-49DD-A156-EFD1E523F6BF}']
878 
879  function IsEmpty: Boolean;
880  function IsUpdated: Boolean;
881  function Length: LongInt;
882  function WasDecoded: Boolean;
883  function Connection: IZConnection;
884 
885  function GetString: RawByteString;
886  procedure SetString(const Value: RawByteString);
887  function GetUnicodeString: WideString;
888  procedure SetUnicodeString(const Value: WideString);
889  function GetBytes: TByteDynArray;
890  procedure SetBytes(const Value: TByteDynArray);
891  function GetUnicodeStream: TStream;
892  function GetStream: TStream;
893  procedure SetStream(Value: TStream; Encoded: Boolean = False);
894  function GetBuffer: Pointer;
895  procedure SetBuffer(Buffer: Pointer; Length: Integer);
896 
897  procedure Clear;
898  function Clone: IZBlob;
899  end;
900 
901  {** Database notification interface. }
902  IZNotification = interface(IZInterface)
903  ['{BF785C71-EBE9-4145-8DAE-40674E45EF6F}']
904 
905  function GetEvent: string;
906  procedure Listen;
907  procedure Unlisten;
908  procedure DoNotify;
909  function CheckEvents: string;
910 
911  function GetConnection: IZConnection;
912  end;
913 
914  {** Database sequence generator interface. }
915  IZSequence = interface(IZInterface)
916  ['{A9A54FE5-0DBE-492F-8DA6-04AC5FCE779C}']
917  function GetName: string;
918  function GetBlockSize: Integer;
919  procedure SetName(const Value: string);
920  procedure SetBlockSize(const Value: Integer);
921  function GetCurrentValue: Int64;
922  function GetNextValue: Int64;
923  function GetCurrentValueSQL: string;
924  function GetNextValueSQL: string;
925  function GetConnection: IZConnection;
926  end;
927 
928 var
929  {** The common driver manager object. }
930  DriverManager: IZDriverManager;
931 
932 implementation
933 
934 uses ZMessages;
935 
936 type
937  {** Driver Manager interface. }
938  TZDriverManager = class(TInterfacedObject, IZDriverManager)
939  private
940  FDrivers: IZCollection;
941  FLoginTimeout: Integer;
942  FLoggingListeners: IZCollection;
943  FURL: TZURL;
944  public
945  constructor Create;
946  destructor Destroy; override;
947 
948  function GetConnection(const Url: string): IZConnection;
949  function GetConnectionWithParams(const Url: string; Info: TStrings): IZConnection;
950  function GetConnectionWithLogin(const Url: string; const User: string;
951  const Password: string): IZConnection;
952 
953  function GetDriver(const Url: string): IZDriver;
954  procedure RegisterDriver(Driver: IZDriver);
955  procedure DeregisterDriver(Driver: IZDriver);
956 
957  function GetDrivers: IZCollection;
958 
959  function GetClientVersion(const Url: string): Integer;
960 
961  function GetLoginTimeout: Integer;
962  procedure SetLoginTimeout(Value: Integer);
963 
964  procedure AddLoggingListener(Listener: IZLoggingListener);
965  procedure RemoveLoggingListener(Listener: IZLoggingListener);
966 
967  procedure LogMessage(Category: TZLoggingCategory; const Protocol: string;
968  const Msg: string);
969  procedure LogError(Category: TZLoggingCategory; const Protocol: string;
970  const Msg: string; ErrorCode: Integer; const Error: string);
971 
972  function ConstructURL(const Protocol, HostName, Database,
973  UserName, Password: String; const Port: Integer;
974  const Properties: TStrings = nil; const LibLocation: String = ''): String;
975  procedure ResolveDatabaseUrl(const Url: string; out HostName: string;
976  out Port: Integer; out Database: string; out UserName: string;
977  out Password: string; ResultInfo: TStrings = nil); overload;
978  procedure ResolveDatabaseUrl(const Url: string; out Database: string); overload;
979  end;
980 
981 { TZDriverManager }
982 
983 {**
984  Constructs this object with default properties.
985 }
986 constructor TZDriverManager.Create;
987 begin
988  FDrivers := TZCollection.Create;
989  FLoginTimeout := 0;
990  FLoggingListeners := TZCollection.Create;
991  FURL := TZURL.Create;
992 end;
993 
994 {**
995  Destroys this object and cleanups the memory.
996 }
997 destructor TZDriverManager.Destroy;
998 begin
999  FURL.Free;
1000  FDrivers := nil;
1001  FLoggingListeners := nil;
1002  inherited Destroy;
1003 end;
1004 
1005 {**
1006  Gets a collection of registered drivers.
1007  @return an unmodifiable collection with registered drivers.
1008 }
1009 function TZDriverManager.GetDrivers: IZCollection;
1010 begin
1011  Result := TZUnmodifiableCollection.Create(FDrivers);
1012 end;
1013 
1014 {**
1015  Gets a login timeout value.
1016  @return a login timeout.
1017 }
1018 function TZDriverManager.GetLoginTimeout: Integer;
1019 begin
1020  Result := FLoginTimeout;
1021 end;
1022 
1023 {**
1024  Sets a new login timeout value.
1025  @param Seconds a new login timeout in seconds.
1026 }
1027 procedure TZDriverManager.SetLoginTimeout(Value: Integer);
1028 begin
1029  FLoginTimeout := Value;
1030 end;
1031 
1032 {**
1033  Registers a driver for specific database.
1034  @param Driver a driver to be registered.
1035 }
1036 procedure TZDriverManager.RegisterDriver(Driver: IZDriver);
1037 begin
1038  if not FDrivers.Contains(Driver) then
1039  FDrivers.Add(Driver);
1040 end;
1041 
1042 {**
1043  Unregisters a driver for specific database.
1044  @param Driver a driver to be unregistered.
1045 }
1046 procedure TZDriverManager.DeregisterDriver(Driver: IZDriver);
1047 begin
1048  FDrivers.Remove(Driver);
1049 end;
1050 
1051 {**
1052  Gets a driver which accepts the specified url.
1053  @param Url a database connection url.
1054  @return a found driver or <code>null</code> otherwise.
1055 }
1056 function TZDriverManager.GetDriver(const Url: string): IZDriver;
1057 var
1058  I: Integer;
1059  Current: IZDriver;
1060 begin
1061  Result := nil;
1062  for I := 0 to FDrivers.Count - 1 do
1063  begin
1064  Current := FDrivers[I] as IZDriver;
1065  if Current.AcceptsURL(Url) then
1066  begin
1067  Result := Current;
1068  Break;
1069  end;
1070  end;
1071 end;
1072 
1073 {**
1074  Locates a required driver and opens a connection to the specified database.
1075  @param Url a database connection Url.
1076  @param Info an extra connection parameters.
1077  @return an opened connection.
1078 }
1079 function TZDriverManager.GetConnectionWithParams(const Url: string; Info: TStrings):
1080  IZConnection;
1081 var
1082  Driver: IZDriver;
1083 begin
1084  Driver := GetDriver(Url);
1085  if Driver = nil then
1086  raise EZSQLException.Create(SDriverWasNotFound);
1087  Result := Driver.Connect(Url, Info);
1088 end;
1089 
1090 {**
1091  Locates a required driver and returns the client library version number.
1092  @param Url a database connection Url.
1093  @return client library version number.
1094 }
1095 function TZDriverManager.GetClientVersion(const Url: string): Integer;
1096 var
1097  Driver: IZDriver;
1098 begin
1099  Driver := GetDriver(Url);
1100  if Driver = nil then
1101  raise EZSQLException.Create(SDriverWasNotFound);
1102  Result := Driver.GetClientVersion(Url);
1103 end;
1104 
1105 {**
1106  Locates a required driver and opens a connection to the specified database.
1107  @param Url a database connection Url.
1108  @param User a user's name.
1109  @param Password a user's password.
1110  @return an opened connection.
1111 }
1112 function TZDriverManager.GetConnectionWithLogin(const Url: string; const User: string;
1113  const Password: string): IZConnection;
1114 var
1115  Info: TStrings;
1116 begin
1117  Info := TStringList.Create;
1118  try
1119  Info.Add('username=' + User);
1120  Info.Add('password=' + Password);
1121  Result := GetConnectionWithParams(Url, Info);
1122  finally
1123  Info.Free;
1124  end;
1125 end;
1126 
1127 {**
1128  Locates a required driver and opens a connection to the specified database.
1129  @param Url a database connection Url.
1130  @return an opened connection.
1131 }
1132 function TZDriverManager.GetConnection(const Url: string): IZConnection;
1133 begin
1134  Result := GetConnectionWithParams(Url, nil);
1135 end;
1136 
1137 {**
1138  Adds a logging listener to log SQL events.
1139  @param Listener a logging interface to be added.
1140 }
1141 procedure TZDriverManager.AddLoggingListener(Listener: IZLoggingListener);
1142 begin
1143  FLoggingListeners.Add(Listener);
1144 end;
1145 
1146 {**
1147  Removes a logging listener from the list.
1148  @param Listener a logging interface to be removed.
1149 }
1150 procedure TZDriverManager.RemoveLoggingListener(Listener: IZLoggingListener);
1151 begin
1152  FLoggingListeners.Remove(Listener);
1153 end;
1154 
1155 {**
1156  Logs a message about event with error result code.
1157  @param Category a category of the message.
1158  @param Protocol a name of the protocol.
1159  @param Msg a description message.
1160  @param ErrorCode an error code.
1161  @param Error an error message.
1162 }
1163 procedure TZDriverManager.LogError(Category: TZLoggingCategory;
1164  const Protocol: string; const Msg: string; ErrorCode: Integer; const Error: string);
1165 var
1166  I: Integer;
1167  Listener: IZLoggingListener;
1168  Event: TZLoggingEvent;
1169 begin
1170  if FLoggingListeners.Count = 0 then
1171  Exit;
1172  Event := TZLoggingEvent.Create(Category, Protocol, Msg, ErrorCode, Error);
1173  try
1174  for I := 0 to FLoggingListeners.Count - 1 do
1175  begin
1176  Listener := FLoggingListeners[I] as IZLoggingListener;
1177  try
1178  Listener.LogEvent(Event);
1179  except
1180  end;
1181  end;
1182  finally
1183  Event.Destroy;
1184  end;
1185 end;
1186 
1187 {**
1188  Logs a message about event with normal result code.
1189  @param Category a category of the message.
1190  @param Protocol a name of the protocol.
1191  @param Msg a description message.
1192 }
1193 procedure TZDriverManager.LogMessage(Category: TZLoggingCategory;
1194  const Protocol: string; const Msg: string);
1195 begin
1196  if FLoggingListeners.Count = 0 then
1197  Exit;
1198  LogError(Category, Protocol, Msg, 0, '');
1199 end;
1200 
1201 {**
1202  Constructs a valid URL
1203  @param Protocol the Driver-protocol (must be assigned).
1204  @param HostName the hostname (could be empty).
1205  @param Database the connection-database (could be empty).
1206  @param UserName the username (could be empty).
1207  @param Password the password(could be empty).
1208  @param Port the Server-Port (could be 0).
1209  @param Properties the Database-Properties (could be empty).
1210 }
1211 function TZDriverManager.ConstructURL(const Protocol, HostName, Database,
1212  UserName, Password: String; const Port: Integer;
1213  const Properties: TStrings = nil; const LibLocation: String = ''): String;
1214 begin
1215  FURL.Protocol := Protocol;
1216  FURL.HostName := HostName;
1217  FURL.Database := DataBase;
1218  FURL.UserName := UserName;
1219  FURL.Password := Password;
1220  FURL.Port := Port;
1221  if Assigned(Properties) then
1222  FURL.Properties.Text := Properties.Text;
1223  FURL.LibLocation := LibLocation;
1224  Result := FURL.URL;
1225 end;
1226 
1227 {**
1228  Resolves a database URL and fills the database connection parameters.
1229  @param Url an initial database URL.
1230  @param HostName a name of the database host.
1231  @param Port a port number.
1232  @param Database a database name.
1233  @param UserName a name of the database user.
1234  @param Password a user's password.
1235  @param ResutlInfo a result info parameters.
1236 }
1237 procedure TZDriverManager.ResolveDatabaseUrl(const Url: string; out HostName: string;
1238  out Port: Integer; out Database: string; out UserName: string;
1239  out Password: string; ResultInfo: TStrings = nil);
1240 begin
1241  FURL.URL := Url;
1242  HostName := FURL.HostName;
1243  Port := FURL.Port;
1244  DataBase := FURL.Database;
1245  UserName := FURL.UserName;
1246  PassWord := FURL.Password;
1247  if Assigned(ResultInfo) then
1248  ResultInfo.Text := FURL.Properties.Text;
1249 end;
1250 
1251 {**
1252  Resolves a database URL and fills the database parameter for MetaData.
1253  @param Url an initial database URL.
1254  @param Database a database name.
1255 }
1256 procedure TZDriverManager.ResolveDatabaseUrl(const Url: string; out Database: string);
1257 begin
1258  FURL.URL := Url;
1259  DataBase := FURL.Database;
1260 end;
1261 
1262 { EZSQLThrowable }
1263 
1264 {**
1265  Creates an exception with message string.
1266  @param Msg a error description.
1267 }
1268 constructor EZSQLThrowable.CreateClone(const E: EZSQLThrowable);
1269 begin
1270  inherited Create(E.Message);
1271  FErrorCode:=E.ErrorCode;
1272  FStatusCode:=E.Statuscode;
1273 end;
1274 
1275 constructor EZSQLThrowable.Create(const Msg: string);
1276 begin
1277  inherited Create(Msg);
1278  FErrorCode := -1;
1279 end;
1280 
1281 {**
1282  Creates an exception with message string.
1283  @param Msg a error description.
1284  @param ErrorCode a native server error code.
1285 }
1286 constructor EZSQLThrowable.CreateWithCode(const ErrorCode: Integer;
1287  const Msg: string);
1288 begin
1289  inherited Create(Msg);
1290  FErrorCode := ErrorCode;
1291 end;
1292 
1293 constructor EZSQLThrowable.CreateWithStatus(const StatusCode, Msg: string);
1294 begin
1295  inherited Create(Msg);
1296  FStatusCode := StatusCode;
1297 end;
1298 
1299 initialization
1300  DriverManager := TZDriverManager.Create;
1301 finalization
1302  DriverManager := nil;
1303 end.
1304