postgres3.pp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. { This unit contains the definitions for structures and externs for
  2. functions used by frontend postgres applications. It is based on
  3. Postgresql's libpq-fe.h.
  4. It is for postgreSQL version 7.4 and higher with support for the v3.0
  5. connection-protocol
  6. }
  7. unit postgres3;
  8. interface
  9. uses dllist;
  10. {$PACKRECORDS C}
  11. const
  12. External_library='pq';
  13. {$i postgres3types.inc}
  14. { ----------------
  15. * Exported functions of libpq
  16. * ----------------
  17. }
  18. { === in fe-connect.c === }
  19. { make a new client connection to the backend }
  20. { Asynchronous (non-blocking) }
  21. (* Const before type ignored *)
  22. function PQconnectStart(conninfo:Pchar):PPGconn;cdecl;external External_library name 'PQconnectStart';
  23. function PQconnectPoll(conn:PPGconn):PostgresPollingStatusType;cdecl;external External_library name 'PQconnectPoll';
  24. { Synchronous (blocking) }
  25. (* Const before type ignored *)
  26. function PQconnectdb(conninfo:Pchar):PPGconn;cdecl;external External_library name 'PQconnectdb';
  27. function PQsetdbLogin(pghost:Pchar; pgport:Pchar; pgoptions:Pchar; pgtty:Pchar; dbName:Pchar;
  28. login:Pchar; pwd:Pchar):PPGconn;cdecl;external External_library name 'PQsetdbLogin';
  29. { was #define dname(params) para_def_expr }
  30. { argument types are unknown }
  31. { return type might be wrong }
  32. function PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME : pchar) : ppgconn;
  33. { close the current connection and free the PGconn data structure }
  34. procedure PQfinish(conn:PPGconn);cdecl;external External_library name 'PQfinish';
  35. { get info about connection options known to PQconnectdb }
  36. function PQconndefaults:PPQconninfoOption;cdecl;external External_library name 'PQconndefaults';
  37. { free the data structure returned by PQconndefaults() }
  38. procedure PQconninfoFree(connOptions:PPQconninfoOption);cdecl;external External_library name 'PQconninfoFree';
  39. {
  40. * close the current connection and restablish a new one with the same
  41. * parameters
  42. }
  43. { Asynchronous (non-blocking) }
  44. function PQresetStart(conn:PPGconn):longint;cdecl;external External_library name 'PQresetStart';
  45. function PQresetPoll(conn:PPGconn):PostgresPollingStatusType;cdecl;external External_library name 'PQresetPoll';
  46. { Synchronous (blocking) }
  47. procedure PQreset(conn:PPGconn);cdecl;external External_library name 'PQreset';
  48. { issue a cancel request }
  49. function PQrequestCancel(conn:PPGconn):longint;cdecl;external External_library name 'PQrequestCancel';
  50. { Accessor functions for PGconn objects }
  51. function PQdb(conn:PPGconn):Pchar;cdecl;external External_library name 'PQdb';
  52. function PQuser(conn:PPGconn):Pchar;cdecl;external External_library name 'PQuser';
  53. function PQpass(conn:PPGconn):Pchar;cdecl;external External_library name 'PQpass';
  54. function PQhost(conn:PPGconn):Pchar;cdecl;external External_library name 'PQhost';
  55. function PQport(conn:PPGconn):Pchar;cdecl;external External_library name 'PQport';
  56. function PQtty(conn:PPGconn):Pchar;cdecl;external External_library name 'PQtty';
  57. function PQoptions(conn:PPGconn):Pchar;cdecl;external External_library name 'PQoptions';
  58. function PQstatus(conn:PPGconn):TConnStatusType;cdecl;external External_library name 'PQstatus';
  59. function PQtransactionStatus(conn:PPGconn):PGTransactionStatusType;cdecl;external External_library name 'PQtransactionStatus';
  60. function PQparameterStatus(conn:PPGconn; paramName:Pchar):Pchar;cdecl;external External_library name 'PQparameterStatus';
  61. function PQprotocolVersion(conn:PPGconn):longint;cdecl;external External_library name 'PQprotocolVersion';
  62. function PQerrorMessage(conn:PPGconn):Pchar;cdecl;external External_library name 'PQerrorMessage';
  63. function PQsocket(conn:PPGconn):longint;cdecl;external External_library name 'PQsocket';
  64. function PQbackendPID(conn:PPGconn):longint;cdecl;external External_library name 'PQbackendPID';
  65. function PQclientEncoding(conn:PPGconn):longint;cdecl;external External_library name 'PQclientEncoding';
  66. function PQsetClientEncoding(conn:PPGconn; encoding:Pchar):longint;cdecl;external External_library name 'PQsetClientEncoding';
  67. {$ifdef USE_SSL}
  68. { Get the SSL structure associated with a connection }
  69. function PQgetssl(conn:PPGconn):PSSL;cdecl;external External_library name 'PQgetssl';
  70. {$endif}
  71. { Set verbosity for PQerrorMessage and PQresultErrorMessage }
  72. function PQsetErrorVerbosity(conn:PPGconn; verbosity:PGVerbosity):PGVerbosity;cdecl;external External_library name 'PQsetErrorVerbosity';
  73. { Enable/disable tracing }
  74. procedure PQtrace(conn:PPGconn; debug_port:PFILE);cdecl;external External_library name 'PQtrace';
  75. procedure PQuntrace(conn:PPGconn);cdecl;external External_library name 'PQuntrace';
  76. { Override default notice handling routines }
  77. function PQsetNoticeReceiver(conn:PPGconn; proc:PQnoticeReceiver; arg:pointer):PQnoticeReceiver;cdecl;external External_library name 'PQsetNoticeReceiver';
  78. function PQsetNoticeProcessor(conn:PPGconn; proc:PQnoticeProcessor; arg:pointer):PQnoticeProcessor;cdecl;external External_library name 'PQsetNoticeProcessor';
  79. { === in fe-exec.c === }
  80. { Simple synchronous query }
  81. function PQexec(conn:PPGconn; query:Pchar):PPGresult;cdecl;external External_library name 'PQexec';
  82. function PQexecParams(conn:PPGconn; command:Pchar; nParams:longint; paramTypes:POid; paramValues:PPchar;
  83. paramLengths:Plongint; paramFormats:Plongint; resultFormat:longint):PPGresult;cdecl;external External_library name 'PQexecParams';
  84. function PQexecPrepared(conn:PPGconn; stmtName:Pchar; nParams:longint; paramValues:PPchar; paramLengths:Plongint;
  85. paramFormats:Plongint; resultFormat:longint):PPGresult;cdecl;external External_library name 'PQexecPrepared';
  86. { Interface for multiple-result or asynchronous queries }
  87. function PQsendQuery(conn:PPGconn; query:Pchar):longint;cdecl;external External_library name 'PQsendQuery';
  88. function PQsendQueryParams(conn:PPGconn; command:Pchar; nParams:longint; paramTypes:POid; paramValues:PPchar;
  89. paramLengths:Plongint; paramFormats:Plongint; resultFormat:longint):longint;cdecl;external External_library name 'PQsendQueryParams';
  90. function PQsendQueryPrepared(conn:PPGconn; stmtName:Pchar; nParams:longint; paramValues:PPchar; paramLengths:Plongint;
  91. paramFormats:Plongint; resultFormat:longint):longint;cdecl;external External_library name 'PQsendQueryPrepared';
  92. function PQgetResult(conn:PPGconn):PPGresult;cdecl;external External_library name 'PQgetResult';
  93. { Routines for managing an asynchronous query }
  94. function PQisBusy(conn:PPGconn):longint;cdecl;external External_library name 'PQisBusy';
  95. function PQconsumeInput(conn:PPGconn):longint;cdecl;external External_library name 'PQconsumeInput';
  96. { LISTEN/NOTIFY support }
  97. function PQnotifies(conn:PPGconn):PPGnotify;cdecl;external External_library name 'PQnotifies';
  98. { Routines for copy in/out }
  99. function PQputCopyData(conn:PPGconn; buffer:Pchar; nbytes:longint):longint;cdecl;external External_library name 'PQputCopyData';
  100. function PQputCopyEnd(conn:PPGconn; errormsg:Pchar):longint;cdecl;external External_library name 'PQputCopyEnd';
  101. function PQgetCopyData(conn:PPGconn; buffer:PPchar; async:longint):longint;cdecl;external External_library name 'PQgetCopyData';
  102. { Deprecated routines for copy in/out }
  103. function PQgetline(conn:PPGconn; _string:Pchar; length:longint):longint;cdecl;external External_library name 'PQgetline';
  104. function PQputline(conn:PPGconn; _string:Pchar):longint;cdecl;external External_library name 'PQputline';
  105. function PQgetlineAsync(conn:PPGconn; buffer:Pchar; bufsize:longint):longint;cdecl;external External_library name 'PQgetlineAsync';
  106. function PQputnbytes(conn:PPGconn; buffer:Pchar; nbytes:longint):longint;cdecl;external External_library name 'PQputnbytes';
  107. function PQendcopy(conn:PPGconn):longint;cdecl;external External_library name 'PQendcopy';
  108. { Set blocking/nonblocking connection to the backend }
  109. function PQsetnonblocking(conn:PPGconn; arg:longint):longint;cdecl;external External_library name 'PQsetnonblocking';
  110. function PQisnonblocking(conn:PPGconn):longint;cdecl;external External_library name 'PQisnonblocking';
  111. { Force the write buffer to be written (or at least try) }
  112. function PQflush(conn:PPGconn):longint;cdecl;external External_library name 'PQflush';
  113. {
  114. * "Fast path" interface --- not really recommended for application
  115. * use
  116. }
  117. function PQfn(conn:PPGconn; fnid:longint; result_buf:Plongint; result_len:Plongint; result_is_int:longint;
  118. args:PPQArgBlock; nargs:longint):PPGresult;cdecl;external External_library name 'PQfn';
  119. { Accessor functions for PGresult objects }
  120. function PQresultStatus(res:PPGresult):TExecStatusType;cdecl;external External_library name 'PQresultStatus';
  121. function PQresStatus(status:TExecStatusType):Pchar;cdecl;external External_library name 'PQresStatus';
  122. function PQresultErrorMessage(res:PPGresult):Pchar;cdecl;external External_library name 'PQresultErrorMessage';
  123. function PQresultErrorField(res:PPGresult; fieldcode:longint):Pchar;cdecl;external External_library name 'PQresultErrorField';
  124. function PQntuples(res:PPGresult):longint;cdecl;external External_library name 'PQntuples';
  125. function PQnfields(res:PPGresult):longint;cdecl;external External_library name 'PQnfields';
  126. function PQbinaryTuples(res:PPGresult):longint;cdecl;external External_library name 'PQbinaryTuples';
  127. function PQfname(res:PPGresult; field_num:longint):Pchar;cdecl;external External_library name 'PQfname';
  128. function PQfnumber(res:PPGresult; field_name:Pchar):longint;cdecl;external External_library name 'PQfnumber';
  129. function PQftable(res:PPGresult; field_num:longint):Oid;cdecl;external External_library name 'PQftable';
  130. function PQftablecol(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQftablecol';
  131. function PQfformat(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQfformat';
  132. function PQftype(res:PPGresult; field_num:longint):Oid;cdecl;external External_library name 'PQftype';
  133. function PQfsize(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQfsize';
  134. function PQfmod(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQfmod';
  135. function PQcmdStatus(res:PPGresult):Pchar;cdecl;external External_library name 'PQcmdStatus';
  136. function PQoidStatus(res:PPGresult):Pchar;cdecl;external External_library name 'PQoidStatus';
  137. { old and ugly }
  138. function PQoidValue(res:PPGresult):Oid;cdecl;external External_library name 'PQoidValue';
  139. { new and improved }
  140. function PQcmdTuples(res:PPGresult):Pchar;cdecl;external External_library name 'PQcmdTuples';
  141. function PQgetvalue(res:PPGresult; tup_num:longint; field_num:longint):Pchar;cdecl;external External_library name 'PQgetvalue';
  142. function PQgetlength(res:PPGresult; tup_num:longint; field_num:longint):longint;cdecl;external External_library name 'PQgetlength';
  143. function PQgetisnull(res:PPGresult; tup_num:longint; field_num:longint):longint;cdecl;external External_library name 'PQgetisnull';
  144. { Delete a PGresult }
  145. procedure PQclear(res:PPGresult);cdecl;external External_library name 'PQclear';
  146. { For freeing other alloc'd results, such as PGnotify structs }
  147. procedure PQfreemem(ptr:pointer);cdecl;external External_library name 'PQfreemem';
  148. { Exists for backward compatibility. bjm 2003-03-24 }
  149. { was #define dname(params) para_def_expr }
  150. { argument types are unknown }
  151. { return type might be wrong }
  152. // function PQfreeNotify(ptr : longint) : longint;
  153. {
  154. * Make an empty PGresult with given status (some apps find this
  155. * useful). If conn is not NULL and status indicates an error, the
  156. * conn's errorMessage is copied.
  157. }
  158. function PQmakeEmptyPGresult(conn:PPGconn; status:TExecStatusType):PPGresult;cdecl;external External_library name 'PQmakeEmptyPGresult';
  159. { Quoting strings before inclusion in queries. }
  160. function PQescapeString(till:Pchar; from:Pchar; length:size_t):size_t;cdecl;external External_library name 'PQescapeString';
  161. function PQescapeBytea(bintext:Pbyte; binlen:size_t; bytealen:Psize_t):Pbyte;cdecl;external External_library name 'PQescapeBytea';
  162. function PQunescapeBytea(strtext:Pbyte; retbuflen:Psize_t):Pbyte;cdecl;external External_library name 'PQunescapeBytea';
  163. { === in fe-print.c === }
  164. { output stream }
  165. procedure PQprint(fout:PFILE; res:PPGresult; ps:PPQprintOpt);cdecl;external External_library name 'PQprint';
  166. { option structure }
  167. {
  168. * really old printing routines
  169. }
  170. { where to send the output }
  171. { pad the fields with spaces }
  172. { field separator }
  173. { display headers? }
  174. procedure PQdisplayTuples(res:PPGresult; fp:PFILE; fillAlign:longint; fieldSep:Pchar; printHeader:longint;
  175. quiet:longint);cdecl;external External_library name 'PQdisplayTuples';
  176. (* Const before type ignored *)
  177. { output stream }
  178. { print attribute names }
  179. { delimiter bars }
  180. procedure PQprintTuples(res:PPGresult; fout:PFILE; printAttName:longint; terseOutput:longint; width:longint);cdecl;external External_library name 'PQprintTuples';
  181. { width of column, if 0, use variable
  182. * width }
  183. { === in fe-lobj.c === }
  184. { Large-object access routines }
  185. function lo_open(conn:PPGconn; lobjId:Oid; mode:longint):longint;cdecl;external External_library name 'lo_open';
  186. function lo_close(conn:PPGconn; fd:longint):longint;cdecl;external External_library name 'lo_close';
  187. function lo_read(conn:PPGconn; fd:longint; buf:Pchar; len:size_t):longint;cdecl;external External_library name 'lo_read';
  188. function lo_write(conn:PPGconn; fd:longint; buf:Pchar; len:size_t):longint;cdecl;external External_library name 'lo_write';
  189. function lo_lseek(conn:PPGconn; fd:longint; offset:longint; whence:longint):longint;cdecl;external External_library name 'lo_lseek';
  190. function lo_creat(conn:PPGconn; mode:longint):Oid;cdecl;external External_library name 'lo_creat';
  191. function lo_tell(conn:PPGconn; fd:longint):longint;cdecl;external External_library name 'lo_tell';
  192. function lo_unlink(conn:PPGconn; lobjId:Oid):longint;cdecl;external External_library name 'lo_unlink';
  193. function lo_import(conn:PPGconn; filename:Pchar):Oid;cdecl;external External_library name 'lo_import';
  194. function lo_export(conn:PPGconn; lobjId:Oid; filename:Pchar):longint;cdecl;external External_library name 'lo_export';
  195. { === in fe-misc.c === }
  196. { Determine length of multibyte encoded char at *s }
  197. function PQmblen(s:Pbyte; encoding:longint):longint;cdecl;external External_library name 'PQmblen';
  198. { Get encoding id from environment variable PGCLIENTENCODING }
  199. function PQenv2encoding:longint;cdecl;external External_library name 'PQenv2encoding';
  200. implementation
  201. { was #define dname(params) para_def_expr }
  202. { argument types are unknown }
  203. { return type might be wrong }
  204. // This function is also defined in postgres3dyn!
  205. function PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME : pchar) : ppgconn;
  206. begin
  207. PQsetdb:=PQsetdbLogin(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME,'','');
  208. end;
  209. { was #define dname(params) para_def_expr }
  210. { argument types are unknown }
  211. { return type might be wrong }
  212. { function PQfreeNotify(ptr : longint) : longint;
  213. begin
  214. PQfreeNotify:=PQfreemem(ptr);
  215. end;}
  216. end.