00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Native Plain Drivers for PostgreSQL }
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 ZPlainPostgreSqlDriver;
00055
00056 interface
00057
00058 {$I ZPlain.inc}
00059
00060 uses ZClasses, ZCompatibility, ZPlainDriver;
00061
00062 const
00063 { Type Lengths }
00064 NAMEDATALEN = 32;
00065
00066 { OIDNAMELEN should be set to NAMEDATALEN + sizeof(Oid) }
00067 OIDNAMELEN = 36;
00068
00069 INV_WRITE = $00020000;
00070 INV_READ = $00040000;
00071
00072 BLOB_SEEK_SET = 0;
00073 BLOB_SEEK_CUR = 1;
00074 BLOB_SEEK_END = 2;
00075
00076 type
00077
00078 { Application-visible enum types }
00079 TZPostgreSQLConnectStatusType = (
00080 CONNECTION_OK,
00081 CONNECTION_BAD
00082 );
00083
00084 TZPostgreSQLFieldCode=(
00085 {$IFNDEF VER130}
00086 PG_DIAG_SEVERITY=ord('S'),
00087 PG_DIAG_SQLSTATE=ord('C'),
00088 PG_DIAG_MESSAGE_PRIMARY=ord('M'),
00089 PG_DIAG_MESSAGE_DETAIL=ord('D'),
00090 PG_DIAG_MESSAGE_HINT=ord('H'),
00091 PG_DIAG_STATEMENT_POSITION=ord('P'),
00092 PG_DIAG_INTERNAL_POSITION=ord('p'),
00093 PG_DIAG_INTERNAL_QUERY=ord('q'),
00094 PG_DIAG_CONTEXT=ord('W'),
00095 PG_DIAG_SOURCE_FILE=ord('F'),
00096 PG_DIAG_SOURCE_LINE=ord('L'),
00097 PG_DIAG_SOURCE_FUNCTION=ord('R')
00098 {$ELSE}
00099 PG_DIAG_SEVERITY,
00100 PG_DIAG_SQLSTATE,
00101 PG_DIAG_MESSAGE_PRIMARY,
00102 PG_DIAG_MESSAGE_DETAIL,
00103 PG_DIAG_MESSAGE_HINT,
00104 PG_DIAG_STATEMENT_POSITION,
00105 PG_DIAG_INTERNAL_POSITION,
00106 PG_DIAG_INTERNAL_QUERY,
00107 PG_DIAG_CONTEXT,
00108 PG_DIAG_SOURCE_FILE,
00109 PG_DIAG_SOURCE_LINE,
00110 PG_DIAG_SOURCE_FUNCTION
00111 {$ENDIF}
00112 );
00113
00114 TZPostgreSQLExecStatusType = (
00115 PGRES_EMPTY_QUERY,
00116 PGRES_COMMAND_OK, { a query command that doesn't return anything
00117 was executed properly by the backend }
00118 PGRES_TUPLES_OK, { a query command that returns tuples
00119 was executed properly by the backend,
00120 PGresult contains the result tuples }
00121 PGRES_COPY_OUT, { Copy Out data transfer in progress }
00122 PGRES_COPY_IN, { Copy In data transfer in progress }
00123 PGRES_BAD_RESPONSE, { an unexpected response was recv'd from
00124 the backend }
00125 PGRES_NONFATAL_ERROR,
00126 PGRES_FATAL_ERROR
00127 );
00128
00129 { PGnotify represents the occurrence of a NOTIFY message.
00130 Ideally this would be an opaque typedef, but it's so simple that it's
00131 unlikely to change.
00132 NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
00133 whereas in earlier versions it was always your own backend's PID.
00134 }
00135 TZPostgreSQLNotify = packed record
00136 relname: PChar; { name of relation containing data }
00137 be_pid: Integer; { process id of backend }
00138 end;
00139
00140 PZPostgreSQLNotify = ^TZPostgreSQLNotify;
00141
00142 { PQnoticeProcessor is the function type for the notice-message callback. }
00143
00144 TZPostgreSQLNoticeProcessor = procedure(arg: Pointer; message: PChar); cdecl;
00145
00146 { Structure for the conninfo parameter definitions returned by PQconndefaults }
00147
00148 TZPostgreSQLConnectInfoOption = packed record
00149 keyword: PChar; { The keyword of the option }
00150 envvar: PChar; { Fallback environment variable name }
00151 compiled: PChar; { Fallback compiled in default value }
00152 val: PChar; { Options value }
00153 lab: PChar; { Label for field in connect dialog }
00154 dispchar: PChar; { Character to display for this field
00155 in a connect dialog. Values are:
00156 "" Display entered value as is
00157 "*" Password field - hide value
00158 "D" Debug options - don't
00159 create a field by default }
00160 dispsize: Integer; { Field size in characters for dialog }
00161 end;
00162
00163 PZPostgreSQLConnectInfoOption = ^TZPostgreSQLConnectInfoOption;
00164
00165 { PQArgBlock -- structure for PQfn() arguments }
00166
00167 TZPostgreSQLArgBlock = packed record
00168 len: Integer;
00169 isint: Integer;
00170 case u: Boolean of
00171 True: (ptr: PInteger); { can't use void (dec compiler barfs) }
00172 False: (_int: Integer);
00173 end;
00174
00175 PZPostgreSQLArgBlock = ^TZPostgreSQLArgBlock;
00176
00177 PZPostgreSQLConnect = Pointer;
00178 PZPostgreSQLResult = Pointer;
00179 Oid = Integer;
00180
00181 type
00182
00183 {** Represents a generic interface to PostgreSQL native API. }
00184 IZPostgreSQLPlainDriver = interface (IZPlainDriver)
00185 ['{03CD6345-2D7A-4FE2-B03D-3C5656789FEB}']
00186
00187 function EncodeBYTEA(Value: string;Handle: PZPostgreSQLConnect): string;
00188 function DecodeBYTEA(value: string): string;
00189
00190 function ConnectDatabase(ConnInfo: PChar): PZPostgreSQLConnect;
00191 function SetDatabaseLogin(Host, Port, Options, TTY, Db, User,Passwd: PChar): PZPostgreSQLConnect;
00192 function GetConnectDefaults: PZPostgreSQLConnectInfoOption;
00193
00194 procedure Finish(Handle: PZPostgreSQLConnect);
00195 procedure Reset(Handle: PZPostgreSQLConnect);
00196 function RequestCancel(Handle: PZPostgreSQLConnect): Integer;
00197 function GetDatabase(Handle: PZPostgreSQLConnect): PChar;
00198 function GetUser(Handle: PZPostgreSQLConnect): PChar;
00199 function GetPassword(Handle: PZPostgreSQLConnect): PChar;
00200 function GetHost(Handle: PZPostgreSQLConnect): PChar;
00201 function GetPort(Handle: PZPostgreSQLConnect): PChar;
00202 function GetTTY(Handle: PZPostgreSQLConnect): PChar; cdecl;
00203 function GetOptions(Handle: PZPostgreSQLConnect): PChar;
00204 function GetStatus(Handle: PZPostgreSQLConnect):TZPostgreSQLConnectStatusType;
00205
00206 function GetErrorMessage(Handle: PZPostgreSQLConnect): PChar;
00207 function GetSocket(Handle: PZPostgreSQLConnect): Integer;
00208 function GetBackendPID(Handle: PZPostgreSQLConnect): Integer;
00209 procedure Trace(Handle: PZPostgreSQLConnect; DebugPort: Pointer);
00210 procedure Untrace(Handle: PZPostgreSQLConnect);
00211 procedure SetNoticeProcessor(Handle: PZPostgreSQLConnect;Proc: TZPostgreSQLNoticeProcessor; Arg: Pointer);
00212
00213 function ExecuteQuery(Handle: PZPostgreSQLConnect;Query: PChar): PZPostgreSQLResult;
00214
00215 function Notifies(Handle: PZPostgreSQLConnect): PZPostgreSQLNotify;
00216 procedure FreeNotify(Handle: PZPostgreSQLNotify);
00217
00218 function SendQuery(Handle: PZPostgreSQLConnect; Query: PChar): Integer;
00219 function GetResult(Handle: PZPostgreSQLConnect): PZPostgreSQLResult;
00220 function IsBusy(Handle: PZPostgreSQLConnect): Integer;
00221 function ConsumeInput(Handle: PZPostgreSQLConnect): Integer;
00222 function GetLine(Handle: PZPostgreSQLConnect; Str: PChar;
00223 Length: Integer): Integer;
00224 function PutLine(Handle: PZPostgreSQLConnect; Str: PChar): Integer;
00225 function GetLineAsync(Handle: PZPostgreSQLConnect; Buffer: PChar;
00226 Length: Integer): Integer;
00227
00228 function PutBytes(Handle: PZPostgreSQLConnect; Buffer: PChar;
00229 Length: Integer): Integer;
00230 function EndCopy(Handle: PZPostgreSQLConnect): Integer;
00231 function ExecuteFunction(Handle: PZPostgreSQLConnect; fnid: Integer;
00232 result_buf, result_len: PInteger; result_is_int: Integer;
00233 args: PZPostgreSQLArgBlock; nargs: Integer): PZPostgreSQLResult;
00234 function GetResultStatus(Res: PZPostgreSQLResult):
00235 TZPostgreSQLExecStatusType;
00236
00237 function GetResultErrorMessage(Res: PZPostgreSQLResult): PChar;
00238 function GetResultErrorField(Res: PZPostgreSQLResult;FieldCode:TZPostgreSQLFieldCode):Pchar;
00239
00240 function GetRowCount(Res: PZPostgreSQLResult): Integer;
00241 function GetFieldCount(Res: PZPostgreSQLResult): Integer;
00242
00243 function GetBinaryTuples(Res: PZPostgreSQLResult): Integer;
00244 function GetFieldName(Res: PZPostgreSQLResult;
00245 FieldNum: Integer): PChar;
00246 function GetFieldNumber(Res: PZPostgreSQLResult;
00247 FieldName: PChar): Integer;
00248 function GetFieldType(Res: PZPostgreSQLResult;
00249 FieldNum: Integer): Oid;
00250 function GetFieldSize(Res: PZPostgreSQLResult;
00251 FieldNum: Integer): Integer;
00252 function GetFieldMode(Res: PZPostgreSQLResult;
00253 FieldNum: Integer): Integer;
00254 function GetCommandStatus(Res: PZPostgreSQLResult): PChar;
00255 function GetOidValue(Res: PZPostgreSQLResult): Oid;
00256 function GetOidStatus(Res: PZPostgreSQLResult): PChar;
00257 function GetCommandTuples(Res: PZPostgreSQLResult): PChar;
00258
00259 function GetValue(Res: PZPostgreSQLResult;
00260 TupNum, FieldNum: Integer): PChar;
00261 function GetLength(Res: PZPostgreSQLResult;
00262 TupNum, FieldNum: Integer): Integer;
00263 function GetIsNull(Res: PZPostgreSQLResult;
00264 TupNum, FieldNum: Integer): Integer;
00265 procedure Clear(Res: PZPostgreSQLResult);
00266
00267 function MakeEmptyResult(Handle: PZPostgreSQLConnect;
00268 Status: TZPostgreSQLExecStatusType): PZPostgreSQLResult;
00269
00270 function OpenLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
00271 Mode: Integer): Integer;
00272 function CloseLargeObject(Handle: PZPostgreSQLConnect;
00273 Fd: Integer): Integer;
00274 function ReadLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
00275 Buffer: PChar; Length: Integer): Integer;
00276 function WriteLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
00277 Buffer: PChar; Length: Integer): Integer;
00278 function SeekLargeObject(Handle: PZPostgreSQLConnect;
00279 Fd, Offset, Whence: Integer): Integer;
00280 function CreateLargeObject(Handle: PZPostgreSQLConnect;
00281 Mode: Integer): Oid;
00282 function TellLargeObject(Handle: PZPostgreSQLConnect;
00283 Fd: Integer): Integer;
00284 function UnlinkLargeObject(Handle: PZPostgreSQLConnect;
00285 ObjId: Oid): Integer;
00286 function ImportLargeObject(Handle: PZPostgreSQLConnect;
00287 FileName: PChar): Oid;
00288 function ExportLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
00289 FileName: PChar): Integer;
00290 end;
00291
00292
00293 {** Implements a driver for PostgreSQL 7.4 }
00294 TZPostgreSQL7PlainDriver = class(TZAbstractObject, IZPlainDriver,
00295 IZPostgreSQLPlainDriver)
00296 public
00297 constructor Create;
00298
00299 function GetProtocol: string;
00300 function GetDescription: string;
00301 procedure Initialize;
00302
00303 function EncodeBYTEA(Value: string;Handle: PZPostgreSQLConnect): string;
00304 function DecodeBYTEA(value: string): string;
00305
00306 function ConnectDatabase(ConnInfo: PChar): PZPostgreSQLConnect;
00307 function SetDatabaseLogin(Host, Port, Options, TTY, Db, User,
00308 Passwd: PChar): PZPostgreSQLConnect;
00309 function GetConnectDefaults: PZPostgreSQLConnectInfoOption;
00310
00311 procedure Finish(Handle: PZPostgreSQLConnect);
00312 procedure Reset(Handle: PZPostgreSQLConnect);
00313 function RequestCancel(Handle: PZPostgreSQLConnect): Integer;
00314 function GetDatabase(Handle: PZPostgreSQLConnect): PChar;
00315 function GetUser(Handle: PZPostgreSQLConnect): PChar;
00316 function GetPassword(Handle: PZPostgreSQLConnect): PChar;
00317 function GetHost(Handle: PZPostgreSQLConnect): PChar;
00318 function GetPort(Handle: PZPostgreSQLConnect): PChar;
00319 function GetTTY(Handle: PZPostgreSQLConnect): PChar; cdecl;
00320 function GetOptions(Handle: PZPostgreSQLConnect): PChar;
00321 function GetStatus(Handle: PZPostgreSQLConnect):
00322 TZPostgreSQLConnectStatusType;
00323
00324 function GetErrorMessage(Handle: PZPostgreSQLConnect): PChar;
00325 function GetSocket(Handle: PZPostgreSQLConnect): Integer;
00326 function GetBackendPID(Handle: PZPostgreSQLConnect): Integer;
00327 procedure Trace(Handle: PZPostgreSQLConnect; DebugPort: Pointer);
00328 procedure Untrace(Handle: PZPostgreSQLConnect);
00329 procedure SetNoticeProcessor(Handle: PZPostgreSQLConnect;
00330 Proc: TZPostgreSQLNoticeProcessor; Arg: Pointer);
00331
00332 function ExecuteQuery(Handle: PZPostgreSQLConnect;
00333 Query: PChar): PZPostgreSQLResult;
00334
00335 function Notifies(Handle: PZPostgreSQLConnect): PZPostgreSQLNotify;
00336 procedure FreeNotify(Handle: PZPostgreSQLNotify);
00337
00338 function SendQuery(Handle: PZPostgreSQLConnect; Query: PChar): Integer;
00339 function GetResult(Handle: PZPostgreSQLConnect): PZPostgreSQLResult;
00340 function IsBusy(Handle: PZPostgreSQLConnect): Integer;
00341 function ConsumeInput(Handle: PZPostgreSQLConnect): Integer;
00342 function GetLine(Handle: PZPostgreSQLConnect; Buffer: PChar;
00343 Length: Integer): Integer;
00344 function PutLine(Handle: PZPostgreSQLConnect; Buffer: PChar): Integer;
00345 function GetLineAsync(Handle: PZPostgreSQLConnect; Buffer: PChar;
00346 Length: Integer): Integer;
00347
00348 function PutBytes(Handle: PZPostgreSQLConnect; Buffer: PChar;
00349 Length: Integer): Integer;
00350 function EndCopy(Handle: PZPostgreSQLConnect): Integer;
00351 function ExecuteFunction(Handle: PZPostgreSQLConnect; fnid: Integer;
00352 result_buf, result_len: PInteger; result_is_int: Integer;
00353 args: PZPostgreSQLArgBlock; nargs: Integer): PZPostgreSQLResult;
00354 function GetResultStatus(Res: PZPostgreSQLResult):
00355 TZPostgreSQLExecStatusType;
00356 function GetResultErrorMessage(Res: PZPostgreSQLResult): PChar;
00357 function GetResultErrorField(Res: PZPostgreSQLResult;FieldCode:TZPostgreSQLFieldCode):PChar;
00358
00359 function GetRowCount(Res: PZPostgreSQLResult): Integer;
00360 function GetFieldCount(Res: PZPostgreSQLResult): Integer;
00361
00362 function GetBinaryTuples(Res: PZPostgreSQLResult): Integer;
00363 function GetFieldName(Res: PZPostgreSQLResult;
00364 FieldNum: Integer): PChar;
00365 function GetFieldNumber(Res: PZPostgreSQLResult;
00366 FieldName: PChar): Integer;
00367 function GetFieldType(Res: PZPostgreSQLResult;
00368 FieldNum: Integer): Oid;
00369 function GetFieldSize(Res: PZPostgreSQLResult;
00370 FieldNum: Integer): Integer;
00371 function GetFieldMode(Res: PZPostgreSQLResult;
00372 FieldNum: Integer): Integer;
00373 function GetCommandStatus(Res: PZPostgreSQLResult): PChar;
00374 function GetOidValue(Res: PZPostgreSQLResult): Oid;
00375 function GetOidStatus(Res: PZPostgreSQLResult): PChar;
00376 function GetCommandTuples(Res: PZPostgreSQLResult): PChar;
00377
00378 function GetValue(Res: PZPostgreSQLResult;
00379 TupNum, FieldNum: Integer): PChar;
00380 function GetLength(Res: PZPostgreSQLResult;
00381 TupNum, FieldNum: Integer): Integer;
00382 function GetIsNull(Res: PZPostgreSQLResult;
00383 TupNum, FieldNum: Integer): Integer;
00384 procedure Clear(Res: PZPostgreSQLResult);
00385
00386 function MakeEmptyResult(Handle: PZPostgreSQLConnect;
00387 Status: TZPostgreSQLExecStatusType): PZPostgreSQLResult;
00388
00389 function OpenLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
00390 Mode: Integer): Integer;
00391 function CloseLargeObject(Handle: PZPostgreSQLConnect;
00392 Fd: Integer): Integer;
00393 function ReadLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
00394 Buffer: PChar; Length: Integer): Integer;
00395 function WriteLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
00396 Buffer: PChar; Length: Integer): Integer;
00397 function SeekLargeObject(Handle: PZPostgreSQLConnect;
00398 Fd, Offset, Whence: Integer): Integer;
00399 function CreateLargeObject(Handle: PZPostgreSQLConnect;
00400 Mode: Integer): Oid;
00401 function TellLargeObject(Handle: PZPostgreSQLConnect;
00402 Fd: Integer): Integer;
00403 function UnlinkLargeObject(Handle: PZPostgreSQLConnect;
00404 ObjId: Oid): Integer;
00405 function ImportLargeObject(Handle: PZPostgreSQLConnect;
00406 FileName: PChar): Oid;
00407 function ExportLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
00408 FileName: PChar): Integer;
00409 end;
00410
00411
00412 {** Implements a driver for PostgreSQL 8.1 }
00413 TZPostgreSQL8PlainDriver = class(TZAbstractObject, IZPlainDriver,IZPostgreSQLPlainDriver)
00414 public
00415 constructor Create;
00416
00417 function GetProtocol: string;
00418 function GetDescription: string;
00419 procedure Initialize;
00420
00421 function ConnectDatabase(ConnInfo: PChar): PZPostgreSQLConnect;
00422 function SetDatabaseLogin(Host, Port, Options, TTY, Db, User,
00423 Passwd: PChar): PZPostgreSQLConnect;
00424 function GetConnectDefaults: PZPostgreSQLConnectInfoOption;
00425
00426 function EncodeBYTEA(Value: string;Handle: PZPostgreSQLConnect): string;
00427 function DecodeBYTEA(value: string): string;
00428
00429 procedure Finish(Handle: PZPostgreSQLConnect);
00430 procedure Reset(Handle: PZPostgreSQLConnect);
00431 function RequestCancel(Handle: PZPostgreSQLConnect): Integer;
00432 function GetDatabase(Handle: PZPostgreSQLConnect): PChar;
00433 function GetUser(Handle: PZPostgreSQLConnect): PChar;
00434 function GetPassword(Handle: PZPostgreSQLConnect): PChar;
00435 function GetHost(Handle: PZPostgreSQLConnect): PChar;
00436 function GetPort(Handle: PZPostgreSQLConnect): PChar;
00437 function GetTTY(Handle: PZPostgreSQLConnect): PChar; cdecl;
00438 function GetOptions(Handle: PZPostgreSQLConnect): PChar;
00439 function GetStatus(Handle: PZPostgreSQLConnect):
00440 TZPostgreSQLConnectStatusType;
00441
00442 function GetErrorMessage(Handle: PZPostgreSQLConnect): PChar;
00443 function GetSocket(Handle: PZPostgreSQLConnect): Integer;
00444 function GetBackendPID(Handle: PZPostgreSQLConnect): Integer;
00445 procedure Trace(Handle: PZPostgreSQLConnect; DebugPort: Pointer);
00446 procedure Untrace(Handle: PZPostgreSQLConnect);
00447 procedure SetNoticeProcessor(Handle: PZPostgreSQLConnect;
00448 Proc: TZPostgreSQLNoticeProcessor; Arg: Pointer);
00449
00450 function ExecuteQuery(Handle: PZPostgreSQLConnect;
00451 Query: PChar): PZPostgreSQLResult;
00452
00453 function Notifies(Handle: PZPostgreSQLConnect): PZPostgreSQLNotify;
00454 procedure FreeNotify(Handle: PZPostgreSQLNotify);
00455
00456 function SendQuery(Handle: PZPostgreSQLConnect; Query: PChar): Integer;
00457 function GetResult(Handle: PZPostgreSQLConnect): PZPostgreSQLResult;
00458 function IsBusy(Handle: PZPostgreSQLConnect): Integer;
00459 function ConsumeInput(Handle: PZPostgreSQLConnect): Integer;
00460 function GetLine(Handle: PZPostgreSQLConnect; Buffer: PChar;
00461 Length: Integer): Integer;
00462 function PutLine(Handle: PZPostgreSQLConnect; Buffer: PChar): Integer;
00463 function GetLineAsync(Handle: PZPostgreSQLConnect; Buffer: PChar;
00464 Length: Integer): Integer;
00465
00466 function PutBytes(Handle: PZPostgreSQLConnect; Buffer: PChar;
00467 Length: Integer): Integer;
00468 function EndCopy(Handle: PZPostgreSQLConnect): Integer;
00469 function ExecuteFunction(Handle: PZPostgreSQLConnect; fnid: Integer;
00470 result_buf, result_len: PInteger; result_is_int: Integer;
00471 args: PZPostgreSQLArgBlock; nargs: Integer): PZPostgreSQLResult;
00472 function GetResultStatus(Res: PZPostgreSQLResult):
00473 TZPostgreSQLExecStatusType;
00474
00475 function GetResultErrorMessage(Res: PZPostgreSQLResult): PChar;
00476 function GetResultErrorField(Res: PZPostgreSQLResult;FieldCode:TZPostgreSQLFieldCode):PChar;
00477
00478 function GetRowCount(Res: PZPostgreSQLResult): Integer;
00479 function GetFieldCount(Res: PZPostgreSQLResult): Integer;
00480
00481 function GetBinaryTuples(Res: PZPostgreSQLResult): Integer;
00482 function GetFieldName(Res: PZPostgreSQLResult;
00483 FieldNum: Integer): PChar;
00484 function GetFieldNumber(Res: PZPostgreSQLResult;
00485 FieldName: PChar): Integer;
00486 function GetFieldType(Res: PZPostgreSQLResult;
00487 FieldNum: Integer): Oid;
00488 function GetFieldSize(Res: PZPostgreSQLResult;
00489 FieldNum: Integer): Integer;
00490 function GetFieldMode(Res: PZPostgreSQLResult;
00491 FieldNum: Integer): Integer;
00492 function GetCommandStatus(Res: PZPostgreSQLResult): PChar;
00493 function GetOidValue(Res: PZPostgreSQLResult): Oid;
00494 function GetOidStatus(Res: PZPostgreSQLResult): PChar;
00495 function GetCommandTuples(Res: PZPostgreSQLResult): PChar;
00496
00497 function GetValue(Res: PZPostgreSQLResult;
00498 TupNum, FieldNum: Integer): PChar;
00499 function GetLength(Res: PZPostgreSQLResult;
00500 TupNum, FieldNum: Integer): Integer;
00501 function GetIsNull(Res: PZPostgreSQLResult;
00502 TupNum, FieldNum: Integer): Integer;
00503 procedure Clear(Res: PZPostgreSQLResult);
00504
00505 function MakeEmptyResult(Handle: PZPostgreSQLConnect;
00506 Status: TZPostgreSQLExecStatusType): PZPostgreSQLResult;
00507
00508 function OpenLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
00509 Mode: Integer): Integer;
00510 function CloseLargeObject(Handle: PZPostgreSQLConnect;
00511 Fd: Integer): Integer;
00512 function ReadLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
00513 Buffer: PChar; Length: Integer): Integer;
00514 function WriteLargeObject(Handle: PZPostgreSQLConnect; Fd: Integer;
00515 Buffer: PChar; Length: Integer): Integer;
00516 function SeekLargeObject(Handle: PZPostgreSQLConnect;
00517 Fd, Offset, Whence: Integer): Integer;
00518 function CreateLargeObject(Handle: PZPostgreSQLConnect;
00519 Mode: Integer): Oid;
00520 function TellLargeObject(Handle: PZPostgreSQLConnect;
00521 Fd: Integer): Integer;
00522 function UnlinkLargeObject(Handle: PZPostgreSQLConnect;
00523 ObjId: Oid): Integer;
00524 function ImportLargeObject(Handle: PZPostgreSQLConnect;
00525 FileName: PChar): Oid;
00526 function ExportLargeObject(Handle: PZPostgreSQLConnect; ObjId: Oid;
00527 FileName: PChar): Integer;
00528 end;
00529
00530
00531 implementation
00532
00533 uses SysUtils, ZPlainPostgreSql7,ZPlainPostgreSql8;
00534
00535
00536
00537 { TZPostgreSQL7PlainDriver }
00538
00539 constructor TZPostgreSQL7PlainDriver.Create;
00540 begin
00541 end;
00542
00543 function TZPostgreSQL7PlainDriver.GetProtocol: string;
00544 begin
00545 Result := 'postgresql-7';
00546 end;
00547
00548 function TZPostgreSQL7PlainDriver.GetDescription: string;
00549 begin
00550 Result := 'Native Plain Driver for PostgreSQL 7.x';
00551 end;
00552
00553 procedure TZPostgreSQL7PlainDriver.Initialize;
00554 begin
00555 ZPlainPostgreSql7.LibraryLoader.LoadIfNeeded;
00556 end;
00557
00558 procedure TZPostgreSQL7PlainDriver.Clear(Res: PZPostgreSQLResult);
00559 begin
00560 ZPlainPostgreSql7.PQclear(Res);
00561 end;
00562
00563 function TZPostgreSQL7PlainDriver.CloseLargeObject(
00564 Handle: PZPostgreSQLConnect; Fd: Integer): Integer;
00565 begin
00566 Result := ZPlainPostgreSql7.lo_close(Handle, Fd);
00567 end;
00568
00569 function TZPostgreSQL7PlainDriver.ConnectDatabase(
00570 ConnInfo: PChar): PZPostgreSQLConnect;
00571 begin
00572 Result := ZPlainPostgreSql7.PQconnectdb(ConnInfo);
00573 end;
00574
00575 function TZPostgreSQL7PlainDriver.ConsumeInput(
00576 Handle: PZPostgreSQLConnect): Integer;
00577 begin
00578 Result := ZPlainPostgreSql7.PQconsumeInput(Handle);
00579 end;
00580
00581 function TZPostgreSQL7PlainDriver.CreateLargeObject(
00582 Handle: PZPostgreSQLConnect; Mode: Integer): Oid;
00583 begin
00584 Result := ZPlainPostgreSql7.lo_creat(Handle, Mode);
00585 end;
00586
00587 function TZPostgreSQL7PlainDriver.DecodeBYTEA(value: string): string;
00588 begin
00589 result:=value;
00590 end;
00591
00592 function TZPostgreSQL7PlainDriver.EncodeBYTEA(Value: string; Handle: PZPostgreSQLConnect): string;
00593 begin
00594 result:=value;
00595 end;
00596
00597 function TZPostgreSQL7PlainDriver.EndCopy(
00598 Handle: PZPostgreSQLConnect): Integer;
00599 begin
00600 Result := ZPlainPostgreSql7.PQendcopy(Handle);
00601 end;
00602
00603 function TZPostgreSQL7PlainDriver.ExecuteFunction(
00604 Handle: PZPostgreSQLConnect; fnid: Integer; result_buf,
00605 result_len: PInteger; result_is_int: Integer; args: PZPostgreSQLArgBlock;
00606 nargs: Integer): PZPostgreSQLResult;
00607 begin
00608 Result := ZPlainPostgreSql7.PQfn(Handle, fnid, result_buf,
00609 result_len, result_is_int, ZPlainPostgreSql7.PPQArgBlock(args), nargs);
00610 end;
00611
00612 function TZPostgreSQL7PlainDriver.ExecuteQuery(
00613 Handle: PZPostgreSQLConnect; Query: PChar): PZPostgreSQLResult;
00614 begin
00615 Result := ZPlainPostgreSql7.PQexec(Handle, Query);
00616 end;
00617
00618 function TZPostgreSQL7PlainDriver.ExportLargeObject(
00619 Handle: PZPostgreSQLConnect; ObjId: Oid; FileName: PChar): Integer;
00620 begin
00621 Result := ZPlainPostgreSql7.lo_export(Handle, ObjId, FileName);
00622 end;
00623
00624 procedure TZPostgreSQL7PlainDriver.Finish(Handle: PZPostgreSQLConnect);
00625 begin
00626 ZPlainPostgreSql7.PQfinish(Handle);
00627 end;
00628
00629 procedure TZPostgreSQL7PlainDriver.FreeNotify(Handle: PZPostgreSQLNotify);
00630 begin
00631 ZPlainPostgreSql7.PQfreeNotify(ZPlainPostgreSql7.PPGnotify(Handle));
00632 end;
00633
00634 function TZPostgreSQL7PlainDriver.GetBackendPID(
00635 Handle: PZPostgreSQLConnect): Integer;
00636 begin
00637 Result := ZPlainPostgreSql7.PQbackendPID(Handle);
00638 end;
00639
00640 function TZPostgreSQL7PlainDriver.GetBinaryTuples(
00641 Res: PZPostgreSQLResult): Integer;
00642 begin
00643 Result := ZPlainPostgreSql7.PQbinaryTuples(Res);
00644 end;
00645
00646 function TZPostgreSQL7PlainDriver.GetCommandStatus(
00647 Res: PZPostgreSQLResult): PChar;
00648 begin
00649 Result := ZPlainPostgreSql7.PQcmdStatus(Res);
00650 end;
00651
00652 function TZPostgreSQL7PlainDriver.GetCommandTuples(
00653 Res: PZPostgreSQLResult): PChar;
00654 begin
00655 Result := ZPlainPostgreSql7.PQcmdTuples(Res);
00656 end;
00657
00658 function TZPostgreSQL7PlainDriver.GetConnectDefaults:
00659 PZPostgreSQLConnectInfoOption;
00660 begin
00661 Result := PZPostgreSQLConnectInfoOption(ZPlainPostgreSql7.PQconndefaults);
00662 end;
00663
00664 function TZPostgreSQL7PlainDriver.GetDatabase(
00665 Handle: PZPostgreSQLConnect): PChar;
00666 begin
00667 Result := ZPlainPostgreSql7.PQdb(Handle);
00668 end;
00669
00670 function TZPostgreSQL7PlainDriver.GetErrorMessage(
00671 Handle: PZPostgreSQLConnect): PChar;
00672 begin
00673 Result := ZPlainPostgreSql7.PQerrorMessage(Handle);
00674 end;
00675
00676 function TZPostgreSQL7PlainDriver.GetFieldCount(
00677 Res: PZPostgreSQLResult): Integer;
00678 begin
00679 Result := ZPlainPostgreSql7.PQnfields(Res);
00680 end;
00681
00682 function TZPostgreSQL7PlainDriver.GetFieldMode(Res: PZPostgreSQLResult;
00683 FieldNum: Integer): Integer;
00684 begin
00685 Result := ZPlainPostgreSql7.PQfmod(Res, FieldNum);
00686 end;
00687
00688 function TZPostgreSQL7PlainDriver.GetFieldName(Res: PZPostgreSQLResult;
00689 FieldNum: Integer): PChar;
00690 begin
00691 Result := ZPlainPostgreSql7.PQfname(Res, FieldNum);
00692 end;
00693
00694 function TZPostgreSQL7PlainDriver.GetFieldNumber(
00695 Res: PZPostgreSQLResult; FieldName: PChar): Integer;
00696 begin
00697 Result := ZPlainPostgreSql7.PQfnumber(Res, FieldName);
00698 end;
00699
00700 function TZPostgreSQL7PlainDriver.GetFieldSize(Res: PZPostgreSQLResult;
00701 FieldNum: Integer): Integer;
00702 begin
00703 Result := ZPlainPostgreSql7.PQfsize(Res, FieldNum);
00704 end;
00705
00706 function TZPostgreSQL7PlainDriver.GetFieldType(Res: PZPostgreSQLResult;
00707 FieldNum: Integer): Oid;
00708 begin
00709 Result := ZPlainPostgreSql7.PQftype(Res, FieldNum);
00710 end;
00711
00712 function TZPostgreSQL7PlainDriver.GetHost(
00713 Handle: PZPostgreSQLConnect): PChar;
00714 begin
00715 Result := ZPlainPostgreSql7.PQhost(Handle);
00716 end;
00717
00718 function TZPostgreSQL7PlainDriver.GetIsNull(Res: PZPostgreSQLResult;
00719 TupNum, FieldNum: Integer): Integer;
00720 begin
00721 Result := ZPlainPostgreSql7.PQgetisnull(Res, TupNum, FieldNum);
00722 end;
00723
00724 function TZPostgreSQL7PlainDriver.GetLength(Res: PZPostgreSQLResult;
00725 TupNum, FieldNum: Integer): Integer;
00726 begin
00727 Result := ZPlainPostgreSql7.PQgetlength(Res, TupNum, FieldNum);
00728 end;
00729
00730 function TZPostgreSQL7PlainDriver.GetLine(Handle: PZPostgreSQLConnect;
00731 Buffer: PChar; Length: Integer): Integer;
00732 begin
00733 Result := ZPlainPostgreSql7.PQgetline(Handle, Buffer, Length);
00734 end;
00735
00736 function TZPostgreSQL7PlainDriver.GetLineAsync(
00737 Handle: PZPostgreSQLConnect; Buffer: PChar; Length: Integer): Integer;
00738 begin
00739 Result := ZPlainPostgreSql7.PQgetlineAsync(Handle, Buffer, Length);
00740 end;
00741
00742 function TZPostgreSQL7PlainDriver.GetOidStatus(
00743 Res: PZPostgreSQLResult): PChar;
00744 begin
00745 Result := ZPlainPostgreSql7.PQoidStatus(Res);
00746 end;
00747
00748 function TZPostgreSQL7PlainDriver.GetOidValue(
00749 Res: PZPostgreSQLResult): Oid;
00750 begin
00751 Result := ZPlainPostgreSql7.PQoidValue(Res);
00752 end;
00753
00754 function TZPostgreSQL7PlainDriver.GetOptions(
00755 Handle: PZPostgreSQLConnect): PChar;
00756 begin
00757 Result := ZPlainPostgreSql7.PQoptions(Handle);
00758 end;
00759
00760 function TZPostgreSQL7PlainDriver.GetPassword(
00761 Handle: PZPostgreSQLConnect): PChar;
00762 begin
00763 Result := ZPlainPostgreSql7.PQpass(Handle);
00764 end;
00765
00766 function TZPostgreSQL7PlainDriver.GetPort(
00767 Handle: PZPostgreSQLConnect): PChar;
00768 begin
00769 Result := ZPlainPostgreSql7.PQport(Handle);
00770 end;
00771
00772 function TZPostgreSQL7PlainDriver.GetResult(
00773 Handle: PZPostgreSQLConnect): PZPostgreSQLResult;
00774 begin
00775 Result := ZPlainPostgreSql7.PQgetResult(Handle);
00776 end;
00777
00778 function TZPostgreSQL7PlainDriver.GetResultErrorField(Res: PZPostgreSQLResult; FieldCode: TZPostgreSQLFieldCode): PChar;
00779 begin
00780
00781 result:='';
00782 end;
00783
00784 function TZPostgreSQL7PlainDriver.GetResultErrorMessage(
00785 Res: PZPostgreSQLResult): PChar;
00786 begin
00787 Result := ZPlainPostgreSql7.PQresultErrorMessage(Res);
00788 end;
00789
00790 function TZPostgreSQL7PlainDriver.GetResultStatus(
00791 Res: PZPostgreSQLResult): TZPostgreSQLExecStatusType;
00792 begin
00793 Result := TZPostgreSQLExecStatusType(ZPlainPostgreSql7.PQresultStatus(Res));
00794 end;
00795
00796 function TZPostgreSQL7PlainDriver.GetRowCount(
00797 Res: PZPostgreSQLResult): Integer;
00798 begin
00799 Result := ZPlainPostgreSql7.PQntuples(Res);
00800 end;
00801
00802 function TZPostgreSQL7PlainDriver.GetSocket(
00803 Handle: PZPostgreSQLConnect): Integer;
00804 begin
00805 Result := ZPlainPostgreSql7.PQsocket(Handle);
00806 end;
00807
00808 function TZPostgreSQL7PlainDriver.GetStatus(
00809 Handle: PZPostgreSQLConnect): TZPostgreSQLConnectStatusType;
00810 begin
00811 Result := TZPostgreSQLConnectStatusType(ZPlainPostgreSql7.PQstatus(Handle));
00812 end;
00813
00814 function TZPostgreSQL7PlainDriver.GetTTY(
00815 Handle: PZPostgreSQLConnect): PChar;
00816 begin
00817 Result := ZPlainPostgreSql7.PQtty(Handle);
00818 end;
00819
00820 function TZPostgreSQL7PlainDriver.GetUser(
00821 Handle: PZPostgreSQLConnect): PChar;
00822 begin
00823 Result := ZPlainPostgreSql7.PQuser(Handle);
00824 end;
00825
00826 function TZPostgreSQL7PlainDriver.GetValue(Res: PZPostgreSQLResult;
00827 TupNum, FieldNum: Integer): PChar;
00828 begin
00829 Result := ZPlainPostgreSql7.PQgetvalue(Res, TupNum, FieldNum);
00830 end;
00831
00832 function TZPostgreSQL7PlainDriver.ImportLargeObject(
00833 Handle: PZPostgreSQLConnect; FileName: PChar): Oid;
00834 begin
00835 Result := ZPlainPostgreSql7.lo_import(Handle, FileName);
00836 end;
00837
00838 function TZPostgreSQL7PlainDriver.IsBusy(
00839 Handle: PZPostgreSQLConnect): Integer;
00840 begin
00841 Result := ZPlainPostgreSql7.PQisBusy(Handle);
00842 end;
00843
00844 function TZPostgreSQL7PlainDriver.MakeEmptyResult(
00845 Handle: PZPostgreSQLConnect;
00846 Status: TZPostgreSQLExecStatusType): PZPostgreSQLResult;
00847 begin
00848 Result := ZPlainPostgreSql7.PQmakeEmptyPGresult(Handle,
00849 ZPlainPostgreSql7.ExecStatusType(Status));
00850 end;
00851
00852 function TZPostgreSQL7PlainDriver.Notifies(
00853 Handle: PZPostgreSQLConnect): PZPostgreSQLNotify;
00854 begin
00855 Result := PZPostgreSQLNotify(ZPlainPostgreSql7.PQnotifies(Handle));
00856 end;
00857
00858 function TZPostgreSQL7PlainDriver.OpenLargeObject(
00859 Handle: PZPostgreSQLConnect; ObjId: Oid; Mode: Integer): Integer;
00860 begin
00861 Result := ZPlainPostgreSql7.lo_open(Handle, ObjId, Mode);
00862 end;
00863
00864 function TZPostgreSQL7PlainDriver.PutBytes(Handle: PZPostgreSQLConnect;
00865 Buffer: PChar; Length: Integer): Integer;
00866 begin
00867 Result := ZPlainPostgreSql7.PQputnbytes(Handle, Buffer, Length);
00868 end;
00869
00870 function TZPostgreSQL7PlainDriver.PutLine(Handle: PZPostgreSQLConnect;
00871 Buffer: PChar): Integer;
00872 begin
00873 Result := ZPlainPostgreSql7.PQputline(Handle, Buffer);
00874 end;
00875
00876 function TZPostgreSQL7PlainDriver.ReadLargeObject(
00877 Handle: PZPostgreSQLConnect; Fd: Integer; Buffer: PChar;
00878 Length: Integer): Integer;
00879 begin
00880 Result := ZPlainPostgreSql7.lo_read(Handle, Fd, Buffer, Length);
00881 end;
00882
00883 function TZPostgreSQL7PlainDriver.RequestCancel(
00884 Handle: PZPostgreSQLConnect): Integer;
00885 begin
00886 Result := ZPlainPostgreSql7.PQrequestCancel(Handle);
00887 end;
00888
00889 procedure TZPostgreSQL7PlainDriver.Reset(Handle: PZPostgreSQLConnect);
00890 begin
00891 ZPlainPostgreSql7.PQreset(Handle);
00892 end;
00893
00894 function TZPostgreSQL7PlainDriver.SeekLargeObject(
00895 Handle: PZPostgreSQLConnect; Fd, Offset, Whence: Integer): Integer;
00896 begin
00897 Result := ZPlainPostgreSql7.lo_lseek(Handle, Fd, Offset, Whence);
00898 end;
00899
00900 function TZPostgreSQL7PlainDriver.SendQuery(Handle: PZPostgreSQLConnect;
00901 Query: PChar): Integer;
00902 begin
00903 Result := ZPlainPostgreSql7.PQsendQuery(Handle, Query);
00904 end;
00905
00906 function TZPostgreSQL7PlainDriver.SetDatabaseLogin(Host, Port, Options,
00907 TTY, Db, User, Passwd: PChar): PZPostgreSQLConnect;
00908 begin
00909 Result := ZPlainPostgreSql7.PQsetdbLogin(Host, Port, Options, TTY, Db,
00910 User, Passwd);
00911 end;
00912
00913 procedure TZPostgreSQL7PlainDriver.SetNoticeProcessor(
00914 Handle: PZPostgreSQLConnect; Proc: TZPostgreSQLNoticeProcessor;
00915 Arg: Pointer);
00916 begin
00917 ZPlainPostgreSql7.PQsetNoticeProcessor(Handle, Proc, Arg);
00918 end;
00919
00920 function TZPostgreSQL7PlainDriver.TellLargeObject(
00921 Handle: PZPostgreSQLConnect; Fd: Integer): Integer;
00922 begin
00923 Result := ZPlainPostgreSql7.lo_tell(Handle, Fd);
00924 end;
00925
00926 procedure TZPostgreSQL7PlainDriver.Trace(Handle: PZPostgreSQLConnect;
00927 DebugPort: Pointer);
00928 begin
00929 ZPlainPostgreSql7.PQtrace(Handle, DebugPort);
00930 end;
00931
00932 function TZPostgreSQL7PlainDriver.UnlinkLargeObject(
00933 Handle: PZPostgreSQLConnect; ObjId: Oid): Integer;
00934 begin
00935 Result := ZPlainPostgreSql7.lo_unlink(Handle, ObjId);
00936 end;
00937
00938 procedure TZPostgreSQL7PlainDriver.Untrace(Handle: PZPostgreSQLConnect);
00939 begin
00940 ZPlainPostgreSql7.PQuntrace(Handle);
00941 end;
00942
00943 function TZPostgreSQL7PlainDriver.WriteLargeObject(
00944 Handle: PZPostgreSQLConnect; Fd: Integer; Buffer: PChar;
00945 Length: Integer): Integer;
00946 begin
00947 Result := ZPlainPostgreSql7.lo_write(Handle, Fd, Buffer, Length);
00948 end;
00949
00950
00951 { TZPostgreSQL8PlainDriver }
00952
00953 constructor TZPostgreSQL8PlainDriver.Create;
00954 begin
00955 end;
00956
00957 function TZPostgreSQL8PlainDriver.GetProtocol: string;
00958 begin
00959 Result := 'postgresql-8';
00960 end;
00961
00962 function TZPostgreSQL8PlainDriver.GetDescription: string;
00963 begin
00964 Result := 'Native Plain Driver for PostgreSQL 8.x';
00965 end;
00966
00967 procedure TZPostgreSQL8PlainDriver.Initialize;
00968 begin
00969 ZPlainPostgreSql8.LibraryLoader.LoadIfNeeded;
00970 end;
00971
00972 procedure TZPostgreSQL8PlainDriver.Clear(Res: PZPostgreSQLResult);
00973 begin
00974 ZPlainPostgreSql8.PQclear(Res);
00975 end;
00976
00977 function TZPostgreSQL8PlainDriver.CloseLargeObject(
00978 Handle: PZPostgreSQLConnect; Fd: Integer): Integer;
00979 begin
00980 Result := ZPlainPostgreSql8.lo_close(Handle, Fd);
00981 end;
00982
00983 function TZPostgreSQL8PlainDriver.ConnectDatabase(
00984 ConnInfo: PChar): PZPostgreSQLConnect;
00985 begin
00986 Result := ZPlainPostgreSql8.PQconnectdb(ConnInfo);
00987 end;
00988
00989 function TZPostgreSQL8PlainDriver.ConsumeInput(
00990 Handle: PZPostgreSQLConnect): Integer;
00991 begin
00992 Result := ZPlainPostgreSql8.PQconsumeInput(Handle);
00993 end;
00994
00995 function TZPostgreSQL8PlainDriver.CreateLargeObject(
00996 Handle: PZPostgreSQLConnect; Mode: Integer): Oid;
00997 begin
00998 Result := ZPlainPostgreSql8.lo_creat(Handle, Mode);
00999 end;
01000
01001 function TZPostgreSQL8PlainDriver.DecodeBYTEA(value: string): string;
01002 var decoded:pchar;
01003 len:Longword;
01004 begin
01005 decoded:=ZPlainPostgreSql8.PQUnescapeBytea(pansichar(value),@len);
01006 SetLength(result,len);
01007 if (len > 0) then Move(decoded^,result[1],len);
01008 ZPlainPostgreSql8.PQFreemem(decoded);
01009 end;
01010
01011 function TZPostgreSQL8PlainDriver.EncodeBYTEA(Value: string;Handle: PZPostgreSQLConnect): string;
01012 var encoded:pchar;
01013 len:Longword;
01014 leng:cardinal;
01015 begin
01016 leng:=Length(Value);
01017 if assigned(ZPlainPostgreSql8.PQescapeByteaConn) then begin
01018 encoded:=ZPlainPostgreSql8.PQescapeByteaConn(Handle,pansichar(value),leng,@len);
01019 end else begin
01020 encoded:=ZPlainPostgreSql8.PQescapeBytea(pansichar(value),leng,@len);
01021 end;
01022 setlength(result,len-1);
01023 StrCopy(pansichar(result),encoded);
01024 ZPlainPostgreSql8.PQFreemem(encoded);
01025 result:=''''+result+'''';
01026 end;
01027
01028 function TZPostgreSQL8PlainDriver.EndCopy( Handle: PZPostgreSQLConnect): Integer;
01029 begin
01030 Result := ZPlainPostgreSql8.PQendcopy(Handle);
01031 end;
01032
01033 function TZPostgreSQL8PlainDriver.ExecuteFunction(
01034 Handle: PZPostgreSQLConnect; fnid: Integer; result_buf,
01035 result_len: PInteger; result_is_int: Integer; args: PZPostgreSQLArgBlock;
01036 nargs: Integer): PZPostgreSQLResult;
01037 begin
01038 Result := ZPlainPostgreSql8.PQfn(Handle, fnid, result_buf,
01039 result_len, result_is_int, ZPlainPostgreSql8.PPQArgBlock(args), nargs);
01040 end;
01041
01042 function TZPostgreSQL8PlainDriver.ExecuteQuery(
01043 Handle: PZPostgreSQLConnect; Query: PChar): PZPostgreSQLResult;
01044 begin
01045 Result := ZPlainPostgreSql8.PQexec(Handle, Query);
01046 end;
01047
01048 function TZPostgreSQL8PlainDriver.ExportLargeObject(
01049 Handle: PZPostgreSQLConnect; ObjId: Oid; FileName: PChar): Integer;
01050 begin
01051 Result := ZPlainPostgreSql8.lo_export(Handle, ObjId, FileName);
01052 end;
01053
01054 procedure TZPostgreSQL8PlainDriver.Finish(Handle: PZPostgreSQLConnect);
01055 begin
01056 ZPlainPostgreSql8.PQfinish(Handle);
01057 end;
01058
01059 procedure TZPostgreSQL8PlainDriver.FreeNotify(Handle: PZPostgreSQLNotify);
01060 begin
01061 ZPlainPostgreSql8.PQfreeNotify(ZPlainPostgreSql8.PPGnotify(Handle));
01062 end;
01063
01064 function TZPostgreSQL8PlainDriver.GetBackendPID(
01065 Handle: PZPostgreSQLConnect): Integer;
01066 begin
01067 Result := ZPlainPostgreSql8.PQbackendPID(Handle);
01068 end;
01069
01070 function TZPostgreSQL8PlainDriver.GetBinaryTuples(
01071 Res: PZPostgreSQLResult): Integer;
01072 begin
01073 Result := ZPlainPostgreSql8.PQbinaryTuples(Res);
01074 end;
01075
01076 function TZPostgreSQL8PlainDriver.GetCommandStatus(
01077 Res: PZPostgreSQLResult): PChar;
01078 begin
01079 Result := ZPlainPostgreSql8.PQcmdStatus(Res);
01080 end;
01081
01082 function TZPostgreSQL8PlainDriver.GetCommandTuples(
01083 Res: PZPostgreSQLResult): PChar;
01084 begin
01085 Result := ZPlainPostgreSql8.PQcmdTuples(Res);
01086 end;
01087
01088 function TZPostgreSQL8PlainDriver.GetConnectDefaults:
01089 PZPostgreSQLConnectInfoOption;
01090 begin
01091 Result := PZPostgreSQLConnectInfoOption(ZPlainPostgreSql8.PQconndefaults);
01092 end;
01093
01094 function TZPostgreSQL8PlainDriver.GetDatabase(
01095 Handle: PZPostgreSQLConnect): PChar;
01096 begin
01097 Result := ZPlainPostgreSql8.PQdb(Handle);
01098 end;
01099
01100 function TZPostgreSQL8PlainDriver.GetErrorMessage(
01101 Handle: PZPostgreSQLConnect): PChar;
01102 begin
01103 Result := ZPlainPostgreSql8.PQerrorMessage(Handle);
01104 end;
01105
01106 function TZPostgreSQL8PlainDriver.GetFieldCount(
01107 Res: PZPostgreSQLResult): Integer;
01108 begin
01109 Result := ZPlainPostgreSql8.PQnfields(Res);
01110 end;
01111
01112 function TZPostgreSQL8PlainDriver.GetFieldMode(Res: PZPostgreSQLResult;
01113 FieldNum: Integer): Integer;
01114 begin
01115 Result := ZPlainPostgreSql8.PQfmod(Res, FieldNum);
01116 end;
01117
01118 function TZPostgreSQL8PlainDriver.GetFieldName(Res: PZPostgreSQLResult;
01119 FieldNum: Integer): PChar;
01120 begin
01121 Result := ZPlainPostgreSql8.PQfname(Res, FieldNum);
01122 end;
01123
01124 function TZPostgreSQL8PlainDriver.GetFieldNumber(
01125 Res: PZPostgreSQLResult; FieldName: PChar): Integer;
01126 begin
01127 Result := ZPlainPostgreSql8.PQfnumber(Res, FieldName);
01128 end;
01129
01130 function TZPostgreSQL8PlainDriver.GetFieldSize(Res: PZPostgreSQLResult;
01131 FieldNum: Integer): Integer;
01132 begin
01133 Result := ZPlainPostgreSql8.PQfsize(Res, FieldNum);
01134 end;
01135
01136 function TZPostgreSQL8PlainDriver.GetFieldType(Res: PZPostgreSQLResult;
01137 FieldNum: Integer): Oid;
01138 begin
01139 Result := ZPlainPostgreSql8.PQftype(Res, FieldNum);
01140 end;
01141
01142 function TZPostgreSQL8PlainDriver.GetHost(
01143 Handle: PZPostgreSQLConnect): PChar;
01144 begin
01145 Result := ZPlainPostgreSql8.PQhost(Handle);
01146 end;
01147
01148 function TZPostgreSQL8PlainDriver.GetIsNull(Res: PZPostgreSQLResult;
01149 TupNum, FieldNum: Integer): Integer;
01150 begin
01151 Result := ZPlainPostgreSql8.PQgetisnull(Res, TupNum, FieldNum);
01152 end;
01153
01154 function TZPostgreSQL8PlainDriver.GetLength(Res: PZPostgreSQLResult;
01155 TupNum, FieldNum: Integer): Integer;
01156 begin
01157 Result := ZPlainPostgreSql8.PQgetlength(Res, TupNum, FieldNum);
01158 end;
01159
01160 function TZPostgreSQL8PlainDriver.GetLine(Handle: PZPostgreSQLConnect;
01161 Buffer: PChar; Length: Integer): Integer;
01162 begin
01163 Result := ZPlainPostgreSql8.PQgetline(Handle, Buffer, Length);
01164 end;
01165
01166 function TZPostgreSQL8PlainDriver.GetLineAsync(
01167 Handle: PZPostgreSQLConnect; Buffer: PChar; Length: Integer): Integer;
01168 begin
01169 Result := ZPlainPostgreSql8.PQgetlineAsync(Handle, Buffer, Length);
01170 end;
01171
01172 function TZPostgreSQL8PlainDriver.GetOidStatus(
01173 Res: PZPostgreSQLResult): PChar;
01174 begin
01175 Result := ZPlainPostgreSql8.PQoidStatus(Res);
01176 end;
01177
01178 function TZPostgreSQL8PlainDriver.GetOidValue(
01179 Res: PZPostgreSQLResult): Oid;
01180 begin
01181 Result := ZPlainPostgreSql8.PQoidValue(Res);
01182 end;
01183
01184 function TZPostgreSQL8PlainDriver.GetOptions(
01185 Handle: PZPostgreSQLConnect): PChar;
01186 begin
01187 Result := ZPlainPostgreSql8.PQoptions(Handle);
01188 end;
01189
01190 function TZPostgreSQL8PlainDriver.GetPassword(
01191 Handle: PZPostgreSQLConnect): PChar;
01192 begin
01193 Result := ZPlainPostgreSql8.PQpass(Handle);
01194 end;
01195
01196 function TZPostgreSQL8PlainDriver.GetPort(
01197 Handle: PZPostgreSQLConnect): PChar;
01198 begin
01199 Result := ZPlainPostgreSql8.PQport(Handle);
01200 end;
01201
01202 function TZPostgreSQL8PlainDriver.GetResult(
01203 Handle: PZPostgreSQLConnect): PZPostgreSQLResult;
01204 begin
01205 Result := ZPlainPostgreSql8.PQgetResult(Handle);
01206 end;
01207
01208 function TZPostgreSQL8PlainDriver.GetResultErrorField(Res: PZPostgreSQLResult; FieldCode: TZPostgreSQLFieldCode): PChar;
01209 begin
01210 Result := ZPlainPostgreSql8.PQresultErrorField(Res,ord(FieldCode));
01211 end;
01212
01213 function TZPostgreSQL8PlainDriver.GetResultErrorMessage(Res: PZPostgreSQLResult): PChar;
01214 begin
01215 Result := ZPlainPostgreSql8.PQresultErrorMessage(Res);
01216 end;
01217
01218 function TZPostgreSQL8PlainDriver.GetResultStatus(
01219 Res: PZPostgreSQLResult): TZPostgreSQLExecStatusType;
01220 begin
01221 Result := TZPostgreSQLExecStatusType(ZPlainPostgreSql8.PQresultStatus(Res));
01222 end;
01223
01224 function TZPostgreSQL8PlainDriver.GetRowCount(
01225 Res: PZPostgreSQLResult): Integer;
01226 begin
01227 Result := ZPlainPostgreSql8.PQntuples(Res);
01228 end;
01229
01230 function TZPostgreSQL8PlainDriver.GetSocket(
01231 Handle: PZPostgreSQLConnect): Integer;
01232 begin
01233 Result := ZPlainPostgreSql8.PQsocket(Handle);
01234 end;
01235
01236 function TZPostgreSQL8PlainDriver.GetStatus(
01237 Handle: PZPostgreSQLConnect): TZPostgreSQLConnectStatusType;
01238 begin
01239 Result := TZPostgreSQLConnectStatusType(ZPlainPostgreSql8.PQstatus(Handle));
01240 end;
01241
01242 function TZPostgreSQL8PlainDriver.GetTTY(
01243 Handle: PZPostgreSQLConnect): PChar;
01244 begin
01245 Result := ZPlainPostgreSql8.PQtty(Handle);
01246 end;
01247
01248 function TZPostgreSQL8PlainDriver.GetUser(
01249 Handle: PZPostgreSQLConnect): PChar;
01250 begin
01251 Result := ZPlainPostgreSql8.PQuser(Handle);
01252 end;
01253
01254 function TZPostgreSQL8PlainDriver.GetValue(Res: PZPostgreSQLResult;
01255 TupNum, FieldNum: Integer): PChar;
01256 begin
01257 Result := ZPlainPostgreSql8.PQgetvalue(Res, TupNum, FieldNum);
01258 end;
01259
01260 function TZPostgreSQL8PlainDriver.ImportLargeObject(
01261 Handle: PZPostgreSQLConnect; FileName: PChar): Oid;
01262 begin
01263 Result := ZPlainPostgreSql8.lo_import(Handle, FileName);
01264 end;
01265
01266 function TZPostgreSQL8PlainDriver.IsBusy(
01267 Handle: PZPostgreSQLConnect): Integer;
01268 begin
01269 Result := ZPlainPostgreSql8.PQisBusy(Handle);
01270 end;
01271
01272 function TZPostgreSQL8PlainDriver.MakeEmptyResult(
01273 Handle: PZPostgreSQLConnect;
01274 Status: TZPostgreSQLExecStatusType): PZPostgreSQLResult;
01275 begin
01276 Result := ZPlainPostgreSql8.PQmakeEmptyPGresult(Handle,
01277 ZPlainPostgreSql8.ExecStatusType(Status));
01278 end;
01279
01280 function TZPostgreSQL8PlainDriver.Notifies(
01281 Handle: PZPostgreSQLConnect): PZPostgreSQLNotify;
01282 begin
01283 Result := PZPostgreSQLNotify(ZPlainPostgreSql8.PQnotifies(Handle));
01284 end;
01285
01286 function TZPostgreSQL8PlainDriver.OpenLargeObject(
01287 Handle: PZPostgreSQLConnect; ObjId: Oid; Mode: Integer): Integer;
01288 begin
01289 Result := ZPlainPostgreSql8.lo_open(Handle, ObjId, Mode);
01290 end;
01291
01292 function TZPostgreSQL8PlainDriver.PutBytes(Handle: PZPostgreSQLConnect;
01293 Buffer: PChar; Length: Integer): Integer;
01294 begin
01295 Result := ZPlainPostgreSql8.PQputnbytes(Handle, Buffer, Length);
01296 end;
01297
01298 function TZPostgreSQL8PlainDriver.PutLine(Handle: PZPostgreSQLConnect;
01299 Buffer: PChar): Integer;
01300 begin
01301 Result := ZPlainPostgreSql8.PQputline(Handle, Buffer);
01302 end;
01303
01304 function TZPostgreSQL8PlainDriver.ReadLargeObject(
01305 Handle: PZPostgreSQLConnect; Fd: Integer; Buffer: PChar;
01306 Length: Integer): Integer;
01307 begin
01308 Result := ZPlainPostgreSql8.lo_read(Handle, Fd, Buffer, Length);
01309 end;
01310
01311 function TZPostgreSQL8PlainDriver.RequestCancel(
01312 Handle: PZPostgreSQLConnect): Integer;
01313 begin
01314 Result := ZPlainPostgreSql8.PQrequestCancel(Handle);
01315 end;
01316
01317 procedure TZPostgreSQL8PlainDriver.Reset(Handle: PZPostgreSQLConnect);
01318 begin
01319 ZPlainPostgreSql8.PQreset(Handle);
01320 end;
01321
01322 function TZPostgreSQL8PlainDriver.SeekLargeObject(
01323 Handle: PZPostgreSQLConnect; Fd, Offset, Whence: Integer): Integer;
01324 begin
01325 Result := ZPlainPostgreSql8.lo_lseek(Handle, Fd, Offset, Whence);
01326 end;
01327
01328 function TZPostgreSQL8PlainDriver.SendQuery(Handle: PZPostgreSQLConnect;
01329 Query: PChar): Integer;
01330 begin
01331 Result := ZPlainPostgreSql8.PQsendQuery(Handle, Query);
01332 end;
01333
01334 function TZPostgreSQL8PlainDriver.SetDatabaseLogin(Host, Port, Options,
01335 TTY, Db, User, Passwd: PChar): PZPostgreSQLConnect;
01336 begin
01337 Result := ZPlainPostgreSql8.PQsetdbLogin(Host, Port, Options, TTY, Db,
01338 User, Passwd);
01339 end;
01340
01341 procedure TZPostgreSQL8PlainDriver.SetNoticeProcessor(
01342 Handle: PZPostgreSQLConnect; Proc: TZPostgreSQLNoticeProcessor;
01343 Arg: Pointer);
01344 begin
01345 ZPlainPostgreSql8.PQsetNoticeProcessor(Handle, Proc, Arg);
01346 end;
01347
01348 function TZPostgreSQL8PlainDriver.TellLargeObject(
01349 Handle: PZPostgreSQLConnect; Fd: Integer): Integer;
01350 begin
01351 Result := ZPlainPostgreSql8.lo_tell(Handle, Fd);
01352 end;
01353
01354 procedure TZPostgreSQL8PlainDriver.Trace(Handle: PZPostgreSQLConnect;
01355 DebugPort: Pointer);
01356 begin
01357 ZPlainPostgreSql8.PQtrace(Handle, DebugPort);
01358 end;
01359
01360 function TZPostgreSQL8PlainDriver.UnlinkLargeObject(
01361 Handle: PZPostgreSQLConnect; ObjId: Oid): Integer;
01362 begin
01363 Result := ZPlainPostgreSql8.lo_unlink(Handle, ObjId);
01364 end;
01365
01366 procedure TZPostgreSQL8PlainDriver.Untrace(Handle: PZPostgreSQLConnect);
01367 begin
01368 ZPlainPostgreSql8.PQuntrace(Handle);
01369 end;
01370
01371 function TZPostgreSQL8PlainDriver.WriteLargeObject(
01372 Handle: PZPostgreSQLConnect; Fd: Integer; Buffer: PChar;
01373 Length: Integer): Integer;
01374 begin
01375 Result := ZPlainPostgreSql8.lo_write(Handle, Fd, Buffer, Length);
01376 end;
01377
01378 end.