postgres.nim 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # This module contains the definitions for structures and externs for
  10. # functions used by frontend postgres applications. It is based on
  11. # Postgresql's libpq-fe.h.
  12. #
  13. # It is for postgreSQL version 7.4 and higher with support for the v3.0
  14. # connection-protocol.
  15. #
  16. when defined(nimHasStyleChecks):
  17. {.push styleChecks: off.}
  18. when defined(windows):
  19. const
  20. dllName = "libpq.dll"
  21. elif defined(macosx):
  22. const
  23. dllName = "libpq.dylib"
  24. else:
  25. const
  26. dllName = "libpq.so(.5|)"
  27. type
  28. POid* = ptr Oid
  29. Oid* = int32
  30. const
  31. ERROR_MSG_LENGTH* = 4096
  32. CMDSTATUS_LEN* = 40
  33. type
  34. SockAddr* = array[1..112, int8]
  35. PGresAttDesc*{.pure, final.} = object
  36. name*: cstring
  37. adtid*: Oid
  38. adtsize*: int
  39. PPGresAttDesc* = ptr PGresAttDesc
  40. PPPGresAttDesc* = ptr PPGresAttDesc
  41. PGresAttValue*{.pure, final.} = object
  42. length*: int32
  43. value*: cstring
  44. PPGresAttValue* = ptr PGresAttValue
  45. PPPGresAttValue* = ptr PPGresAttValue
  46. PExecStatusType* = ptr ExecStatusType
  47. ExecStatusType* = enum
  48. PGRES_EMPTY_QUERY = 0, PGRES_COMMAND_OK, PGRES_TUPLES_OK, PGRES_COPY_OUT,
  49. PGRES_COPY_IN, PGRES_BAD_RESPONSE, PGRES_NONFATAL_ERROR, PGRES_FATAL_ERROR,
  50. PGRES_COPY_BOTH, PGRES_SINGLE_TUPLE
  51. PGlobjfuncs*{.pure, final.} = object
  52. fn_lo_open*: Oid
  53. fn_lo_close*: Oid
  54. fn_lo_creat*: Oid
  55. fn_lo_unlink*: Oid
  56. fn_lo_lseek*: Oid
  57. fn_lo_tell*: Oid
  58. fn_lo_read*: Oid
  59. fn_lo_write*: Oid
  60. PPGlobjfuncs* = ptr PGlobjfuncs
  61. PConnStatusType* = ptr ConnStatusType
  62. ConnStatusType* = enum
  63. CONNECTION_OK, CONNECTION_BAD, CONNECTION_STARTED, CONNECTION_MADE,
  64. CONNECTION_AWAITING_RESPONSE, CONNECTION_AUTH_OK, CONNECTION_SETENV,
  65. CONNECTION_SSL_STARTUP, CONNECTION_NEEDED, CONNECTION_CHECK_WRITABLE,
  66. CONNECTION_CONSUME, CONNECTION_GSS_STARTUP, CONNECTION_CHECK_TARGET
  67. PGconn*{.pure, final.} = object
  68. pghost*: cstring
  69. pgtty*: cstring
  70. pgport*: cstring
  71. pgoptions*: cstring
  72. dbName*: cstring
  73. status*: ConnStatusType
  74. errorMessage*: array[0..(ERROR_MSG_LENGTH) - 1, char]
  75. Pfin*: File
  76. Pfout*: File
  77. Pfdebug*: File
  78. sock*: int32
  79. laddr*: SockAddr
  80. raddr*: SockAddr
  81. salt*: array[0..(2) - 1, char]
  82. asyncNotifyWaiting*: int32
  83. notifyList*: pointer
  84. pguser*: cstring
  85. pgpass*: cstring
  86. lobjfuncs*: PPGlobjfuncs
  87. PPGconn* = ptr PGconn
  88. PGresult*{.pure, final.} = object
  89. ntups*: int32
  90. numAttributes*: int32
  91. attDescs*: PPGresAttDesc
  92. tuples*: PPPGresAttValue
  93. tupArrSize*: int32
  94. resultStatus*: ExecStatusType
  95. cmdStatus*: array[0..(CMDSTATUS_LEN) - 1, char]
  96. binary*: int32
  97. conn*: PPGconn
  98. PPGresult* = ptr PGresult
  99. PPostgresPollingStatusType* = ptr PostgresPollingStatusType
  100. PostgresPollingStatusType* = enum
  101. PGRES_POLLING_FAILED = 0, PGRES_POLLING_READING, PGRES_POLLING_WRITING,
  102. PGRES_POLLING_OK, PGRES_POLLING_ACTIVE
  103. PPGTransactionStatusType* = ptr PGTransactionStatusType
  104. PGTransactionStatusType* = enum
  105. PQTRANS_IDLE, PQTRANS_ACTIVE, PQTRANS_INTRANS, PQTRANS_INERROR,
  106. PQTRANS_UNKNOWN
  107. PPGVerbosity* = ptr PGVerbosity
  108. PGVerbosity* = enum
  109. PQERRORS_TERSE, PQERRORS_DEFAULT, PQERRORS_VERBOSE, PQERRORS_SQLSTATE
  110. PPGNotify* = ptr pgNotify
  111. pgNotify*{.pure, final.} = object
  112. relname*: cstring
  113. be_pid*: int32
  114. extra*: cstring
  115. PQnoticeReceiver* = proc (arg: pointer, res: PPGresult){.cdecl.}
  116. PQnoticeProcessor* = proc (arg: pointer, message: cstring){.cdecl.}
  117. Ppqbool* = ptr pqbool
  118. pqbool* = char
  119. PPQprintOpt* = ptr PQprintOpt
  120. PQprintOpt*{.pure, final.} = object
  121. header*: pqbool
  122. align*: pqbool
  123. standard*: pqbool
  124. html3*: pqbool
  125. expanded*: pqbool
  126. pager*: pqbool
  127. fieldSep*: cstring
  128. tableOpt*: cstring
  129. caption*: cstring
  130. fieldName*: ptr cstring
  131. PPQconninfoOption* = ptr PQconninfoOption
  132. PQconninfoOption*{.pure, final.} = object
  133. keyword*: cstring
  134. envvar*: cstring
  135. compiled*: cstring
  136. val*: cstring
  137. label*: cstring
  138. dispchar*: cstring
  139. dispsize*: int32
  140. PPQArgBlock* = ptr PQArgBlock
  141. PQArgBlock*{.pure, final.} = object
  142. length*: int32
  143. isint*: int32
  144. p*: pointer
  145. proc pqinitOpenSSL*(do_ssl: int32, do_crypto: int32) {.cdecl, dynlib: dllName,
  146. importc: "PQinitOpenSSL".}
  147. proc pqconnectStart*(conninfo: cstring): PPGconn{.cdecl, dynlib: dllName,
  148. importc: "PQconnectStart".}
  149. proc pqconnectPoll*(conn: PPGconn): PostgresPollingStatusType{.cdecl,
  150. dynlib: dllName, importc: "PQconnectPoll".}
  151. proc pqconnectdb*(conninfo: cstring): PPGconn{.cdecl, dynlib: dllName,
  152. importc: "PQconnectdb".}
  153. proc pqsetdbLogin*(pghost: cstring, pgport: cstring, pgoptions: cstring,
  154. pgtty: cstring, dbName: cstring, login: cstring, pwd: cstring): PPGconn{.
  155. cdecl, dynlib: dllName, importc: "PQsetdbLogin".}
  156. proc pqsetdb*(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME: cstring): PPGconn
  157. proc pqfinish*(conn: PPGconn){.cdecl, dynlib: dllName, importc: "PQfinish".}
  158. proc pqconndefaults*(): PPQconninfoOption{.cdecl, dynlib: dllName,
  159. importc: "PQconndefaults".}
  160. proc pqconninfoFree*(connOptions: PPQconninfoOption){.cdecl, dynlib: dllName,
  161. importc: "PQconninfoFree".}
  162. proc pqresetStart*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  163. importc: "PQresetStart".}
  164. proc pqresetPoll*(conn: PPGconn): PostgresPollingStatusType{.cdecl,
  165. dynlib: dllName, importc: "PQresetPoll".}
  166. proc pqreset*(conn: PPGconn){.cdecl, dynlib: dllName, importc: "PQreset".}
  167. proc pqrequestCancel*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  168. importc: "PQrequestCancel".}
  169. proc pqdb*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQdb".}
  170. proc pquser*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQuser".}
  171. proc pqpass*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQpass".}
  172. proc pqhost*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQhost".}
  173. proc pqport*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQport".}
  174. proc pqtty*(conn: PPGconn): cstring{.cdecl, dynlib: dllName, importc: "PQtty".}
  175. proc pqoptions*(conn: PPGconn): cstring{.cdecl, dynlib: dllName,
  176. importc: "PQoptions".}
  177. proc pqstatus*(conn: PPGconn): ConnStatusType{.cdecl, dynlib: dllName,
  178. importc: "PQstatus".}
  179. proc pqtransactionStatus*(conn: PPGconn): PGTransactionStatusType{.cdecl,
  180. dynlib: dllName, importc: "PQtransactionStatus".}
  181. proc pqparameterStatus*(conn: PPGconn, paramName: cstring): cstring{.cdecl,
  182. dynlib: dllName, importc: "PQparameterStatus".}
  183. proc pqserverVersion*(conn: PPGconn): int32{.cdecl,
  184. dynlib: dllName, importc: "PQserverVersion".}
  185. proc pqprotocolVersion*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  186. importc: "PQprotocolVersion".}
  187. proc pqerrorMessage*(conn: PPGconn): cstring{.cdecl, dynlib: dllName,
  188. importc: "PQerrorMessage".}
  189. proc pqsocket*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  190. importc: "PQsocket".}
  191. proc pqbackendPID*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  192. importc: "PQbackendPID".}
  193. proc pqconnectionNeedsPassword*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  194. importc: "PQconnectionNeedsPassword".}
  195. proc pqconnectionUsedPassword*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  196. importc: "PQconnectionUsedPassword".}
  197. proc pqclientEncoding*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  198. importc: "PQclientEncoding".}
  199. proc pqsetClientEncoding*(conn: PPGconn, encoding: cstring): int32{.cdecl,
  200. dynlib: dllName, importc: "PQsetClientEncoding".}
  201. when defined(USE_SSL):
  202. # Get the SSL structure associated with a connection
  203. proc pqgetssl*(conn: PPGconn): PSSL{.cdecl, dynlib: dllName,
  204. importc: "PQgetssl".}
  205. proc pqsetErrorVerbosity*(conn: PPGconn, verbosity: PGVerbosity): PGVerbosity{.
  206. cdecl, dynlib: dllName, importc: "PQsetErrorVerbosity".}
  207. proc pqtrace*(conn: PPGconn, debug_port: File){.cdecl, dynlib: dllName,
  208. importc: "PQtrace".}
  209. proc pquntrace*(conn: PPGconn){.cdecl, dynlib: dllName, importc: "PQuntrace".}
  210. proc pqsetNoticeReceiver*(conn: PPGconn, theProc: PQnoticeReceiver, arg: pointer): PQnoticeReceiver{.
  211. cdecl, dynlib: dllName, importc: "PQsetNoticeReceiver".}
  212. proc pqsetNoticeProcessor*(conn: PPGconn, theProc: PQnoticeProcessor,
  213. arg: pointer): PQnoticeProcessor{.cdecl,
  214. dynlib: dllName, importc: "PQsetNoticeProcessor".}
  215. proc pqexec*(conn: PPGconn, query: cstring): PPGresult{.cdecl, dynlib: dllName,
  216. importc: "PQexec".}
  217. proc pqexecParams*(conn: PPGconn, command: cstring, nParams: int32,
  218. paramTypes: POid, paramValues: cstringArray,
  219. paramLengths, paramFormats: ptr int32, resultFormat: int32): PPGresult{.
  220. cdecl, dynlib: dllName, importc: "PQexecParams".}
  221. proc pqprepare*(conn: PPGconn, stmtName, query: cstring, nParams: int32,
  222. paramTypes: POid): PPGresult{.cdecl, dynlib: dllName, importc: "PQprepare".}
  223. proc pqexecPrepared*(conn: PPGconn, stmtName: cstring, nParams: int32,
  224. paramValues: cstringArray,
  225. paramLengths, paramFormats: ptr int32, resultFormat: int32): PPGresult{.
  226. cdecl, dynlib: dllName, importc: "PQexecPrepared".}
  227. proc pqsendQuery*(conn: PPGconn, query: cstring): int32{.cdecl, dynlib: dllName,
  228. importc: "PQsendQuery".}
  229. ## See also https://www.postgresql.org/docs/current/libpq-async.html
  230. proc pqsendQueryParams*(conn: PPGconn, command: cstring, nParams: int32,
  231. paramTypes: POid, paramValues: cstringArray,
  232. paramLengths, paramFormats: ptr int32,
  233. resultFormat: int32): int32{.cdecl, dynlib: dllName,
  234. importc: "PQsendQueryParams".}
  235. proc pqsendQueryPrepared*(conn: PPGconn, stmtName: cstring, nParams: int32,
  236. paramValues: cstringArray,
  237. paramLengths, paramFormats: ptr int32,
  238. resultFormat: int32): int32{.cdecl, dynlib: dllName,
  239. importc: "PQsendQueryPrepared".}
  240. proc pqSetSingleRowMode*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  241. importc: "PQsetSingleRowMode".}
  242. ## See also https://www.postgresql.org/docs/current/libpq-single-row-mode.html
  243. proc pqgetResult*(conn: PPGconn): PPGresult{.cdecl, dynlib: dllName,
  244. importc: "PQgetResult".}
  245. proc pqisBusy*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  246. importc: "PQisBusy".}
  247. proc pqconsumeInput*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  248. importc: "PQconsumeInput".}
  249. proc pqnotifies*(conn: PPGconn): PPGNotify{.cdecl, dynlib: dllName,
  250. importc: "PQnotifies".}
  251. proc pqputCopyData*(conn: PPGconn, buffer: cstring, nbytes: int32): int32{.
  252. cdecl, dynlib: dllName, importc: "PQputCopyData".}
  253. proc pqputCopyEnd*(conn: PPGconn, errormsg: cstring): int32{.cdecl,
  254. dynlib: dllName, importc: "PQputCopyEnd".}
  255. proc pqgetCopyData*(conn: PPGconn, buffer: cstringArray, async: int32): int32{.
  256. cdecl, dynlib: dllName, importc: "PQgetCopyData".}
  257. proc pqgetline*(conn: PPGconn, str: cstring, len: int32): int32{.cdecl,
  258. dynlib: dllName, importc: "PQgetline".}
  259. proc pqputline*(conn: PPGconn, str: cstring): int32{.cdecl, dynlib: dllName,
  260. importc: "PQputline".}
  261. proc pqgetlineAsync*(conn: PPGconn, buffer: cstring, bufsize: int32): int32{.
  262. cdecl, dynlib: dllName, importc: "PQgetlineAsync".}
  263. proc pqputnbytes*(conn: PPGconn, buffer: cstring, nbytes: int32): int32{.cdecl,
  264. dynlib: dllName, importc: "PQputnbytes".}
  265. proc pqendcopy*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  266. importc: "PQendcopy".}
  267. proc pqsetnonblocking*(conn: PPGconn, arg: int32): int32{.cdecl,
  268. dynlib: dllName, importc: "PQsetnonblocking".}
  269. proc pqisnonblocking*(conn: PPGconn): int32{.cdecl, dynlib: dllName,
  270. importc: "PQisnonblocking".}
  271. proc pqflush*(conn: PPGconn): int32{.cdecl, dynlib: dllName, importc: "PQflush".}
  272. proc pqfn*(conn: PPGconn, fnid: int32, result_buf, result_len: ptr int32,
  273. result_is_int: int32, args: PPQArgBlock, nargs: int32): PPGresult{.
  274. cdecl, dynlib: dllName, importc: "PQfn".}
  275. proc pqresultStatus*(res: PPGresult): ExecStatusType{.cdecl, dynlib: dllName,
  276. importc: "PQresultStatus".}
  277. proc pqresStatus*(status: ExecStatusType): cstring{.cdecl, dynlib: dllName,
  278. importc: "PQresStatus".}
  279. proc pqresultErrorMessage*(res: PPGresult): cstring{.cdecl, dynlib: dllName,
  280. importc: "PQresultErrorMessage".}
  281. proc pqresultErrorField*(res: PPGresult, fieldcode: int32): cstring{.cdecl,
  282. dynlib: dllName, importc: "PQresultErrorField".}
  283. proc pqntuples*(res: PPGresult): int32{.cdecl, dynlib: dllName,
  284. importc: "PQntuples".}
  285. proc pqnfields*(res: PPGresult): int32{.cdecl, dynlib: dllName,
  286. importc: "PQnfields".}
  287. proc pqbinaryTuples*(res: PPGresult): int32{.cdecl, dynlib: dllName,
  288. importc: "PQbinaryTuples".}
  289. proc pqfname*(res: PPGresult, field_num: int32): cstring{.cdecl,
  290. dynlib: dllName, importc: "PQfname".}
  291. proc pqfnumber*(res: PPGresult, field_name: cstring): int32{.cdecl,
  292. dynlib: dllName, importc: "PQfnumber".}
  293. proc pqftable*(res: PPGresult, field_num: int32): Oid{.cdecl, dynlib: dllName,
  294. importc: "PQftable".}
  295. proc pqftablecol*(res: PPGresult, field_num: int32): int32{.cdecl,
  296. dynlib: dllName, importc: "PQftablecol".}
  297. proc pqfformat*(res: PPGresult, field_num: int32): int32{.cdecl,
  298. dynlib: dllName, importc: "PQfformat".}
  299. proc pqftype*(res: PPGresult, field_num: int32): Oid{.cdecl, dynlib: dllName,
  300. importc: "PQftype".}
  301. proc pqfsize*(res: PPGresult, field_num: int32): int32{.cdecl, dynlib: dllName,
  302. importc: "PQfsize".}
  303. proc pqfmod*(res: PPGresult, field_num: int32): int32{.cdecl, dynlib: dllName,
  304. importc: "PQfmod".}
  305. proc pqcmdStatus*(res: PPGresult): cstring{.cdecl, dynlib: dllName,
  306. importc: "PQcmdStatus".}
  307. proc pqoidStatus*(res: PPGresult): cstring{.cdecl, dynlib: dllName,
  308. importc: "PQoidStatus".}
  309. proc pqoidValue*(res: PPGresult): Oid{.cdecl, dynlib: dllName,
  310. importc: "PQoidValue".}
  311. proc pqcmdTuples*(res: PPGresult): cstring{.cdecl, dynlib: dllName,
  312. importc: "PQcmdTuples".}
  313. proc pqgetvalue*(res: PPGresult, tup_num: int32, field_num: int32): cstring{.
  314. cdecl, dynlib: dllName, importc: "PQgetvalue".}
  315. proc pqgetlength*(res: PPGresult, tup_num: int32, field_num: int32): int32{.
  316. cdecl, dynlib: dllName, importc: "PQgetlength".}
  317. proc pqgetisnull*(res: PPGresult, tup_num: int32, field_num: int32): int32{.
  318. cdecl, dynlib: dllName, importc: "PQgetisnull".}
  319. proc pqclear*(res: PPGresult){.cdecl, dynlib: dllName, importc: "PQclear".}
  320. proc pqfreemem*(p: pointer){.cdecl, dynlib: dllName, importc: "PQfreemem".}
  321. proc pqmakeEmptyPGresult*(conn: PPGconn, status: ExecStatusType): PPGresult{.
  322. cdecl, dynlib: dllName, importc: "PQmakeEmptyPGresult".}
  323. proc pqescapeString*(till, `from`: cstring, len: int): int{.cdecl,
  324. dynlib: dllName, importc: "PQescapeString".}
  325. proc pqescapeBytea*(bintext: cstring, binlen: int, bytealen: var int): cstring{.
  326. cdecl, dynlib: dllName, importc: "PQescapeBytea".}
  327. proc pqunescapeBytea*(strtext: cstring, retbuflen: var int): cstring{.cdecl,
  328. dynlib: dllName, importc: "PQunescapeBytea".}
  329. proc pqprint*(fout: File, res: PPGresult, ps: PPQprintOpt){.cdecl,
  330. dynlib: dllName, importc: "PQprint".}
  331. proc pqdisplayTuples*(res: PPGresult, fp: File, fillAlign: int32,
  332. fieldSep: cstring, printHeader: int32, quiet: int32){.
  333. cdecl, dynlib: dllName, importc: "PQdisplayTuples".}
  334. proc pqprintTuples*(res: PPGresult, fout: File, printAttName: int32,
  335. terseOutput: int32, width: int32){.cdecl, dynlib: dllName,
  336. importc: "PQprintTuples".}
  337. proc lo_open*(conn: PPGconn, lobjId: Oid, mode: int32): int32{.cdecl,
  338. dynlib: dllName, importc: "lo_open".}
  339. proc lo_close*(conn: PPGconn, fd: int32): int32{.cdecl, dynlib: dllName,
  340. importc: "lo_close".}
  341. proc lo_read*(conn: PPGconn, fd: int32, buf: cstring, length: int): int32{.
  342. cdecl, dynlib: dllName, importc: "lo_read".}
  343. proc lo_write*(conn: PPGconn, fd: int32, buf: cstring, length: int): int32{.
  344. cdecl, dynlib: dllName, importc: "lo_write".}
  345. proc lo_lseek*(conn: PPGconn, fd: int32, offset: int32, whence: int32): int32{.
  346. cdecl, dynlib: dllName, importc: "lo_lseek".}
  347. proc lo_creat*(conn: PPGconn, mode: int32): Oid{.cdecl, dynlib: dllName,
  348. importc: "lo_creat".}
  349. proc lo_tell*(conn: PPGconn, fd: int32): int32{.cdecl, dynlib: dllName,
  350. importc: "lo_tell".}
  351. proc lo_unlink*(conn: PPGconn, lobjId: Oid): int32{.cdecl, dynlib: dllName,
  352. importc: "lo_unlink".}
  353. proc lo_import*(conn: PPGconn, filename: cstring): Oid{.cdecl, dynlib: dllName,
  354. importc: "lo_import".}
  355. proc lo_export*(conn: PPGconn, lobjId: Oid, filename: cstring): int32{.cdecl,
  356. dynlib: dllName, importc: "lo_export".}
  357. proc pqmblen*(s: cstring, encoding: int32): int32{.cdecl, dynlib: dllName,
  358. importc: "PQmblen".}
  359. proc pqenv2encoding*(): int32{.cdecl, dynlib: dllName, importc: "PQenv2encoding".}
  360. proc pqsetdb(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME: cstring): PPGconn =
  361. result = pqsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, "", "")
  362. when defined(nimHasStyleChecks):
  363. {.pop.}