postgres3dyn.pp 20 KB

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