PostgresLibrary.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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. if(value == null) {
  195. //Console.WriteLine("ConvertDbTypeToSystemDbType typ: " +
  196. // typ + " value is null");
  197. return null;
  198. }
  199. else if(value.Equals("")) {
  200. //Console.WriteLine("ConvertDbTypeToSystemDbType typ: " +
  201. // typ + " value is string empty");
  202. return null;
  203. }
  204. //Console.WriteLine("ConvertDbTypeToSystemDbType typ: " +
  205. // typ + " value: " + value);
  206. // Date, Time, and DateTime
  207. // are parsed based on ISO format
  208. // "YYYY-MM-DD hh:mi:ss.ms"
  209. switch(typ) {
  210. case DbType.String:
  211. obj = String.Copy(value);
  212. break;
  213. case DbType.Boolean:
  214. obj = value.Equals("t");
  215. break;
  216. case DbType.Int16:
  217. obj = Int16.Parse(value);
  218. break;
  219. case DbType.Int32:
  220. obj = Int32.Parse(value);
  221. break;
  222. case DbType.Int64:
  223. obj = Int64.Parse(value);
  224. break;
  225. case DbType.Decimal:
  226. obj = Decimal.Parse(value);
  227. break;
  228. case DbType.Single:
  229. obj = Single.Parse(value);
  230. break;
  231. case DbType.Double:
  232. obj = Double.Parse(value);
  233. break;
  234. case DbType.Date:
  235. String[] sd = value.Split(new Char[] {'-'});
  236. obj = new DateTime(
  237. Int32.Parse(sd[0]), Int32.Parse(sd[1]), Int32.Parse(sd[2]),
  238. 0,0,0);
  239. break;
  240. case DbType.Time:
  241. String[] st = value.Split(new Char[] {':'});
  242. obj = new DateTime(0001,01,01,
  243. Int32.Parse(st[0]),Int32.Parse(st[1]),Int32.Parse(st[2]));
  244. break;
  245. case DbType.DateTime:
  246. Int32 YYYY,MM,DD,hh,mi,ss,ms;
  247. YYYY = Int32.Parse(value.Substring(0,4));
  248. MM = Int32.Parse(value.Substring(5,2));
  249. DD = Int32.Parse(value.Substring(8,2));
  250. hh = Int32.Parse(value.Substring(11,2));
  251. mi = Int32.Parse(value.Substring(14,2));
  252. ss = Int32.Parse(value.Substring(17,2));
  253. ms = Int32.Parse(value.Substring(20,2));
  254. obj = new DateTime(YYYY,MM,DD,hh,mi,ss,ms);
  255. break;
  256. default:
  257. obj = String.Copy(value);
  258. break;
  259. }
  260. return obj;
  261. }
  262. // Translates System.Data.DbType to System.Type
  263. public static Type DbTypeToSystemType (DbType dType) {
  264. // FIXME: more types need
  265. // to be mapped
  266. // from PostgreSQL oid type
  267. // to .NET System.<type>
  268. Type typ = null;
  269. switch(dType) {
  270. case DbType.String:
  271. typ = typeof(String);
  272. break;
  273. case DbType.Boolean:
  274. typ = typeof(Boolean);
  275. break;
  276. case DbType.Int16:
  277. typ = typeof(Int16);
  278. break;
  279. case DbType.Int32:
  280. typ = typeof(Int32);
  281. break;
  282. case DbType.Int64:
  283. typ = typeof(Int64);
  284. break;
  285. case DbType.Decimal:
  286. typ = typeof(Decimal);
  287. break;
  288. case DbType.Single:
  289. typ = typeof(Single);
  290. break;
  291. case DbType.Double:
  292. typ = typeof(Double);
  293. break;
  294. case DbType.Date:
  295. case DbType.Time:
  296. case DbType.DateTime:
  297. typ = typeof(DateTime);
  298. break;
  299. default:
  300. typ = typeof(String);
  301. break;
  302. }
  303. return typ;
  304. }
  305. // Find DbType for oid
  306. // which requires a look up of PostgresTypes
  307. // DbType <-> typname <-> oid
  308. public static string OidToTypname (int oid, ArrayList pgTypes) {
  309. // FIXME: more types need
  310. // to be mapped
  311. // from PostgreSQL oid type
  312. // to .NET System.<type>
  313. string typname = "text"; // default
  314. int i;
  315. for(i = 0; i < pgTypes.Count; i++) {
  316. PostgresType pt = (PostgresType) pgTypes[i];
  317. if(pt.oid == oid) {
  318. typname = pt.typname;
  319. break;
  320. }
  321. }
  322. return typname;
  323. }
  324. }
  325. sealed internal class PostgresLibrary
  326. {
  327. #region PInvoke Functions
  328. // pinvoke prototypes to PostgreSQL client library
  329. // pq.dll on windows and libpq.so on linux
  330. [DllImport("pq")]
  331. public static extern IntPtr PQconnectStart (string conninfo);
  332. // PGconn *PQconnectStart(const char *conninfo);
  333. [DllImport("pq")]
  334. public static extern PostgresPollingStatusType PQconnectPoll (IntPtr conn);
  335. // PostgresPollingStatusType PQconnectPoll(PGconn *conn);
  336. [DllImport("pq")]
  337. public static extern IntPtr PQconnectdb (string conninfo);
  338. // PGconn *PQconnectdb(const char *conninfo);
  339. [DllImport("pq")]
  340. public static extern IntPtr PQsetdbLogin (string pghost,
  341. string pgport, string pgoptions,
  342. string pgtty, string dbName,
  343. string login, string pwd);
  344. // PGconn *PQsetdbLogin(const char *pghost,
  345. // const char *pgport, const char *pgoptions,
  346. // const char *pgtty, const char *dbName,
  347. // const char *login, const char *pwd);
  348. [DllImport("pq")]
  349. public static extern void PQfinish (IntPtr conn);
  350. // void PQfinish(PGconn *conn);
  351. [DllImport("pq")]
  352. public static extern IntPtr PQconndefaults ();
  353. // PQconninfoOption *PQconndefaults(void);
  354. [DllImport("pq")]
  355. public static extern void PQconninfoFree (IntPtr connOptions);
  356. // void PQconninfoFree(PQconninfoOption *connOptions);
  357. [DllImport("pq")]
  358. public static extern int PQresetStart (IntPtr conn);
  359. // int PQresetStart(PGconn *conn);
  360. [DllImport("pq")]
  361. public static extern IntPtr PQresetPoll (IntPtr conn);
  362. // PostgresPollingStatusType PQresetPoll(PGconn *conn);
  363. [DllImport("pq")]
  364. public static extern void PQreset (IntPtr conn);
  365. // void PQreset(PGconn *conn);
  366. [DllImport("pq")]
  367. public static extern int PQrequestCancel (IntPtr conn);
  368. // int PQrequestCancel(PGconn *conn);
  369. [DllImport("pq")]
  370. public static extern string PQdb (IntPtr conn);
  371. // char *PQdb(const PGconn *conn);
  372. [DllImport("pq")]
  373. public static extern string PQuser (IntPtr conn);
  374. // char *PQuser(const PGconn *conn);
  375. [DllImport("pq")]
  376. public static extern string PQpass (IntPtr conn);
  377. // char *PQpass(const PGconn *conn);
  378. [DllImport("pq")]
  379. public static extern string PQhost (IntPtr conn);
  380. // char *PQhost(const PGconn *conn);
  381. [DllImport("pq")]
  382. public static extern string PQport (IntPtr conn);
  383. // char *PQport(const PGconn *conn);
  384. [DllImport("pq")]
  385. public static extern string PQtty (IntPtr conn);
  386. // char *PQtty(const PGconn *conn);
  387. [DllImport("pq")]
  388. public static extern string PQoptions (IntPtr conn);
  389. // char *PQoptions(const PGconn *conn);
  390. [DllImport("pq")]
  391. public static extern ConnStatusType PQstatus (IntPtr conn);
  392. // ConnStatusType PQstatus(const PGconn *conn);
  393. [DllImport("pq")]
  394. public static extern string PQerrorMessage (IntPtr conn);
  395. // char *PQerrorMessage(const PGconn *conn);
  396. [DllImport("pq")]
  397. public static extern int PQsocket (IntPtr conn);
  398. // int PQsocket(const PGconn *conn);
  399. [DllImport("pq")]
  400. public static extern int PQbackendPID (IntPtr conn);
  401. // int PQbackendPID(const PGconn *conn);
  402. [DllImport("pq")]
  403. public static extern int PQclientEncoding (IntPtr conn);
  404. // int PQclientEncoding(const PGconn *conn);
  405. [DllImport("pq")]
  406. public static extern int PQsetClientEncoding (IntPtr conn,
  407. string encoding);
  408. // int PQsetClientEncoding(PGconn *conn,
  409. // const char *encoding);
  410. //FIXME: when loading, causes runtime exception
  411. //[DllImport("pq")]
  412. //public static extern IntPtr PQgetssl (IntPtr conn);
  413. // SSL *PQgetssl(PGconn *conn);
  414. [DllImport("pq")]
  415. public static extern void PQtrace (IntPtr conn,
  416. IntPtr debug_port);
  417. // void PQtrace(PGconn *conn,
  418. // FILE *debug_port);
  419. [DllImport("pq")]
  420. public static extern void PQuntrace (IntPtr conn);
  421. // void PQuntrace(PGconn *conn);
  422. [DllImport("pq")]
  423. public static extern IntPtr PQsetNoticeProcessor (IntPtr conn,
  424. IntPtr proc, IntPtr arg);
  425. // PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
  426. // PQnoticeProcessor proc, void *arg);
  427. [DllImport("pq")]
  428. public static extern int PQescapeString (string to,
  429. string from, int length);
  430. // size_t PQescapeString(char *to,
  431. // const char *from, size_t length);
  432. [DllImport("pq")]
  433. public static extern string PQescapeBytea (string bintext,
  434. int binlen, IntPtr bytealen);
  435. // unsigned char *PQescapeBytea(unsigned char *bintext,
  436. // size_t binlen, size_t *bytealen);
  437. [DllImport("pq")]
  438. public static extern IntPtr PQexec (IntPtr conn,
  439. string query);
  440. // PGresult *PQexec(PGconn *conn,
  441. // const char *query);
  442. [DllImport("pq")]
  443. public static extern IntPtr PQnotifies (IntPtr conn);
  444. // PGnotify *PQnotifies(PGconn *conn);
  445. [DllImport("pq")]
  446. public static extern void PQfreeNotify (IntPtr notify);
  447. // void PQfreeNotify(PGnotify *notify);
  448. [DllImport("pq")]
  449. public static extern int PQsendQuery (IntPtr conn,
  450. string query);
  451. // int PQsendQuery(PGconn *conn,
  452. // const char *query);
  453. [DllImport("pq")]
  454. public static extern IntPtr PQgetResult (IntPtr conn);
  455. // PGresult *PQgetResult(PGconn *conn);
  456. [DllImport("pq")]
  457. public static extern int PQisBusy (IntPtr conn);
  458. // int PQisBusy(PGconn *conn);
  459. [DllImport("pq")]
  460. public static extern int PQconsumeInput (IntPtr conn);
  461. // int PQconsumeInput(PGconn *conn);
  462. [DllImport("pq")]
  463. public static extern int PQgetline (IntPtr conn,
  464. string str, int length);
  465. // int PQgetline(PGconn *conn,
  466. // char *string, int length);
  467. [DllImport("pq")]
  468. public static extern int PQputline (IntPtr conn,
  469. string str);
  470. // int PQputline(PGconn *conn,
  471. // const char *string);
  472. [DllImport("pq")]
  473. public static extern int PQgetlineAsync (IntPtr conn,
  474. string buffer, int bufsize);
  475. // int PQgetlineAsync(PGconn *conn, char *buffer,
  476. // int bufsize);
  477. [DllImport("pq")]
  478. public static extern int PQputnbytes (IntPtr conn,
  479. string buffer, int nbytes);
  480. // int PQputnbytes(PGconn *conn,
  481. //const char *buffer, int nbytes);
  482. [DllImport("pq")]
  483. public static extern int PQendcopy (IntPtr conn);
  484. // int PQendcopy(PGconn *conn);
  485. [DllImport("pq")]
  486. public static extern int PQsetnonblocking (IntPtr conn,
  487. int arg);
  488. // int PQsetnonblocking(PGconn *conn, int arg);
  489. [DllImport("pq")]
  490. public static extern int PQisnonblocking (IntPtr conn);
  491. // int PQisnonblocking(const PGconn *conn);
  492. [DllImport("pq")]
  493. public static extern int PQflush (IntPtr conn);
  494. // int PQflush(PGconn *conn);
  495. [DllImport("pq")]
  496. public static extern IntPtr PQfn (IntPtr conn, int fnid,
  497. IntPtr result_buf, IntPtr result_len,
  498. int result_is_int, IntPtr args,
  499. int nargs);
  500. // PGresult *PQfn(PGconn *conn, int fnid,
  501. // int *result_buf, int *result_len,
  502. // int result_is_int, const PQArgBlock *args,
  503. // int nargs);
  504. [DllImport("pq")]
  505. public static extern ExecStatusType PQresultStatus (IntPtr res);
  506. // ExecStatusType PQresultStatus(const PGresult *res);
  507. [DllImport("pq")]
  508. public static extern string PQresStatus (ExecStatusType status);
  509. // char *PQresStatus(ExecStatusType status);
  510. [DllImport("pq")]
  511. public static extern string PQresultErrorMessage (IntPtr res);
  512. // char *PQresultErrorMessage(const PGresult *res);
  513. [DllImport("pq")]
  514. public static extern int PQntuples (IntPtr res);
  515. // int PQntuples(const PGresult *res);
  516. [DllImport("pq")]
  517. public static extern int PQnfields (IntPtr res);
  518. // int PQnfields(const PGresult *res);
  519. [DllImport("pq")]
  520. public static extern int PQbinaryTuples (IntPtr res);
  521. // int PQbinaryTuples(const PGresult *res);
  522. [DllImport("pq")]
  523. public static extern string PQfname (IntPtr res,
  524. int field_num);
  525. // char *PQfname(const PGresult *res,
  526. // int field_num);
  527. [DllImport("pq")]
  528. public static extern int PQfnumber (IntPtr res,
  529. string field_name);
  530. // int PQfnumber(const PGresult *res,
  531. // const char *field_name);
  532. [DllImport("pq")]
  533. public static extern int PQftype (IntPtr res,
  534. int field_num);
  535. // Oid PQftype(const PGresult *res,
  536. // int field_num);
  537. [DllImport("pq")]
  538. public static extern int PQfsize (IntPtr res,
  539. int field_num);
  540. // int PQfsize(const PGresult *res,
  541. // int field_num);
  542. [DllImport("pq")]
  543. public static extern int PQfmod (IntPtr res, int field_num);
  544. // int PQfmod(const PGresult *res, int field_num);
  545. [DllImport("pq")]
  546. public static extern string PQcmdStatus (IntPtr res);
  547. // char *PQcmdStatus(PGresult *res);
  548. [DllImport("pq")]
  549. public static extern string PQoidStatus (IntPtr res);
  550. // char *PQoidStatus(const PGresult *res);
  551. [DllImport("pq")]
  552. public static extern int PQoidValue (IntPtr res);
  553. // Oid PQoidValue(const PGresult *res);
  554. [DllImport("pq")]
  555. public static extern string PQcmdTuples (IntPtr res);
  556. // char *PQcmdTuples(PGresult *res);
  557. [DllImport("pq")]
  558. public static extern string PQgetvalue (IntPtr res,
  559. int tup_num, int field_num);
  560. // char *PQgetvalue(const PGresult *res,
  561. // int tup_num, int field_num);
  562. [DllImport("pq")]
  563. public static extern int PQgetlength (IntPtr res,
  564. int tup_num, int field_num);
  565. // int PQgetlength(const PGresult *res,
  566. // int tup_num, int field_num);
  567. [DllImport("pq")]
  568. public static extern int PQgetisnull (IntPtr res,
  569. int tup_num, int field_num);
  570. // int PQgetisnull(const PGresult *res,
  571. // int tup_num, int field_num);
  572. [DllImport("pq")]
  573. public static extern void PQclear (IntPtr res);
  574. // void PQclear(PGresult *res);
  575. [DllImport("pq")]
  576. public static extern IntPtr PQmakeEmptyPGresult (IntPtr conn,
  577. IntPtr status);
  578. // PGresult *PQmakeEmptyPGresult(PGconn *conn,
  579. // ExecStatusType status);
  580. [DllImport("pq")]
  581. public static extern void PQprint (IntPtr fout,
  582. IntPtr res, IntPtr ps);
  583. // void PQprint(FILE *fout,
  584. // const PGresult *res, const PQprintOpt *ps);
  585. [DllImport("pq")]
  586. public static extern void PQdisplayTuples (IntPtr res,
  587. IntPtr fp, int fillAlign, string fieldSep,
  588. int printHeader, int quiet);
  589. // void PQdisplayTuples(const PGresult *res,
  590. // FILE *fp, int fillAlign, const char *fieldSep,
  591. // int printHeader, int quiet);
  592. [DllImport("pq")]
  593. public static extern void PQprintTuples (IntPtr res,
  594. IntPtr fout, int printAttName, int terseOutput,
  595. int width);
  596. // void PQprintTuples(const PGresult *res,
  597. // FILE *fout, int printAttName, int terseOutput,
  598. // int width);
  599. [DllImport("pq")]
  600. public static extern int lo_open (IntPtr conn,
  601. int lobjId, int mode);
  602. // int lo_open(PGconn *conn,
  603. // Oid lobjId, int mode);
  604. [DllImport("pq")]
  605. public static extern int lo_close (IntPtr conn, int fd);
  606. // int lo_close(PGconn *conn, int fd);
  607. [DllImport("pq")]
  608. public static extern int lo_read (IntPtr conn,
  609. int fd, string buf, int len);
  610. // int lo_read(PGconn *conn,
  611. // int fd, char *buf, size_t len);
  612. [DllImport("pq")]
  613. public static extern int lo_write (IntPtr conn,
  614. int fd, string buf, int len);
  615. // int lo_write(PGconn *conn,
  616. // int fd, char *buf, size_t len);
  617. [DllImport("pq")]
  618. public static extern int lo_lseek (IntPtr conn,
  619. int fd, int offset, int whence);
  620. // int lo_lseek(PGconn *conn,
  621. // int fd, int offset, int whence);
  622. [DllImport("pq")]
  623. public static extern int lo_creat (IntPtr conn,
  624. int mode);
  625. // Oid lo_creat(PGconn *conn,
  626. // int mode);
  627. [DllImport("pq")]
  628. public static extern int lo_tell (IntPtr conn, int fd);
  629. // int lo_tell(PGconn *conn, int fd);
  630. [DllImport("pq")]
  631. public static extern int lo_unlink (IntPtr conn,
  632. int lobjId);
  633. // int lo_unlink(PGconn *conn,
  634. // Oid lobjId);
  635. [DllImport("pq")]
  636. public static extern int lo_import (IntPtr conn,
  637. string filename);
  638. // Oid lo_import(PGconn *conn,
  639. // const char *filename);
  640. [DllImport("pq")]
  641. public static extern int lo_export (IntPtr conn,
  642. int lobjId, string filename);
  643. // int lo_export(PGconn *conn,
  644. // Oid lobjId, const char *filename);
  645. [DllImport("pq")]
  646. public static extern int PQmblen (string s,
  647. int encoding);
  648. // int PQmblen(const unsigned char *s,
  649. // int encoding);
  650. [DllImport("pq")]
  651. public static extern int PQenv2encoding ();
  652. // int PQenv2encoding(void);
  653. #endregion
  654. }
  655. }