PostgresLibrary.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. //
  2. // System.Data.SqlClient.PostgresLibrary.cs
  3. //
  4. // PInvoke methods to libpq
  5. // which is PostgreSQL client library
  6. //
  7. // May also contain enumerations,
  8. // data types, or wrapper methods.
  9. //
  10. // Author:
  11. // Rodrigo Moya ([email protected])
  12. // Daniel Morgan ([email protected])
  13. //
  14. // (C) Ximian, Inc 2002
  15. //
  16. // *** uncomment #define to get debug messages, comment for production ***
  17. //#define DEBUG_PostgresLibrary
  18. using System;
  19. using System.Data;
  20. using System.Runtime.InteropServices;
  21. using System.Diagnostics;
  22. using System.Collections;
  23. namespace System.Data.SqlClient {
  24. /* IMPORTANT: DO NOT CHANGE ANY OF THESE ENUMS BELOW */
  25. internal enum ConnStatusType
  26. {
  27. CONNECTION_OK,
  28. CONNECTION_BAD,
  29. CONNECTION_STARTED,
  30. CONNECTION_MADE,
  31. CONNECTION_AWAITING_RESPONSE,
  32. CONNECTION_AUTH_OK,
  33. CONNECTION_SETENV
  34. }
  35. internal enum PostgresPollingStatusType
  36. {
  37. PGRES_POLLING_FAILED = 0,
  38. PGRES_POLLING_READING,
  39. PGRES_POLLING_WRITING,
  40. PGRES_POLLING_OK,
  41. PGRES_POLLING_ACTIVE
  42. }
  43. internal enum ExecStatusType
  44. {
  45. PGRES_EMPTY_QUERY = 0,
  46. PGRES_COMMAND_OK,
  47. PGRES_TUPLES_OK,
  48. PGRES_COPY_OUT,
  49. PGRES_COPY_IN,
  50. PGRES_BAD_RESPONSE,
  51. PGRES_NONFATAL_ERROR,
  52. PGRES_FATAL_ERROR
  53. }
  54. internal struct PostgresType {
  55. public int oid;
  56. public string typname;
  57. public DbType dbType;
  58. }
  59. sealed internal class PostgresHelper {
  60. // translates the PostgreSQL typname to System.Data.DbType
  61. public static DbType TypnameToSqlDbType(string typname) {
  62. DbType sqlType;
  63. // FIXME: use hashtable here?
  64. switch(typname) {
  65. case "abstime":
  66. sqlType = DbType.Int32;
  67. break;
  68. case "aclitem":
  69. sqlType = DbType.String;
  70. break;
  71. case "bit":
  72. sqlType = DbType.String;
  73. break;
  74. case "bool":
  75. sqlType = DbType.Boolean;
  76. break;
  77. case "box":
  78. sqlType = DbType.String;
  79. break;
  80. case "bpchar":
  81. sqlType = DbType.String;
  82. break;
  83. case "bytea":
  84. sqlType = DbType.String;
  85. break;
  86. case "char":
  87. sqlType = DbType.String;
  88. break;
  89. case "cidr":
  90. sqlType = DbType.String;
  91. break;
  92. case "circle":
  93. sqlType = DbType.String;
  94. break;
  95. case "date":
  96. sqlType = DbType.Date;
  97. break;
  98. case "float4":
  99. sqlType = DbType.Single;
  100. break;
  101. case "float8":
  102. sqlType = DbType.Double;
  103. break;
  104. case "inet":
  105. sqlType = DbType.String;
  106. break;
  107. case "int2":
  108. sqlType = DbType.Int16;
  109. break;
  110. case "int4":
  111. sqlType = DbType.Int32;
  112. break;
  113. case "int8":
  114. sqlType = DbType.Int64;
  115. break;
  116. case "interval":
  117. sqlType = DbType.String;
  118. break;
  119. case "line":
  120. sqlType = DbType.String;
  121. break;
  122. case "lseg":
  123. sqlType = DbType.String;
  124. break;
  125. case "macaddr":
  126. sqlType = DbType.String;
  127. break;
  128. case "money":
  129. sqlType = DbType.Decimal;
  130. break;
  131. case "name":
  132. sqlType = DbType.String;
  133. break;
  134. case "numeric":
  135. sqlType = DbType.Decimal;
  136. break;
  137. case "oid":
  138. sqlType = DbType.Int32;
  139. break;
  140. case "path":
  141. sqlType = DbType.String;
  142. break;
  143. case "point":
  144. sqlType = DbType.String;
  145. break;
  146. case "polygon":
  147. sqlType = DbType.String;
  148. break;
  149. case "refcursor":
  150. sqlType = DbType.String;
  151. break;
  152. case "reltime":
  153. sqlType = DbType.String;
  154. break;
  155. case "text":
  156. sqlType = DbType.String;
  157. break;
  158. case "time":
  159. sqlType = DbType.Time;
  160. break;
  161. case "timestamp":
  162. sqlType = DbType.DateTime;
  163. break;
  164. case "timestamptz":
  165. sqlType = DbType.DateTime;
  166. break;
  167. case "timetz":
  168. sqlType = DbType.DateTime;
  169. break;
  170. case "tinterval":
  171. sqlType = DbType.String;
  172. break;
  173. case "varbit":
  174. sqlType = DbType.String;
  175. break;
  176. case "varchar":
  177. sqlType = DbType.String;
  178. break;
  179. default:
  180. sqlType = DbType.String;
  181. break;
  182. }
  183. return sqlType;
  184. }
  185. // Converts data value from database to .NET System type.
  186. public static object ConvertDbTypeToSystem (DbType typ, String value) {
  187. object obj = null;
  188. // FIXME: more types need
  189. // to be converted
  190. // from PostgreSQL oid type
  191. // to .NET System.<type>
  192. // FIXME: need to handle a NULL for each type
  193. // maybe setting obj to System.DBNull.Value ?
  194. //
  195. // if(value == null) {
  196. //#if DEBUG_PostgresLibrary
  197. // Console.WriteLine("column is NULL");
  198. //#endif // DEBUG_PostgresLibrary
  199. // return null;
  200. // }
  201. // else if(value.Equals("")) {
  202. //#if DEBUG_PostgresLibrary
  203. // Console.WriteLine("column has a NULL");
  204. //#endif // DEBUG_PostgresLibrary
  205. //
  206. // return null;
  207. // }
  208. //
  209. //#if DEBUG_PostgresLibrary
  210. // Console.WriteLine("ConvertDbTypeToSystem typ: " +
  211. // typ + " value: " + value);
  212. //#endif // DEBUG_PostgresLibrary
  213. //
  214. // Date, Time, and DateTime
  215. // are parsed based on ISO format
  216. // "YYYY-MM-DD hh:mi:ss.ms"
  217. switch(typ) {
  218. case DbType.String:
  219. obj = String.Copy(value);
  220. break;
  221. case DbType.Boolean:
  222. obj = value.Equals("t");
  223. break;
  224. case DbType.Int16:
  225. obj = Int16.Parse(value);
  226. break;
  227. case DbType.Int32:
  228. obj = Int32.Parse(value);
  229. break;
  230. case DbType.Int64:
  231. obj = Int64.Parse(value);
  232. break;
  233. case DbType.Decimal:
  234. obj = Decimal.Parse(value);
  235. break;
  236. case DbType.Single:
  237. obj = Single.Parse(value);
  238. break;
  239. case DbType.Double:
  240. obj = Double.Parse(value);
  241. break;
  242. case DbType.Date:
  243. String[] sd = value.Split(new Char[] {'-'});
  244. obj = new DateTime(
  245. Int32.Parse(sd[0]), Int32.Parse(sd[1]), Int32.Parse(sd[2]),
  246. 0,0,0);
  247. break;
  248. case DbType.Time:
  249. String[] st = value.Split(new Char[] {':'});
  250. obj = new DateTime(0001,01,01,
  251. Int32.Parse(st[0]),Int32.Parse(st[1]),Int32.Parse(st[2]));
  252. break;
  253. case DbType.DateTime:
  254. Int32 YYYY,MM,DD,hh,mi,ss,ms;
  255. YYYY = Int32.Parse(value.Substring(0,4));
  256. MM = Int32.Parse(value.Substring(5,2));
  257. DD = Int32.Parse(value.Substring(8,2));
  258. hh = Int32.Parse(value.Substring(11,2));
  259. mi = Int32.Parse(value.Substring(14,2));
  260. ss = Int32.Parse(value.Substring(17,2));
  261. ms = Int32.Parse(value.Substring(20,2));
  262. obj = new DateTime(YYYY,MM,DD,hh,mi,ss,ms);
  263. break;
  264. default:
  265. obj = String.Copy(value);
  266. break;
  267. }
  268. return obj;
  269. }
  270. // Translates System.Data.DbType to System.Type
  271. public static Type DbTypeToSystemType (DbType dType) {
  272. // FIXME: more types need
  273. // to be mapped
  274. // from PostgreSQL oid type
  275. // to .NET System.<type>
  276. Type typ = null;
  277. switch(dType) {
  278. case DbType.String:
  279. typ = typeof(String);
  280. break;
  281. case DbType.Boolean:
  282. typ = typeof(Boolean);
  283. break;
  284. case DbType.Int16:
  285. typ = typeof(Int16);
  286. break;
  287. case DbType.Int32:
  288. typ = typeof(Int32);
  289. break;
  290. case DbType.Int64:
  291. typ = typeof(Int64);
  292. break;
  293. case DbType.Decimal:
  294. typ = typeof(Decimal);
  295. break;
  296. case DbType.Single:
  297. typ = typeof(Single);
  298. break;
  299. case DbType.Double:
  300. typ = typeof(Double);
  301. break;
  302. case DbType.Date:
  303. case DbType.Time:
  304. case DbType.DateTime:
  305. typ = typeof(DateTime);
  306. break;
  307. default:
  308. typ = typeof(String);
  309. break;
  310. }
  311. return typ;
  312. }
  313. // Find DbType for oid
  314. // which requires a look up of PostgresTypes
  315. // DbType <-> typname <-> oid
  316. public static string OidToTypname (int oid, ArrayList pgTypes) {
  317. // FIXME: more types need
  318. // to be mapped
  319. // from PostgreSQL oid type
  320. // to .NET System.<type>
  321. string typname = "text"; // default
  322. int i;
  323. for(i = 0; i < pgTypes.Count; i++) {
  324. PostgresType pt = (PostgresType) pgTypes[i];
  325. if(pt.oid == oid) {
  326. typname = pt.typname;
  327. break;
  328. }
  329. }
  330. return typname;
  331. }
  332. }
  333. sealed internal class PostgresLibrary
  334. {
  335. #region PInvoke Functions
  336. // pinvoke prototypes to PostgreSQL client library
  337. // pq.dll on windows and libpq.so on linux
  338. [DllImport("pq")]
  339. public static extern IntPtr PQconnectStart (string conninfo);
  340. // PGconn *PQconnectStart(const char *conninfo);
  341. [DllImport("pq")]
  342. public static extern PostgresPollingStatusType PQconnectPoll (IntPtr conn);
  343. // PostgresPollingStatusType PQconnectPoll(PGconn *conn);
  344. [DllImport("pq")]
  345. public static extern IntPtr PQconnectdb (string conninfo);
  346. // PGconn *PQconnectdb(const char *conninfo);
  347. [DllImport("pq")]
  348. public static extern IntPtr PQsetdbLogin (string pghost,
  349. string pgport, string pgoptions,
  350. string pgtty, string dbName,
  351. string login, string pwd);
  352. // PGconn *PQsetdbLogin(const char *pghost,
  353. // const char *pgport, const char *pgoptions,
  354. // const char *pgtty, const char *dbName,
  355. // const char *login, const char *pwd);
  356. [DllImport("pq")]
  357. public static extern void PQfinish (IntPtr conn);
  358. // void PQfinish(PGconn *conn);
  359. [DllImport("pq")]
  360. public static extern IntPtr PQconndefaults ();
  361. // PQconninfoOption *PQconndefaults(void);
  362. [DllImport("pq")]
  363. public static extern void PQconninfoFree (IntPtr connOptions);
  364. // void PQconninfoFree(PQconninfoOption *connOptions);
  365. [DllImport("pq")]
  366. public static extern int PQresetStart (IntPtr conn);
  367. // int PQresetStart(PGconn *conn);
  368. [DllImport("pq")]
  369. public static extern IntPtr PQresetPoll (IntPtr conn);
  370. // PostgresPollingStatusType PQresetPoll(PGconn *conn);
  371. [DllImport("pq")]
  372. public static extern void PQreset (IntPtr conn);
  373. // void PQreset(PGconn *conn);
  374. [DllImport("pq")]
  375. public static extern int PQrequestCancel (IntPtr conn);
  376. // int PQrequestCancel(PGconn *conn);
  377. [DllImport("pq")]
  378. public static extern string PQdb (IntPtr conn);
  379. // char *PQdb(const PGconn *conn);
  380. [DllImport("pq")]
  381. public static extern string PQuser (IntPtr conn);
  382. // char *PQuser(const PGconn *conn);
  383. [DllImport("pq")]
  384. public static extern string PQpass (IntPtr conn);
  385. // char *PQpass(const PGconn *conn);
  386. [DllImport("pq")]
  387. public static extern string PQhost (IntPtr conn);
  388. // char *PQhost(const PGconn *conn);
  389. [DllImport("pq")]
  390. public static extern string PQport (IntPtr conn);
  391. // char *PQport(const PGconn *conn);
  392. [DllImport("pq")]
  393. public static extern string PQtty (IntPtr conn);
  394. // char *PQtty(const PGconn *conn);
  395. [DllImport("pq")]
  396. public static extern string PQoptions (IntPtr conn);
  397. // char *PQoptions(const PGconn *conn);
  398. [DllImport("pq")]
  399. public static extern ConnStatusType PQstatus (IntPtr conn);
  400. // ConnStatusType PQstatus(const PGconn *conn);
  401. [DllImport("pq")]
  402. public static extern string PQerrorMessage (IntPtr conn);
  403. // char *PQerrorMessage(const PGconn *conn);
  404. [DllImport("pq")]
  405. public static extern int PQsocket (IntPtr conn);
  406. // int PQsocket(const PGconn *conn);
  407. [DllImport("pq")]
  408. public static extern int PQbackendPID (IntPtr conn);
  409. // int PQbackendPID(const PGconn *conn);
  410. [DllImport("pq")]
  411. public static extern int PQclientEncoding (IntPtr conn);
  412. // int PQclientEncoding(const PGconn *conn);
  413. [DllImport("pq")]
  414. public static extern int PQsetClientEncoding (IntPtr conn,
  415. string encoding);
  416. // int PQsetClientEncoding(PGconn *conn,
  417. // const char *encoding);
  418. //FIXME: when loading, causes runtime exception
  419. //[DllImport("pq")]
  420. //public static extern IntPtr PQgetssl (IntPtr conn);
  421. // SSL *PQgetssl(PGconn *conn);
  422. [DllImport("pq")]
  423. public static extern void PQtrace (IntPtr conn,
  424. IntPtr debug_port);
  425. // void PQtrace(PGconn *conn,
  426. // FILE *debug_port);
  427. [DllImport("pq")]
  428. public static extern void PQuntrace (IntPtr conn);
  429. // void PQuntrace(PGconn *conn);
  430. [DllImport("pq")]
  431. public static extern IntPtr PQsetNoticeProcessor (IntPtr conn,
  432. IntPtr proc, IntPtr arg);
  433. // PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
  434. // PQnoticeProcessor proc, void *arg);
  435. [DllImport("pq")]
  436. public static extern int PQescapeString (string to,
  437. string from, int length);
  438. // size_t PQescapeString(char *to,
  439. // const char *from, size_t length);
  440. [DllImport("pq")]
  441. public static extern string PQescapeBytea (string bintext,
  442. int binlen, IntPtr bytealen);
  443. // unsigned char *PQescapeBytea(unsigned char *bintext,
  444. // size_t binlen, size_t *bytealen);
  445. [DllImport("pq")]
  446. public static extern IntPtr PQexec (IntPtr conn,
  447. string query);
  448. // PGresult *PQexec(PGconn *conn,
  449. // const char *query);
  450. [DllImport("pq")]
  451. public static extern IntPtr PQnotifies (IntPtr conn);
  452. // PGnotify *PQnotifies(PGconn *conn);
  453. [DllImport("pq")]
  454. public static extern void PQfreeNotify (IntPtr notify);
  455. // void PQfreeNotify(PGnotify *notify);
  456. [DllImport("pq")]
  457. public static extern int PQsendQuery (IntPtr conn,
  458. string query);
  459. // int PQsendQuery(PGconn *conn,
  460. // const char *query);
  461. [DllImport("pq")]
  462. public static extern IntPtr PQgetResult (IntPtr conn);
  463. // PGresult *PQgetResult(PGconn *conn);
  464. [DllImport("pq")]
  465. public static extern int PQisBusy (IntPtr conn);
  466. // int PQisBusy(PGconn *conn);
  467. [DllImport("pq")]
  468. public static extern int PQconsumeInput (IntPtr conn);
  469. // int PQconsumeInput(PGconn *conn);
  470. [DllImport("pq")]
  471. public static extern int PQgetline (IntPtr conn,
  472. string str, int length);
  473. // int PQgetline(PGconn *conn,
  474. // char *string, int length);
  475. [DllImport("pq")]
  476. public static extern int PQputline (IntPtr conn,
  477. string str);
  478. // int PQputline(PGconn *conn,
  479. // const char *string);
  480. [DllImport("pq")]
  481. public static extern int PQgetlineAsync (IntPtr conn,
  482. string buffer, int bufsize);
  483. // int PQgetlineAsync(PGconn *conn, char *buffer,
  484. // int bufsize);
  485. [DllImport("pq")]
  486. public static extern int PQputnbytes (IntPtr conn,
  487. string buffer, int nbytes);
  488. // int PQputnbytes(PGconn *conn,
  489. //const char *buffer, int nbytes);
  490. [DllImport("pq")]
  491. public static extern int PQendcopy (IntPtr conn);
  492. // int PQendcopy(PGconn *conn);
  493. [DllImport("pq")]
  494. public static extern int PQsetnonblocking (IntPtr conn,
  495. int arg);
  496. // int PQsetnonblocking(PGconn *conn, int arg);
  497. [DllImport("pq")]
  498. public static extern int PQisnonblocking (IntPtr conn);
  499. // int PQisnonblocking(const PGconn *conn);
  500. [DllImport("pq")]
  501. public static extern int PQflush (IntPtr conn);
  502. // int PQflush(PGconn *conn);
  503. [DllImport("pq")]
  504. public static extern IntPtr PQfn (IntPtr conn, int fnid,
  505. IntPtr result_buf, IntPtr result_len,
  506. int result_is_int, IntPtr args,
  507. int nargs);
  508. // PGresult *PQfn(PGconn *conn, int fnid,
  509. // int *result_buf, int *result_len,
  510. // int result_is_int, const PQArgBlock *args,
  511. // int nargs);
  512. [DllImport("pq")]
  513. public static extern ExecStatusType PQresultStatus (IntPtr res);
  514. // ExecStatusType PQresultStatus(const PGresult *res);
  515. [DllImport("pq")]
  516. public static extern string PQresStatus (ExecStatusType status);
  517. // char *PQresStatus(ExecStatusType status);
  518. [DllImport("pq")]
  519. public static extern string PQresultErrorMessage (IntPtr res);
  520. // char *PQresultErrorMessage(const PGresult *res);
  521. [DllImport("pq")]
  522. public static extern int PQntuples (IntPtr res);
  523. // int PQntuples(const PGresult *res);
  524. [DllImport("pq")]
  525. public static extern int PQnfields (IntPtr res);
  526. // int PQnfields(const PGresult *res);
  527. [DllImport("pq")]
  528. public static extern int PQbinaryTuples (IntPtr res);
  529. // int PQbinaryTuples(const PGresult *res);
  530. [DllImport("pq")]
  531. public static extern string PQfname (IntPtr res,
  532. int field_num);
  533. // char *PQfname(const PGresult *res,
  534. // int field_num);
  535. [DllImport("pq")]
  536. public static extern int PQfnumber (IntPtr res,
  537. string field_name);
  538. // int PQfnumber(const PGresult *res,
  539. // const char *field_name);
  540. [DllImport("pq")]
  541. public static extern int PQftype (IntPtr res,
  542. int field_num);
  543. // Oid PQftype(const PGresult *res,
  544. // int field_num);
  545. [DllImport("pq")]
  546. public static extern int PQfsize (IntPtr res,
  547. int field_num);
  548. // int PQfsize(const PGresult *res,
  549. // int field_num);
  550. [DllImport("pq")]
  551. public static extern int PQfmod (IntPtr res, int field_num);
  552. // int PQfmod(const PGresult *res, int field_num);
  553. [DllImport("pq")]
  554. public static extern string PQcmdStatus (IntPtr res);
  555. // char *PQcmdStatus(PGresult *res);
  556. [DllImport("pq")]
  557. public static extern string PQoidStatus (IntPtr res);
  558. // char *PQoidStatus(const PGresult *res);
  559. [DllImport("pq")]
  560. public static extern int PQoidValue (IntPtr res);
  561. // Oid PQoidValue(const PGresult *res);
  562. [DllImport("pq")]
  563. public static extern string PQcmdTuples (IntPtr res);
  564. // char *PQcmdTuples(PGresult *res);
  565. [DllImport("pq")]
  566. public static extern string PQgetvalue (IntPtr res,
  567. int tup_num, int field_num);
  568. // char *PQgetvalue(const PGresult *res,
  569. // int tup_num, int field_num);
  570. [DllImport("pq")]
  571. public static extern int PQgetlength (IntPtr res,
  572. int tup_num, int field_num);
  573. // int PQgetlength(const PGresult *res,
  574. // int tup_num, int field_num);
  575. [DllImport("pq")]
  576. public static extern int PQgetisnull (IntPtr res,
  577. int tup_num, int field_num);
  578. // int PQgetisnull(const PGresult *res,
  579. // int tup_num, int field_num);
  580. [DllImport("pq")]
  581. public static extern void PQclear (IntPtr res);
  582. // void PQclear(PGresult *res);
  583. [DllImport("pq")]
  584. public static extern IntPtr PQmakeEmptyPGresult (IntPtr conn,
  585. IntPtr status);
  586. // PGresult *PQmakeEmptyPGresult(PGconn *conn,
  587. // ExecStatusType status);
  588. [DllImport("pq")]
  589. public static extern void PQprint (IntPtr fout,
  590. IntPtr res, IntPtr ps);
  591. // void PQprint(FILE *fout,
  592. // const PGresult *res, const PQprintOpt *ps);
  593. [DllImport("pq")]
  594. public static extern void PQdisplayTuples (IntPtr res,
  595. IntPtr fp, int fillAlign, string fieldSep,
  596. int printHeader, int quiet);
  597. // void PQdisplayTuples(const PGresult *res,
  598. // FILE *fp, int fillAlign, const char *fieldSep,
  599. // int printHeader, int quiet);
  600. [DllImport("pq")]
  601. public static extern void PQprintTuples (IntPtr res,
  602. IntPtr fout, int printAttName, int terseOutput,
  603. int width);
  604. // void PQprintTuples(const PGresult *res,
  605. // FILE *fout, int printAttName, int terseOutput,
  606. // int width);
  607. [DllImport("pq")]
  608. public static extern int lo_open (IntPtr conn,
  609. int lobjId, int mode);
  610. // int lo_open(PGconn *conn,
  611. // Oid lobjId, int mode);
  612. [DllImport("pq")]
  613. public static extern int lo_close (IntPtr conn, int fd);
  614. // int lo_close(PGconn *conn, int fd);
  615. [DllImport("pq")]
  616. public static extern int lo_read (IntPtr conn,
  617. int fd, string buf, int len);
  618. // int lo_read(PGconn *conn,
  619. // int fd, char *buf, size_t len);
  620. [DllImport("pq")]
  621. public static extern int lo_write (IntPtr conn,
  622. int fd, string buf, int len);
  623. // int lo_write(PGconn *conn,
  624. // int fd, char *buf, size_t len);
  625. [DllImport("pq")]
  626. public static extern int lo_lseek (IntPtr conn,
  627. int fd, int offset, int whence);
  628. // int lo_lseek(PGconn *conn,
  629. // int fd, int offset, int whence);
  630. [DllImport("pq")]
  631. public static extern int lo_creat (IntPtr conn,
  632. int mode);
  633. // Oid lo_creat(PGconn *conn,
  634. // int mode);
  635. [DllImport("pq")]
  636. public static extern int lo_tell (IntPtr conn, int fd);
  637. // int lo_tell(PGconn *conn, int fd);
  638. [DllImport("pq")]
  639. public static extern int lo_unlink (IntPtr conn,
  640. int lobjId);
  641. // int lo_unlink(PGconn *conn,
  642. // Oid lobjId);
  643. [DllImport("pq")]
  644. public static extern int lo_import (IntPtr conn,
  645. string filename);
  646. // Oid lo_import(PGconn *conn,
  647. // const char *filename);
  648. [DllImport("pq")]
  649. public static extern int lo_export (IntPtr conn,
  650. int lobjId, string filename);
  651. // int lo_export(PGconn *conn,
  652. // Oid lobjId, const char *filename);
  653. [DllImport("pq")]
  654. public static extern int PQmblen (string s,
  655. int encoding);
  656. // int PQmblen(const unsigned char *s,
  657. // int encoding);
  658. [DllImport("pq")]
  659. public static extern int PQenv2encoding ();
  660. // int PQenv2encoding(void);
  661. #endregion
  662. }
  663. }