2
0

postgres3dyn.pp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. {
  2. Contains the Postgres protocol 3 functions calls
  3. Call InitialisePostgres3 before using any of the calls, and call ReleasePostgres3
  4. when finished.
  5. }
  6. unit postgres3dyn;
  7. {$mode objfpc}{$H+}
  8. interface
  9. uses
  10. dynlibs, SysUtils, dllistdyn, ctypes;
  11. {$IFDEF Unix}
  12. const
  13. {$ifdef darwin}
  14. pqlib = 'libpq.'+sharedsuffix; // No version number.
  15. {$else}
  16. pqlib5 = 'libpq.'+sharedsuffix+'.5'; // 8.2 and higher
  17. pqlib4 = 'libpq.'+sharedsuffix+'.4'; // 8.0, 8.1
  18. pqlib3 = 'libpq.'+sharedsuffix+'.3'; // 7.3, 7.4
  19. pqlib = pqlib5;
  20. {$endif}
  21. {$ENDIF}
  22. {$IFDEF Windows}
  23. const
  24. pqlib = 'libpq.dll'; // Not sure if it has a version number ?
  25. {$ENDIF}
  26. {$PACKRECORDS C}
  27. {$i postgres3types.inc}
  28. var
  29. { ----------------
  30. * Exported functions of libpq
  31. * ----------------
  32. }
  33. { === in fe-connect.c === }
  34. { make a new client connection to the backend }
  35. { Asynchronous (non-blocking) }
  36. (* Const before type ignored *)
  37. PQconnectStart : function (conninfo:Pchar):PPGconn;cdecl;
  38. PQconnectPoll : function (conn:PPGconn):PostgresPollingStatusType;cdecl;
  39. { Synchronous (blocking) }
  40. (* Const before type ignored *)
  41. PQconnectdb : function (conninfo:Pchar):PPGconn;cdecl;
  42. PQsetdbLogin : function (pghost:Pchar; pgport:Pchar; pgoptions:Pchar; pgtty:Pchar; dbName:Pchar;login:Pchar; pwd:Pchar):PPGconn;cdecl;
  43. { was #define dname(params) para_def_expr }
  44. { argument types are unknown }
  45. { return type might be wrong }
  46. { close the current connection and free the PGconn data structure }
  47. PQfinish : procedure (conn:PPGconn);cdecl;
  48. { get info about connection options known to PQconnectdb }
  49. PQconndefaults : function : PPQconninfoOption;cdecl;
  50. { free the data structure returned by PQconndefaults() }
  51. PQconninfoFree : procedure (connOptions:PPQconninfoOption);cdecl;
  52. {
  53. * close the current connection and restablish a new one with the same
  54. * parameters
  55. }
  56. { Asynchronous (non-blocking) }
  57. PQresetStart : function (conn:PPGconn):longint;cdecl;
  58. PQresetPoll : function (conn:PPGconn):PostgresPollingStatusType;cdecl;
  59. { Synchronous (blocking) }
  60. PQreset : procedure (conn:PPGconn);cdecl;
  61. { issue a cancel request }
  62. PQrequestCancel : function (conn:PPGconn):longint;cdecl;
  63. { Accessor functions for PGconn objects }
  64. PQdb : function (conn:PPGconn):Pchar;cdecl;
  65. PQuser : function (conn:PPGconn):Pchar;cdecl;
  66. PQpass : function (conn:PPGconn):Pchar;cdecl;
  67. PQhost : function (conn:PPGconn):Pchar;cdecl;
  68. PQport : function (conn:PPGconn):Pchar;cdecl;
  69. PQtty : function (conn:PPGconn):Pchar;cdecl;
  70. PQoptions : function (conn:PPGconn):Pchar;cdecl;
  71. PQstatus : function (conn:PPGconn):TConnStatusType;cdecl;
  72. PQtransactionStatus : function (conn:PPGconn):PGTransactionStatusType;cdecl;
  73. PQparameterStatus : function (conn:PPGconn; paramName:Pchar):Pchar;cdecl;
  74. PQprotocolVersion : function (conn:PPGconn):longint;cdecl;
  75. PQserverVersion : function (conn:PPGconn):longint;cdecl;
  76. PQerrorMessage : function (conn:PPGconn):Pchar;cdecl;
  77. PQsocket : function (conn:PPGconn):longint;cdecl;
  78. PQbackendPID : function (conn:PPGconn):longint;cdecl;
  79. PQclientEncoding : function (conn:PPGconn):longint;cdecl;
  80. PQsetClientEncoding : function (conn:PPGconn; encoding:Pchar):longint;cdecl;
  81. {$ifdef USE_SSL}
  82. { Get the SSL structure associated with a connection }
  83. PQgetssl : function (conn:PPGconn):PSSL;cdecl;
  84. {$endif}
  85. { Set verbosity for PQerrorMessage and PQresultErrorMessage }
  86. PQsetErrorVerbosity : function (conn:PPGconn; verbosity:PGVerbosity):PGVerbosity;cdecl;
  87. { Enable/disable tracing }
  88. PQtrace : procedure (conn:PPGconn; debug_port:PFILE);cdecl;
  89. PQuntrace : procedure (conn:PPGconn);cdecl;
  90. { Override default notice handling routines }
  91. PQsetNoticeReceiver : function (conn:PPGconn; proc:PQnoticeReceiver; arg:pointer):PQnoticeReceiver;cdecl;
  92. PQsetNoticeProcessor : function (conn:PPGconn; proc:PQnoticeProcessor; arg:pointer):PQnoticeProcessor;cdecl;
  93. { === in fe-exec.c === }
  94. { Simple synchronous query }
  95. PQexec : function (conn:PPGconn; query:Pchar):PPGresult;cdecl;
  96. PQexecParams : function (conn:PPGconn; command:Pchar; nParams:longint; paramTypes:POid; paramValues:PPchar;paramLengths:Plongint; paramFormats:Plongint; resultFormat:longint):PPGresult;cdecl;
  97. PQexecPrepared : function (conn:PPGconn; stmtName:Pchar; nParams:longint; paramValues:PPchar; paramLengths:Plongint;paramFormats:Plongint; resultFormat:longint):PPGresult;cdecl;
  98. PQPrepare : function (conn:PPGconn; stmtName:Pchar; query:Pchar; nParams:longint; paramTypes:POid):PPGresult;cdecl;
  99. PQdescribePrepared : function (conn:PPGconn; stmtName:Pchar):PPGresult;cdecl;
  100. { Interface for multiple-result or asynchronous queries }
  101. PQsendQuery : function (conn:PPGconn; query:Pchar):longint;cdecl;
  102. PQsendQueryParams : function (conn:PPGconn; command:Pchar; nParams:longint; paramTypes:POid; paramValues:PPchar;paramLengths:Plongint; paramFormats:Plongint; resultFormat:longint):longint;cdecl;
  103. PQsendQueryPrepared : function (conn:PPGconn; stmtName:Pchar; nParams:longint; paramValues:PPchar; paramLengths:Plongint;paramFormats:Plongint; resultFormat:longint):longint;cdecl;
  104. PQgetResult : function (conn:PPGconn):PPGresult;cdecl;
  105. { Routines for managing an asynchronous query }
  106. PQisBusy : function (conn:PPGconn):longint;cdecl;
  107. PQconsumeInput : function (conn:PPGconn):longint;cdecl;
  108. { LISTEN/NOTIFY support }
  109. PQnotifies : function (conn:PPGconn):PPGnotify;cdecl;
  110. { Routines for copy in/out }
  111. PQputCopyData : function (conn:PPGconn; buffer:Pchar; nbytes:longint):longint;cdecl;
  112. PQputCopyEnd : function (conn:PPGconn; errormsg:Pchar):longint;cdecl;
  113. PQgetCopyData : function (conn:PPGconn; buffer:PPchar; async:longint):longint;cdecl;
  114. { Deprecated routines for copy in/out }
  115. PQgetline : function (conn:PPGconn; _string:Pchar; length:longint):longint;cdecl;
  116. PQputline : function (conn:PPGconn; _string:Pchar):longint;cdecl;
  117. PQgetlineAsync : function (conn:PPGconn; buffer:Pchar; bufsize:longint):longint;cdecl;
  118. PQputnbytes : function (conn:PPGconn; buffer:Pchar; nbytes:longint):longint;cdecl;
  119. PQendcopy : function (conn:PPGconn):longint;cdecl;
  120. { Set blocking/nonblocking connection to the backend }
  121. PQsetnonblocking : function (conn:PPGconn; arg:longint):longint;cdecl;
  122. PQisnonblocking : function (conn:PPGconn):longint;cdecl;
  123. PQisthreadsafe : function ():longint;cdecl;
  124. { Force the write buffer to be written (or at least try) }
  125. PQflush : function (conn:PPGconn):longint;cdecl;
  126. {
  127. * "Fast path" interface --- not really recommended for application
  128. * use
  129. }
  130. PQfn : function (conn:PPGconn; fnid:longint; result_buf:Plongint; result_len:Plongint; result_is_int:longint;args:PPQArgBlock; nargs:longint):PPGresult;cdecl;
  131. { Accessor functions for PGresult objects }
  132. PQresultStatus : function (res:PPGresult):TExecStatusType;cdecl;
  133. PQresStatus : function (status:TExecStatusType):Pchar;cdecl;
  134. PQresultErrorMessage : function (res:PPGresult):Pchar;cdecl;
  135. PQresultErrorField : function (res:PPGresult; fieldcode:longint):Pchar;cdecl;
  136. PQntuples : function (res:PPGresult):longint;cdecl;
  137. PQnfields : function (res:PPGresult):longint;cdecl;
  138. PQbinaryTuples : function (res:PPGresult):longint;cdecl;
  139. PQfname : function (res:PPGresult; field_num:longint):Pchar;cdecl;
  140. PQfnumber : function (res:PPGresult; field_name:Pchar):longint;cdecl;
  141. PQftable : function (res:PPGresult; field_num:longint):Oid;cdecl;
  142. PQftablecol : function (res:PPGresult; field_num:longint):longint;cdecl;
  143. PQfformat : function (res:PPGresult; field_num:longint):longint;cdecl;
  144. PQftype : function (res:PPGresult; field_num:longint):Oid;cdecl;
  145. PQfsize : function (res:PPGresult; field_num:longint):longint;cdecl;
  146. PQfmod : function (res:PPGresult; field_num:longint):longint;cdecl;
  147. PQcmdStatus : function (res:PPGresult):Pchar;cdecl;
  148. PQoidStatus : function (res:PPGresult):Pchar;cdecl;
  149. { old and ugly }
  150. PQoidValue : function (res:PPGresult):Oid;cdecl;
  151. { new and improved }
  152. PQcmdTuples : function (res:PPGresult):Pchar;cdecl;
  153. PQgetvalue : function (res:PPGresult; tup_num:longint; field_num:longint):Pchar;cdecl;
  154. PQgetlength : function (res:PPGresult; tup_num:longint; field_num:longint):longint;cdecl;
  155. PQgetisnull : function (res:PPGresult; tup_num:longint; field_num:longint):longint;cdecl;
  156. PQnparams : function (res:PPGresult):longint;cdecl;
  157. PQparamtype : function (res:PPGresult; param_num:longint):Oid;cdecl;
  158. { Delete a PGresult }
  159. PQclear : procedure (res:PPGresult);cdecl;
  160. { For freeing other alloc'd results, such as PGnotify structs }
  161. PQfreemem : procedure (ptr:pointer);cdecl;
  162. { Exists for backward compatibility. bjm 2003-03-24 }
  163. { was #define dname(params) para_def_expr }
  164. { argument types are unknown }
  165. { return type might be wrong }
  166. // function PQfreeNotify(ptr : longint) : longint;
  167. {
  168. * Make an empty PGresult with given status (some apps find this
  169. * useful). If conn is not NULL and status indicates an error, the
  170. * conn's errorMessage is copied.
  171. }
  172. PQmakeEmptyPGresult : function (conn:PPGconn; status:TExecStatusType):PPGresult;cdecl;
  173. { Quoting strings before inclusion in queries. }
  174. PQescapeStringConn : function (conn:PPGconn; str:Pcchar; from:Pcchar; length:size_t; error:Pcint):size_t;cdecl;
  175. PQescapeLiteral : function (conn:PPGconn; str:Pcchar; len:size_t):Pcchar;cdecl;
  176. PQescapeIdentifier : function (conn:PPGconn; str:Pcchar; len:size_t):Pcchar;cdecl;
  177. PQescapeByteaConn : function (conn:PPGconn; from:Pbyte; from_length:size_t; to_length:Psize_t):Pbyte;cdecl;
  178. PQunescapeBytea : function (strtext:Pbyte; retbuflen:Psize_t):Pbyte;cdecl;
  179. { These forms are deprecated! }
  180. PQescapeString : function (till:Pchar; from:Pchar; length:size_t):size_t;cdecl;
  181. PQescapeBytea : function (bintext:Pbyte; binlen:size_t; bytealen:Psize_t):Pbyte;cdecl;
  182. { === in fe-print.c === }
  183. { output stream }
  184. PQprint : procedure (fout:PFILE; res:PPGresult; ps:PPQprintOpt);cdecl;
  185. { option structure }
  186. {
  187. * really old printing routines
  188. }
  189. { where to send the output }
  190. { pad the fields with spaces }
  191. { field separator }
  192. { display headers? }
  193. PQdisplayTuples : procedure (res:PPGresult; fp:PFILE; fillAlign:longint; fieldSep:Pchar; printHeader:longint;quiet:longint);cdecl;
  194. (* Const before type ignored *)
  195. { output stream }
  196. { print attribute names }
  197. { delimiter bars }
  198. PQprintTuples : procedure (res:PPGresult; fout:PFILE; printAttName:longint; terseOutput:longint; width:longint);cdecl;
  199. { width of column, if 0, use variable
  200. * width }
  201. { === in fe-lobj.c === }
  202. { Large-object access routines }
  203. lo_open : function (conn:PPGconn; lobjId:Oid; mode:longint):longint;cdecl;
  204. lo_close : function (conn:PPGconn; fd:longint):longint;cdecl;
  205. lo_read : function (conn:PPGconn; fd:longint; buf:Pchar; len:size_t):longint;cdecl;
  206. lo_write : function (conn:PPGconn; fd:longint; buf:Pchar; len:size_t):longint;cdecl;
  207. lo_lseek : function (conn:PPGconn; fd:longint; offset:longint; whence:longint):longint;cdecl;
  208. lo_creat : function (conn:PPGconn; mode:longint):Oid;cdecl;
  209. lo_tell : function (conn:PPGconn; fd:longint):longint;cdecl;
  210. lo_truncate : function (conn:PPGconn; fd:longint; len:size_t):longint;cdecl;
  211. lo_unlink : function (conn:PPGconn; lobjId:Oid):longint;cdecl;
  212. lo_import : function (conn:PPGconn; filename:Pchar):Oid;cdecl;
  213. lo_import_with_oid : function (conn:PPGconn; filename:Pcchar; lobjId:Oid):Oid;cdecl;
  214. lo_export : function (conn:PPGconn; lobjId:Oid; filename:Pchar):longint;cdecl;
  215. { === in fe-misc.c === }
  216. { Determine length of multibyte encoded char at *s }
  217. PQmblen : function (s:Pbyte; encoding:longint):longint;cdecl;
  218. { Get encoding id from environment variable PGCLIENTENCODING }
  219. PQenv2encoding: function :longint;cdecl;
  220. { === in fe-auth.c === }
  221. PQencryptPassword : function (passwd:Pcchar; user:Pcchar):Pcchar;cdecl;
  222. Function InitialisePostgres3(Const libpath : ansistring) : integer;
  223. Procedure InitialisePostgres3;
  224. Procedure ReleasePostgres3;
  225. function PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME : pchar) : ppgconn;
  226. var Postgres3LibraryHandle : TLibHandle;
  227. Postgres3LoadedLibrary : String;
  228. implementation
  229. resourcestring
  230. SErrLoadFailed = 'Can not load PostgreSQL client library "%s". Check your installation.';
  231. SErrAlreadyLoaded = 'PostgreSQL interface already initialized from library %s.';
  232. var
  233. RefCount : integer;
  234. procedure InitialisePostgres3;
  235. begin
  236. EnterCriticalsection(libpgCriticalSection);
  237. try
  238. if (RefCount<>0) then
  239. // pretend to load whatever is already loaded, so we do not get a library name conflict.
  240. inc(Refcount)
  241. else
  242. InitialisePostgres3(pqlib)
  243. finally
  244. LeaveCriticalsection(libpgCriticalSection);
  245. end;
  246. end;
  247. function InitialisePostgres3(Const libpath : ansistring) : Integer;
  248. begin
  249. EnterCriticalsection(libpgCriticalSection);
  250. try
  251. inc(RefCount);
  252. Result:=Refcount;
  253. if RefCount = 1 then
  254. begin
  255. Postgres3LibraryHandle := loadlibrary(libpath);
  256. if Postgres3LibraryHandle = nilhandle then
  257. begin
  258. RefCount := 0;
  259. Raise EInOutError.CreateFmt(SErrLoadFailed,[libpath]);
  260. end;
  261. Postgres3LoadedLibrary:=libpath;
  262. pointer(PQconnectStart) := GetProcedureAddress(Postgres3LibraryHandle,'PQconnectStart');
  263. pointer(PQconnectPoll) := GetProcedureAddress(Postgres3LibraryHandle,'PQconnectPoll');
  264. pointer(PQconnectdb) := GetProcedureAddress(Postgres3LibraryHandle,'PQconnectdb');
  265. pointer(PQsetdbLogin) := GetProcedureAddress(Postgres3LibraryHandle,'PQsetdbLogin');
  266. pointer(PQfinish) := GetProcedureAddress(Postgres3LibraryHandle,'PQfinish');
  267. pointer(PQconndefaults) := GetProcedureAddress(Postgres3LibraryHandle,'PQconndefaults');
  268. pointer(PQconninfoFree) := GetProcedureAddress(Postgres3LibraryHandle,'PQconninfoFree');
  269. pointer(PQresetStart) := GetProcedureAddress(Postgres3LibraryHandle,'PQresetStart');
  270. pointer(PQresetPoll) := GetProcedureAddress(Postgres3LibraryHandle,'PQresetPoll');
  271. pointer(PQreset) := GetProcedureAddress(Postgres3LibraryHandle,'PQreset');
  272. pointer(PQrequestCancel) := GetProcedureAddress(Postgres3LibraryHandle,'PQrequestCancel');
  273. pointer(PQdb) := GetProcedureAddress(Postgres3LibraryHandle,'PQdb');
  274. pointer(PQuser) := GetProcedureAddress(Postgres3LibraryHandle,'PQuser');
  275. pointer(PQpass) := GetProcedureAddress(Postgres3LibraryHandle,'PQpass');
  276. pointer(PQhost) := GetProcedureAddress(Postgres3LibraryHandle,'PQhost');
  277. pointer(PQport) := GetProcedureAddress(Postgres3LibraryHandle,'PQport');
  278. pointer(PQtty) := GetProcedureAddress(Postgres3LibraryHandle,'PQtty');
  279. pointer(PQoptions) := GetProcedureAddress(Postgres3LibraryHandle,'PQoptions');
  280. pointer(PQstatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQstatus');
  281. pointer(PQtransactionStatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQtransactionStatus');
  282. pointer(PQparameterStatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQparameterStatus');
  283. pointer(PQprotocolVersion) := GetProcedureAddress(Postgres3LibraryHandle,'PQprotocolVersion');
  284. pointer(PQserverVersion) := GetProcedureAddress(Postgres3LibraryHandle,'PQserverVersion');
  285. pointer(PQerrorMessage) := GetProcedureAddress(Postgres3LibraryHandle,'PQerrorMessage');
  286. pointer(PQsocket) := GetProcedureAddress(Postgres3LibraryHandle,'PQsocket');
  287. pointer(PQbackendPID) := GetProcedureAddress(Postgres3LibraryHandle,'PQbackendPID');
  288. pointer(PQclientEncoding) := GetProcedureAddress(Postgres3LibraryHandle,'PQclientEncoding');
  289. pointer(PQsetClientEncoding) := GetProcedureAddress(Postgres3LibraryHandle,'PQsetClientEncoding');
  290. {$ifdef USE_SSL}
  291. pointer(PQgetssl) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetssl');
  292. {$endif}
  293. pointer(PQsetErrorVerbosity) := GetProcedureAddress(Postgres3LibraryHandle,'PQsetErrorVerbosity');
  294. pointer(PQtrace) := GetProcedureAddress(Postgres3LibraryHandle,'PQtrace');
  295. pointer(PQuntrace) := GetProcedureAddress(Postgres3LibraryHandle,'PQuntrace');
  296. pointer(PQsetNoticeReceiver) := GetProcedureAddress(Postgres3LibraryHandle,'PQsetNoticeReceiver');
  297. pointer(PQsetNoticeProcessor) := GetProcedureAddress(Postgres3LibraryHandle,'PQsetNoticeProcessor');
  298. pointer(PQexec) := GetProcedureAddress(Postgres3LibraryHandle,'PQexec');
  299. pointer(PQexecParams) := GetProcedureAddress(Postgres3LibraryHandle,'PQexecParams');
  300. pointer(PQexecPrepared) := GetProcedureAddress(Postgres3LibraryHandle,'PQexecPrepared');
  301. pointer(PQPrepare) := GetProcedureAddress(Postgres3LibraryHandle,'PQprepare');
  302. pointer(PQdescribePrepared) := GetProcedureAddress(Postgres3LibraryHandle,'PQdescribePrepared');
  303. pointer(PQsendQuery) := GetProcedureAddress(Postgres3LibraryHandle,'PQsendQuery');
  304. pointer(PQsendQueryParams) := GetProcedureAddress(Postgres3LibraryHandle,'PQsendQueryParams');
  305. pointer(PQsendQueryPrepared) := GetProcedureAddress(Postgres3LibraryHandle,'PQsendQueryPrepared');
  306. pointer(PQgetResult) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetResult');
  307. pointer(PQisBusy) := GetProcedureAddress(Postgres3LibraryHandle,'PQisBusy');
  308. pointer(PQconsumeInput) := GetProcedureAddress(Postgres3LibraryHandle,'PQconsumeInput');
  309. pointer(PQnotifies) := GetProcedureAddress(Postgres3LibraryHandle,'PQnotifies');
  310. pointer(PQputCopyData) := GetProcedureAddress(Postgres3LibraryHandle,'PQputCopyData');
  311. pointer(PQputCopyEnd) := GetProcedureAddress(Postgres3LibraryHandle,'PQputCopyEnd');
  312. pointer(PQgetCopyData) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetCopyData');
  313. pointer(PQgetline) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetline');
  314. pointer(PQputline) := GetProcedureAddress(Postgres3LibraryHandle,'PQputline');
  315. pointer(PQgetlineAsync) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetlineAsync');
  316. pointer(PQputnbytes) := GetProcedureAddress(Postgres3LibraryHandle,'PQputnbytes');
  317. pointer(PQendcopy) := GetProcedureAddress(Postgres3LibraryHandle,'PQendcopy');
  318. pointer(PQsetnonblocking) := GetProcedureAddress(Postgres3LibraryHandle,'PQsetnonblocking');
  319. pointer(PQisnonblocking) := GetProcedureAddress(Postgres3LibraryHandle,'PQisnonblocking');
  320. pointer(PQisthreadsafe) := GetProcedureAddress(Postgres3LibraryHandle,'PQisthreadsafe');
  321. pointer(PQflush) := GetProcedureAddress(Postgres3LibraryHandle,'PQflush');
  322. pointer(PQfn) := GetProcedureAddress(Postgres3LibraryHandle,'PQfn');
  323. pointer(PQresultStatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQresultStatus');
  324. pointer(PQresStatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQresStatus');
  325. pointer(PQresultErrorMessage) := GetProcedureAddress(Postgres3LibraryHandle,'PQresultErrorMessage');
  326. pointer(PQresultErrorField) := GetProcedureAddress(Postgres3LibraryHandle,'PQresultErrorField');
  327. pointer(PQntuples) := GetProcedureAddress(Postgres3LibraryHandle,'PQntuples');
  328. pointer(PQnfields) := GetProcedureAddress(Postgres3LibraryHandle,'PQnfields');
  329. pointer(PQbinaryTuples) := GetProcedureAddress(Postgres3LibraryHandle,'PQbinaryTuples');
  330. pointer(PQfname) := GetProcedureAddress(Postgres3LibraryHandle,'PQfname');
  331. pointer(PQfnumber) := GetProcedureAddress(Postgres3LibraryHandle,'PQfnumber');
  332. pointer(PQftable) := GetProcedureAddress(Postgres3LibraryHandle,'PQftable');
  333. pointer(PQftablecol) := GetProcedureAddress(Postgres3LibraryHandle,'PQftablecol');
  334. pointer(PQfformat) := GetProcedureAddress(Postgres3LibraryHandle,'PQfformat');
  335. pointer(PQftype) := GetProcedureAddress(Postgres3LibraryHandle,'PQftype');
  336. pointer(PQfsize) := GetProcedureAddress(Postgres3LibraryHandle,'PQfsize');
  337. pointer(PQfmod) := GetProcedureAddress(Postgres3LibraryHandle,'PQfmod');
  338. pointer(PQcmdStatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQcmdStatus');
  339. pointer(PQoidStatus) := GetProcedureAddress(Postgres3LibraryHandle,'PQoidStatus');
  340. pointer(PQoidValue) := GetProcedureAddress(Postgres3LibraryHandle,'PQoidValue');
  341. pointer(PQcmdTuples) := GetProcedureAddress(Postgres3LibraryHandle,'PQcmdTuples');
  342. pointer(PQgetvalue) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetvalue');
  343. pointer(PQgetlength) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetlength');
  344. pointer(PQgetisnull) := GetProcedureAddress(Postgres3LibraryHandle,'PQgetisnull');
  345. pointer(PQnparams) := GetProcedureAddress(Postgres3LibraryHandle,'PQnparams');
  346. pointer(PQparamtype) := GetProcedureAddress(Postgres3LibraryHandle,'PQparamtype');
  347. pointer(PQclear) := GetProcedureAddress(Postgres3LibraryHandle,'PQclear');
  348. pointer(PQfreemem) := GetProcedureAddress(Postgres3LibraryHandle,'PQfreemem');
  349. pointer(PQmakeEmptyPGresult) := GetProcedureAddress(Postgres3LibraryHandle,'PQmakeEmptyPGresult');
  350. pointer(PQescapeStringConn) := GetProcedureAddress(Postgres3LibraryHandle,'PQescapeStringConn');
  351. pointer(PQescapeLiteral) := GetProcedureAddress(Postgres3LibraryHandle,'PQescapeLiteral');
  352. pointer(PQescapeIdentifier) := GetProcedureAddress(Postgres3LibraryHandle,'PQescapeIdentifier');
  353. pointer(PQescapeByteaConn) := GetProcedureAddress(Postgres3LibraryHandle,'PQescapeByteaConn');
  354. pointer(PQunescapeBytea) := GetProcedureAddress(Postgres3LibraryHandle,'PQunescapeBytea');
  355. pointer(PQescapeString) := GetProcedureAddress(Postgres3LibraryHandle,'PQescapeString');
  356. pointer(PQescapeBytea) := GetProcedureAddress(Postgres3LibraryHandle,'PQescapeBytea');
  357. pointer(PQprint) := GetProcedureAddress(Postgres3LibraryHandle,'PQprint');
  358. pointer(PQdisplayTuples) := GetProcedureAddress(Postgres3LibraryHandle,'PQdisplayTuples');
  359. pointer(PQprintTuples) := GetProcedureAddress(Postgres3LibraryHandle,'PQprintTuples');
  360. pointer(lo_open) := GetProcedureAddress(Postgres3LibraryHandle,'lo_open');
  361. pointer(lo_close) := GetProcedureAddress(Postgres3LibraryHandle,'lo_close');
  362. pointer(lo_read) := GetProcedureAddress(Postgres3LibraryHandle,'lo_read');
  363. pointer(lo_write) := GetProcedureAddress(Postgres3LibraryHandle,'lo_write');
  364. pointer(lo_lseek) := GetProcedureAddress(Postgres3LibraryHandle,'lo_lseek');
  365. pointer(lo_creat) := GetProcedureAddress(Postgres3LibraryHandle,'lo_creat');
  366. pointer(lo_tell) := GetProcedureAddress(Postgres3LibraryHandle,'lo_tell');
  367. pointer(lo_truncate) := GetProcedureAddress(Postgres3LibraryHandle,'lo_truncate');
  368. pointer(lo_unlink) := GetProcedureAddress(Postgres3LibraryHandle,'lo_unlink');
  369. pointer(lo_import) := GetProcedureAddress(Postgres3LibraryHandle,'lo_import');
  370. pointer(lo_import_with_oid) := GetProcedureAddress(Postgres3LibraryHandle,'lo_import_with_oid');
  371. pointer(lo_export) := GetProcedureAddress(Postgres3LibraryHandle,'lo_export');
  372. pointer(PQmblen) := GetProcedureAddress(Postgres3LibraryHandle,'PQmblen');
  373. pointer(PQenv2encoding) := GetProcedureAddress(Postgres3LibraryHandle,'PQenv2encoding');
  374. pointer(PQencryptPassword) := GetProcedureAddress(Postgres3LibraryHandle,'PQencryptPassword');
  375. InitialiseDllist(libpath);
  376. end
  377. else
  378. if (libpath<>pqlib) and (Postgres3LoadedLibrary<>libpath) then
  379. begin
  380. Dec(RefCount);
  381. Raise EInOUtError.CreateFmt(SErrAlreadyLoaded,[Postgres3LoadedLibrary]);
  382. end;
  383. finally
  384. LeaveCriticalsection(libpgCriticalSection);
  385. end;
  386. end;
  387. Procedure ReleasePostgres3;
  388. begin
  389. EnterCriticalsection(libpgCriticalSection);
  390. try
  391. if RefCount > 0 then dec(RefCount);
  392. if RefCount = 0 then
  393. begin
  394. if not UnloadLibrary(Postgres3LibraryHandle) then inc(RefCount);
  395. ReleaseDllist;
  396. end;
  397. finally
  398. LeaveCriticalsection(libpgCriticalSection);
  399. end;
  400. end;
  401. // This function is also defined in postgres3!
  402. function PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME : pchar) : ppgconn;
  403. begin
  404. PQsetdb:=PQsetdbLogin(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME,'','');
  405. end;
  406. end.