postgres3.pp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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:PAnsiChar):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:PAnsiChar):PPGconn;cdecl;external External_library name 'PQconnectdb';
  27. function PQsetdbLogin(pghost:PAnsiChar; pgport:PAnsiChar; pgoptions:PAnsiChar; pgtty:PAnsiChar; dbName:PAnsiChar;
  28. login:PAnsiChar; pwd:PAnsiChar):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 : PAnsiChar) : 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):PAnsiChar;cdecl;external External_library name 'PQdb';
  52. function PQuser(conn:PPGconn):PAnsiChar;cdecl;external External_library name 'PQuser';
  53. function PQpass(conn:PPGconn):PAnsiChar;cdecl;external External_library name 'PQpass';
  54. function PQhost(conn:PPGconn):PAnsiChar;cdecl;external External_library name 'PQhost';
  55. function PQport(conn:PPGconn):PAnsiChar;cdecl;external External_library name 'PQport';
  56. function PQtty(conn:PPGconn):PAnsiChar;cdecl;external External_library name 'PQtty';
  57. function PQoptions(conn:PPGconn):PAnsiChar;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:PAnsiChar):PAnsiChar;cdecl;external External_library name 'PQparameterStatus';
  61. function PQprotocolVersion(conn:PPGconn):longint;cdecl;external External_library name 'PQprotocolVersion';
  62. function PQserverVersion(conn:PPGconn):longint;cdecl;external External_library name 'PQserverVersion';
  63. function PQerrorMessage(conn:PPGconn):PAnsiChar;cdecl;external External_library name 'PQerrorMessage';
  64. function PQsocket(conn:PPGconn):longint;cdecl;external External_library name 'PQsocket';
  65. function PQbackendPID(conn:PPGconn):longint;cdecl;external External_library name 'PQbackendPID';
  66. function PQclientEncoding(conn:PPGconn):longint;cdecl;external External_library name 'PQclientEncoding';
  67. function PQsetClientEncoding(conn:PPGconn; encoding:PAnsiChar):longint;cdecl;external External_library name 'PQsetClientEncoding';
  68. {$ifdef USE_SSL}
  69. { Get the SSL structure associated with a connection }
  70. function PQgetssl(conn:PPGconn):PSSL;cdecl;external External_library name 'PQgetssl';
  71. {$endif}
  72. { Set verbosity for PQerrorMessage and PQresultErrorMessage }
  73. function PQsetErrorVerbosity(conn:PPGconn; verbosity:PGVerbosity):PGVerbosity;cdecl;external External_library name 'PQsetErrorVerbosity';
  74. { Enable/disable tracing }
  75. procedure PQtrace(conn:PPGconn; debug_port:PFILE);cdecl;external External_library name 'PQtrace';
  76. procedure PQuntrace(conn:PPGconn);cdecl;external External_library name 'PQuntrace';
  77. { Override default notice handling routines }
  78. function PQsetNoticeReceiver(conn:PPGconn; proc:PQnoticeReceiver; arg:pointer):PQnoticeReceiver;cdecl;external External_library name 'PQsetNoticeReceiver';
  79. function PQsetNoticeProcessor(conn:PPGconn; proc:PQnoticeProcessor; arg:pointer):PQnoticeProcessor;cdecl;external External_library name 'PQsetNoticeProcessor';
  80. { === in fe-exec.c === }
  81. { Simple synchronous query }
  82. function PQexec(conn:PPGconn; query:PAnsiChar):PPGresult;cdecl;external External_library name 'PQexec';
  83. function PQexecParams(conn:PPGconn; command:PAnsiChar; nParams:longint; paramTypes:POid; paramValues:PPAnsiChar;
  84. paramLengths:Plongint; paramFormats:Plongint; resultFormat:longint):PPGresult;cdecl;external External_library name 'PQexecParams';
  85. function PQexecPrepared(conn:PPGconn; stmtName:PAnsiChar; nParams:longint; paramValues:PPAnsiChar; paramLengths:Plongint;
  86. paramFormats:Plongint; resultFormat:longint):PPGresult;cdecl;external External_library name 'PQexecPrepared';
  87. function PQdescribePrepared(conn:PPGconn; stmtName:PAnsiChar):PPGresult;cdecl;external External_library name 'PQdescribePrepared';
  88. { Interface for multiple-result or asynchronous queries }
  89. function PQsendQuery(conn:PPGconn; query:PAnsiChar):longint;cdecl;external External_library name 'PQsendQuery';
  90. function PQsendQueryParams(conn:PPGconn; command:PAnsiChar; nParams:longint; paramTypes:POid; paramValues:PPAnsiChar;
  91. paramLengths:Plongint; paramFormats:Plongint; resultFormat:longint):longint;cdecl;external External_library name 'PQsendQueryParams';
  92. function PQsendQueryPrepared(conn:PPGconn; stmtName:PAnsiChar; nParams:longint; paramValues:PPAnsiChar; paramLengths:Plongint;
  93. paramFormats:Plongint; resultFormat:longint):longint;cdecl;external External_library name 'PQsendQueryPrepared';
  94. function PQgetResult(conn:PPGconn):PPGresult;cdecl;external External_library name 'PQgetResult';
  95. { Routines for managing an asynchronous query }
  96. function PQisBusy(conn:PPGconn):longint;cdecl;external External_library name 'PQisBusy';
  97. function PQconsumeInput(conn:PPGconn):longint;cdecl;external External_library name 'PQconsumeInput';
  98. { LISTEN/NOTIFY support }
  99. function PQnotifies(conn:PPGconn):PPGnotify;cdecl;external External_library name 'PQnotifies';
  100. { Routines for copy in/out }
  101. function PQputCopyData(conn:PPGconn; buffer:PAnsiChar; nbytes:longint):longint;cdecl;external External_library name 'PQputCopyData';
  102. function PQputCopyEnd(conn:PPGconn; errormsg:PAnsiChar):longint;cdecl;external External_library name 'PQputCopyEnd';
  103. function PQgetCopyData(conn:PPGconn; buffer:PPAnsiChar; async:longint):longint;cdecl;external External_library name 'PQgetCopyData';
  104. { Deprecated routines for copy in/out }
  105. function PQgetline(conn:PPGconn; _string:PAnsiChar; length:longint):longint;cdecl;external External_library name 'PQgetline';
  106. function PQputline(conn:PPGconn; _string:PAnsiChar):longint;cdecl;external External_library name 'PQputline';
  107. function PQgetlineAsync(conn:PPGconn; buffer:PAnsiChar; bufsize:longint):longint;cdecl;external External_library name 'PQgetlineAsync';
  108. function PQputnbytes(conn:PPGconn; buffer:PAnsiChar; nbytes:longint):longint;cdecl;external External_library name 'PQputnbytes';
  109. function PQendcopy(conn:PPGconn):longint;cdecl;external External_library name 'PQendcopy';
  110. { Set blocking/nonblocking connection to the backend }
  111. function PQsetnonblocking(conn:PPGconn; arg:longint):longint;cdecl;external External_library name 'PQsetnonblocking';
  112. function PQisnonblocking(conn:PPGconn):longint;cdecl;external External_library name 'PQisnonblocking';
  113. { Force the write buffer to be written (or at least try) }
  114. function PQflush(conn:PPGconn):longint;cdecl;external External_library name 'PQflush';
  115. {
  116. * "Fast path" interface --- not really recommended for application
  117. * use
  118. }
  119. function PQfn(conn:PPGconn; fnid:longint; result_buf:Plongint; result_len:Plongint; result_is_int:longint;
  120. args:PPQArgBlock; nargs:longint):PPGresult;cdecl;external External_library name 'PQfn';
  121. { Accessor functions for PGresult objects }
  122. function PQresultStatus(res:PPGresult):TExecStatusType;cdecl;external External_library name 'PQresultStatus';
  123. function PQresStatus(status:TExecStatusType):PAnsiChar;cdecl;external External_library name 'PQresStatus';
  124. function PQresultErrorMessage(res:PPGresult):PAnsiChar;cdecl;external External_library name 'PQresultErrorMessage';
  125. function PQresultErrorField(res:PPGresult; fieldcode:longint):PAnsiChar;cdecl;external External_library name 'PQresultErrorField';
  126. function PQntuples(res:PPGresult):longint;cdecl;external External_library name 'PQntuples';
  127. function PQnfields(res:PPGresult):longint;cdecl;external External_library name 'PQnfields';
  128. function PQbinaryTuples(res:PPGresult):longint;cdecl;external External_library name 'PQbinaryTuples';
  129. function PQfname(res:PPGresult; field_num:longint):PAnsiChar;cdecl;external External_library name 'PQfname';
  130. function PQfnumber(res:PPGresult; field_name:PAnsiChar):longint;cdecl;external External_library name 'PQfnumber';
  131. function PQftable(res:PPGresult; field_num:longint):Oid;cdecl;external External_library name 'PQftable';
  132. function PQftablecol(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQftablecol';
  133. function PQfformat(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQfformat';
  134. function PQftype(res:PPGresult; field_num:longint):Oid;cdecl;external External_library name 'PQftype';
  135. function PQfsize(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQfsize';
  136. function PQfmod(res:PPGresult; field_num:longint):longint;cdecl;external External_library name 'PQfmod';
  137. function PQcmdStatus(res:PPGresult):PAnsiChar;cdecl;external External_library name 'PQcmdStatus';
  138. function PQoidStatus(res:PPGresult):PAnsiChar;cdecl;external External_library name 'PQoidStatus';
  139. { old and ugly }
  140. function PQoidValue(res:PPGresult):Oid;cdecl;external External_library name 'PQoidValue';
  141. { new and improved }
  142. function PQcmdTuples(res:PPGresult):PAnsiChar;cdecl;external External_library name 'PQcmdTuples';
  143. function PQgetvalue(res:PPGresult; tup_num:longint; field_num:longint):PAnsiChar;cdecl;external External_library name 'PQgetvalue';
  144. function PQgetlength(res:PPGresult; tup_num:longint; field_num:longint):longint;cdecl;external External_library name 'PQgetlength';
  145. function PQgetisnull(res:PPGresult; tup_num:longint; field_num:longint):longint;cdecl;external External_library name 'PQgetisnull';
  146. { Delete a PGresult }
  147. procedure PQclear(res:PPGresult);cdecl;external External_library name 'PQclear';
  148. { For freeing other alloc'd results, such as PGnotify structs }
  149. procedure PQfreemem(ptr:pointer);cdecl;external External_library name 'PQfreemem';
  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. function PQmakeEmptyPGresult(conn:PPGconn; status:TExecStatusType):PPGresult;cdecl;external External_library name 'PQmakeEmptyPGresult';
  161. { Quoting strings before inclusion in queries. }
  162. function PQescapeString(till:PAnsiChar; from:PAnsiChar; length:size_t):size_t;cdecl;external External_library name 'PQescapeString';
  163. function PQescapeBytea(bintext:Pbyte; binlen:size_t; bytealen:Psize_t):Pbyte;cdecl;external External_library name 'PQescapeBytea';
  164. function PQunescapeBytea(strtext:Pbyte; retbuflen:Psize_t):Pbyte;cdecl;external External_library name 'PQunescapeBytea';
  165. { === in fe-print.c === }
  166. { output stream }
  167. procedure PQprint(fout:PFILE; res:PPGresult; ps:PPQprintOpt);cdecl;external External_library name 'PQprint';
  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. procedure PQdisplayTuples(res:PPGresult; fp:PFILE; fillAlign:longint; fieldSep:PAnsiChar; printHeader:longint;
  177. quiet:longint);cdecl;external External_library name 'PQdisplayTuples';
  178. (* Const before type ignored *)
  179. { output stream }
  180. { print attribute names }
  181. { delimiter bars }
  182. procedure PQprintTuples(res:PPGresult; fout:PFILE; printAttName:longint; terseOutput:longint; width:longint);cdecl;external External_library name 'PQprintTuples';
  183. { width of column, if 0, use variable
  184. * width }
  185. { === in fe-lobj.c === }
  186. { Large-object access routines }
  187. function lo_open(conn:PPGconn; lobjId:Oid; mode:longint):longint;cdecl;external External_library name 'lo_open';
  188. function lo_close(conn:PPGconn; fd:longint):longint;cdecl;external External_library name 'lo_close';
  189. function lo_read(conn:PPGconn; fd:longint; buf:PAnsiChar; len:size_t):longint;cdecl;external External_library name 'lo_read';
  190. function lo_write(conn:PPGconn; fd:longint; buf:PAnsiChar; len:size_t):longint;cdecl;external External_library name 'lo_write';
  191. function lo_lseek(conn:PPGconn; fd:longint; offset:longint; whence:longint):longint;cdecl;external External_library name 'lo_lseek';
  192. function lo_creat(conn:PPGconn; mode:longint):Oid;cdecl;external External_library name 'lo_creat';
  193. function lo_tell(conn:PPGconn; fd:longint):longint;cdecl;external External_library name 'lo_tell';
  194. function lo_unlink(conn:PPGconn; lobjId:Oid):longint;cdecl;external External_library name 'lo_unlink';
  195. function lo_import(conn:PPGconn; filename:PAnsiChar):Oid;cdecl;external External_library name 'lo_import';
  196. function lo_export(conn:PPGconn; lobjId:Oid; filename:PAnsiChar):longint;cdecl;external External_library name 'lo_export';
  197. { === in fe-misc.c === }
  198. { Determine length of multibyte encoded AnsiChar at *s }
  199. function PQmblen(s:Pbyte; encoding:longint):longint;cdecl;external External_library name 'PQmblen';
  200. { Get encoding id from environment variable PGCLIENTENCODING }
  201. function PQenv2encoding:longint;cdecl;external External_library name 'PQenv2encoding';
  202. implementation
  203. { was #define dname(params) para_def_expr }
  204. { argument types are unknown }
  205. { return type might be wrong }
  206. // This function is also defined in postgres3dyn!
  207. function PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME : PAnsiChar) : ppgconn;
  208. begin
  209. PQsetdb:=PQsetdbLogin(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME,'','');
  210. end;
  211. { was #define dname(params) para_def_expr }
  212. { argument types are unknown }
  213. { return type might be wrong }
  214. { function PQfreeNotify(ptr : longint) : longint;
  215. begin
  216. PQfreeNotify:=PQfreemem(ptr);
  217. end;}
  218. end.