(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.Data.PostgreSqlClient / Mono.Data.PostgreSqlClient / PostgresLibrary.cs
blob9a068794a334f9a5b8d8365d3175a6e4a4210656
1 //
2 // Mono.Data.PostgreSqlClient.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 (rodrigo@ximian.com)
12 // Daniel Morgan (danmorg@sc.rr.com)
14 // (C) Ximian, Inc 2002
18 // Permission is hereby granted, free of charge, to any person obtaining
19 // a copy of this software and associated documentation files (the
20 // "Software"), to deal in the Software without restriction, including
21 // without limitation the rights to use, copy, modify, merge, publish,
22 // distribute, sublicense, and/or sell copies of the Software, and to
23 // permit persons to whom the Software is furnished to do so, subject to
24 // the following conditions:
25 //
26 // The above copyright notice and this permission notice shall be
27 // included in all copies or substantial portions of the Software.
28 //
29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 // *** uncomment #define to get debug messages, comment for production ***
39 //#define DEBUG_PostgresLibrary
41 using System;
42 using System.Data;
43 using System.Runtime.InteropServices;
44 using System.Diagnostics;
45 using System.Collections;
47 namespace Mono.Data.PostgreSqlClient {
49 /* IMPORTANT: DO NOT CHANGE ANY OF THESE ENUMS BELOW */
51 internal enum ConnStatusType
53 CONNECTION_OK,
54 CONNECTION_BAD,
55 CONNECTION_STARTED,
56 CONNECTION_MADE,
57 CONNECTION_AWAITING_RESPONSE,
58 CONNECTION_AUTH_OK,
59 CONNECTION_SETENV
62 internal enum PostgresPollingStatusType
64 PGRES_POLLING_FAILED = 0,
65 PGRES_POLLING_READING,
66 PGRES_POLLING_WRITING,
67 PGRES_POLLING_OK,
68 PGRES_POLLING_ACTIVE
71 internal enum ExecStatusType
73 PGRES_EMPTY_QUERY = 0,
74 PGRES_COMMAND_OK,
75 PGRES_TUPLES_OK,
76 PGRES_COPY_OUT,
77 PGRES_COPY_IN,
78 PGRES_BAD_RESPONSE,
79 PGRES_NONFATAL_ERROR,
80 PGRES_FATAL_ERROR
83 sealed internal class PostgresLibrary
85 #region PInvoke Functions
87 // pinvoke prototypes to PostgreSQL client library
88 // pq.dll on windows and libpq.so on linux
90 [DllImport("pq")]
91 public static extern IntPtr PQconnectStart (string conninfo);
92 // PGconn *PQconnectStart(const char *conninfo);
94 [DllImport("pq")]
95 public static extern PostgresPollingStatusType PQconnectPoll (IntPtr conn);
96 // PostgresPollingStatusType PQconnectPoll(PGconn *conn);
98 [DllImport("pq")]
99 public static extern IntPtr PQconnectdb (string conninfo);
100 // PGconn *PQconnectdb(const char *conninfo);
102 [DllImport("pq")]
103 public static extern IntPtr PQsetdbLogin (string pghost,
104 string pgport, string pgoptions,
105 string pgtty, string dbName,
106 string login, string pwd);
107 // PGconn *PQsetdbLogin(const char *pghost,
108 // const char *pgport, const char *pgoptions,
109 // const char *pgtty, const char *dbName,
110 // const char *login, const char *pwd);
112 [DllImport("pq")]
113 public static extern void PQfinish (IntPtr conn);
114 // void PQfinish(PGconn *conn);
116 [DllImport("pq")]
117 public static extern IntPtr PQconndefaults ();
118 // PQconninfoOption *PQconndefaults(void);
120 [DllImport("pq")]
121 public static extern void PQconninfoFree (IntPtr connOptions);
122 // void PQconninfoFree(PQconninfoOption *connOptions);
124 [DllImport("pq")]
125 public static extern int PQresetStart (IntPtr conn);
126 // int PQresetStart(PGconn *conn);
128 [DllImport("pq")]
129 public static extern IntPtr PQresetPoll (IntPtr conn);
130 // PostgresPollingStatusType PQresetPoll(PGconn *conn);
132 [DllImport("pq")]
133 public static extern void PQreset (IntPtr conn);
134 // void PQreset(PGconn *conn);
136 [DllImport("pq")]
137 public static extern int PQrequestCancel (IntPtr conn);
138 // int PQrequestCancel(PGconn *conn);
140 [DllImport("pq")]
141 public static extern string PQdb (IntPtr conn);
142 // char *PQdb(const PGconn *conn);
144 [DllImport("pq")]
145 public static extern string PQuser (IntPtr conn);
146 // char *PQuser(const PGconn *conn);
148 [DllImport("pq")]
149 public static extern string PQpass (IntPtr conn);
150 // char *PQpass(const PGconn *conn);
152 [DllImport("pq")]
153 public static extern string PQhost (IntPtr conn);
154 // char *PQhost(const PGconn *conn);
156 [DllImport("pq")]
157 public static extern string PQport (IntPtr conn);
158 // char *PQport(const PGconn *conn);
160 [DllImport("pq")]
161 public static extern string PQtty (IntPtr conn);
162 // char *PQtty(const PGconn *conn);
164 [DllImport("pq")]
165 public static extern string PQoptions (IntPtr conn);
166 // char *PQoptions(const PGconn *conn);
168 [DllImport("pq")]
169 public static extern ConnStatusType PQstatus (IntPtr conn);
170 // ConnStatusType PQstatus(const PGconn *conn);
172 [DllImport("pq")]
173 public static extern string PQerrorMessage (IntPtr conn);
174 // char *PQerrorMessage(const PGconn *conn);
176 [DllImport("pq")]
177 public static extern int PQsocket (IntPtr conn);
178 // int PQsocket(const PGconn *conn);
180 [DllImport("pq")]
181 public static extern int PQbackendPID (IntPtr conn);
182 // int PQbackendPID(const PGconn *conn);
184 [DllImport("pq")]
185 public static extern int PQclientEncoding (IntPtr conn);
186 // int PQclientEncoding(const PGconn *conn);
188 [DllImport("pq")]
189 public static extern int PQsetClientEncoding (IntPtr conn,
190 string encoding);
191 // int PQsetClientEncoding(PGconn *conn,
192 // const char *encoding);
194 //FIXME: when loading, causes runtime exception
195 //[DllImport("pq")]
196 //public static extern IntPtr PQgetssl (IntPtr conn);
197 // SSL *PQgetssl(PGconn *conn);
199 [DllImport("pq")]
200 public static extern void PQtrace (IntPtr conn,
201 IntPtr debug_port);
202 // void PQtrace(PGconn *conn,
203 // FILE *debug_port);
205 [DllImport("pq")]
206 public static extern void PQuntrace (IntPtr conn);
207 // void PQuntrace(PGconn *conn);
209 [DllImport("pq")]
210 public static extern IntPtr PQsetNoticeProcessor (IntPtr conn,
211 IntPtr proc, IntPtr arg);
212 // PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
213 // PQnoticeProcessor proc, void *arg);
215 [DllImport("pq")]
216 public static extern uint PQescapeString (out string to,
217 string from, uint length);
218 // size_t PQescapeString(char *to,
219 // const char *from, size_t length);
221 [DllImport("pq")]
222 public static extern byte[] PQescapeBytea (byte[] bintext,
223 uint binlen, uint bytealen);
224 // unsigned char *PQescapeBytea(unsigned char *bintext,
225 // size_t binlen, size_t *bytealen);
227 [DllImport("pq")]
228 public static extern IntPtr PQexec (IntPtr conn,
229 string query);
230 // PGresult *PQexec(PGconn *conn,
231 // const char *query);
233 [DllImport("pq")]
234 public static extern IntPtr PQnotifies (IntPtr conn);
235 // PGnotify *PQnotifies(PGconn *conn);
237 [DllImport("pq")]
238 public static extern void PQfreeNotify (IntPtr notify);
239 // void PQfreeNotify(PGnotify *notify);
241 [DllImport("pq")]
242 public static extern int PQsendQuery (IntPtr conn,
243 string query);
244 // int PQsendQuery(PGconn *conn,
245 // const char *query);
247 [DllImport("pq")]
248 public static extern IntPtr PQgetResult (IntPtr conn);
249 // PGresult *PQgetResult(PGconn *conn);
251 [DllImport("pq")]
252 public static extern int PQisBusy (IntPtr conn);
253 // int PQisBusy(PGconn *conn);
255 [DllImport("pq")]
256 public static extern int PQconsumeInput (IntPtr conn);
257 // int PQconsumeInput(PGconn *conn);
259 [DllImport("pq")]
260 public static extern int PQgetline (IntPtr conn,
261 string str, int length);
262 // int PQgetline(PGconn *conn,
263 // char *string, int length);
265 [DllImport("pq")]
266 public static extern int PQputline (IntPtr conn,
267 string str);
268 // int PQputline(PGconn *conn,
269 // const char *string);
271 [DllImport("pq")]
272 public static extern int PQgetlineAsync (IntPtr conn,
273 string buffer, int bufsize);
274 // int PQgetlineAsync(PGconn *conn, char *buffer,
275 // int bufsize);
277 [DllImport("pq")]
278 public static extern int PQputnbytes (IntPtr conn,
279 string buffer, int nbytes);
280 // int PQputnbytes(PGconn *conn,
281 //const char *buffer, int nbytes);
283 [DllImport("pq")]
284 public static extern int PQendcopy (IntPtr conn);
285 // int PQendcopy(PGconn *conn);
287 [DllImport("pq")]
288 public static extern int PQsetnonblocking (IntPtr conn,
289 int arg);
290 // int PQsetnonblocking(PGconn *conn, int arg);
292 [DllImport("pq")]
293 public static extern int PQisnonblocking (IntPtr conn);
294 // int PQisnonblocking(const PGconn *conn);
296 [DllImport("pq")]
297 public static extern int PQflush (IntPtr conn);
298 // int PQflush(PGconn *conn);
300 [DllImport("pq")]
301 public static extern IntPtr PQfn (IntPtr conn, int fnid,
302 IntPtr result_buf, IntPtr result_len,
303 int result_is_int, IntPtr args,
304 int nargs);
305 // PGresult *PQfn(PGconn *conn, int fnid,
306 // int *result_buf, int *result_len,
307 // int result_is_int, const PQArgBlock *args,
308 // int nargs);
310 [DllImport("pq")]
311 public static extern ExecStatusType PQresultStatus (IntPtr res);
312 // ExecStatusType PQresultStatus(const PGresult *res);
314 [DllImport("pq")]
315 public static extern string PQresStatus (ExecStatusType status);
316 // char *PQresStatus(ExecStatusType status);
318 [DllImport("pq")]
319 public static extern string PQresultErrorMessage (IntPtr res);
320 // char *PQresultErrorMessage(const PGresult *res);
322 [DllImport("pq")]
323 public static extern int PQntuples (IntPtr res);
324 // int PQntuples(const PGresult *res);
326 [DllImport("pq")]
327 public static extern int PQnfields (IntPtr res);
328 // int PQnfields(const PGresult *res);
330 [DllImport("pq")]
331 public static extern int PQbinaryTuples (IntPtr res);
332 // int PQbinaryTuples(const PGresult *res);
334 [DllImport("pq")]
335 public static extern string PQfname (IntPtr res,
336 int field_num);
337 // char *PQfname(const PGresult *res,
338 // int field_num);
340 [DllImport("pq")]
341 public static extern int PQfnumber (IntPtr res,
342 string field_name);
343 // int PQfnumber(const PGresult *res,
344 // const char *field_name);
346 [DllImport("pq")]
347 public static extern int PQftype (IntPtr res,
348 int field_num);
349 // Oid PQftype(const PGresult *res,
350 // int field_num);
352 [DllImport("pq")]
353 public static extern int PQfsize (IntPtr res,
354 int field_num);
355 // int PQfsize(const PGresult *res,
356 // int field_num);
358 [DllImport("pq")]
359 public static extern int PQfmod (IntPtr res, int field_num);
360 // int PQfmod(const PGresult *res, int field_num);
362 [DllImport("pq")]
363 public static extern string PQcmdStatus (IntPtr res);
364 // char *PQcmdStatus(PGresult *res);
366 [DllImport("pq")]
367 public static extern string PQoidStatus (IntPtr res);
368 // char *PQoidStatus(const PGresult *res);
370 [DllImport("pq")]
371 public static extern int PQoidValue (IntPtr res);
372 // Oid PQoidValue(const PGresult *res);
374 [DllImport("pq")]
375 public static extern string PQcmdTuples (IntPtr res);
376 // char *PQcmdTuples(PGresult *res);
378 [DllImport("pq")]
379 public static extern string PQgetvalue (IntPtr res,
380 int tup_num, int field_num);
381 // char *PQgetvalue(const PGresult *res,
382 // int tup_num, int field_num);
384 [DllImport("pq")]
385 public static extern int PQgetlength (IntPtr res,
386 int tup_num, int field_num);
387 // int PQgetlength(const PGresult *res,
388 // int tup_num, int field_num);
390 [DllImport("pq")]
391 public static extern int PQgetisnull (IntPtr res,
392 int tup_num, int field_num);
393 // int PQgetisnull(const PGresult *res,
394 // int tup_num, int field_num);
396 [DllImport("pq")]
397 public static extern void PQclear (IntPtr res);
398 // void PQclear(PGresult *res);
400 [DllImport("pq")]
401 public static extern IntPtr PQmakeEmptyPGresult (IntPtr conn,
402 IntPtr status);
403 // PGresult *PQmakeEmptyPGresult(PGconn *conn,
404 // ExecStatusType status);
406 [DllImport("pq")]
407 public static extern void PQprint (IntPtr fout,
408 IntPtr res, IntPtr ps);
409 // void PQprint(FILE *fout,
410 // const PGresult *res, const PQprintOpt *ps);
412 [DllImport("pq")]
413 public static extern void PQdisplayTuples (IntPtr res,
414 IntPtr fp, int fillAlign, string fieldSep,
415 int printHeader, int quiet);
416 // void PQdisplayTuples(const PGresult *res,
417 // FILE *fp, int fillAlign, const char *fieldSep,
418 // int printHeader, int quiet);
420 [DllImport("pq")]
421 public static extern void PQprintTuples (IntPtr res,
422 IntPtr fout, int printAttName, int terseOutput,
423 int width);
424 // void PQprintTuples(const PGresult *res,
425 // FILE *fout, int printAttName, int terseOutput,
426 // int width);
428 [DllImport("pq")]
429 public static extern int lo_open (IntPtr conn,
430 int lobjId, int mode);
431 // int lo_open(PGconn *conn,
432 // Oid lobjId, int mode);
434 [DllImport("pq")]
435 public static extern int lo_close (IntPtr conn, int fd);
436 // int lo_close(PGconn *conn, int fd);
438 [DllImport("pq")]
439 public static extern int lo_read (IntPtr conn,
440 int fd, string buf, int len);
441 // int lo_read(PGconn *conn,
442 // int fd, char *buf, size_t len);
444 [DllImport("pq")]
445 public static extern int lo_write (IntPtr conn,
446 int fd, string buf, int len);
447 // int lo_write(PGconn *conn,
448 // int fd, char *buf, size_t len);
450 [DllImport("pq")]
451 public static extern int lo_lseek (IntPtr conn,
452 int fd, int offset, int whence);
453 // int lo_lseek(PGconn *conn,
454 // int fd, int offset, int whence);
456 [DllImport("pq")]
457 public static extern int lo_creat (IntPtr conn,
458 int mode);
459 // Oid lo_creat(PGconn *conn,
460 // int mode);
462 [DllImport("pq")]
463 public static extern int lo_tell (IntPtr conn, int fd);
464 // int lo_tell(PGconn *conn, int fd);
466 [DllImport("pq")]
467 public static extern int lo_unlink (IntPtr conn,
468 int lobjId);
469 // int lo_unlink(PGconn *conn,
470 // Oid lobjId);
472 [DllImport("pq")]
473 public static extern int lo_import (IntPtr conn,
474 string filename);
475 // Oid lo_import(PGconn *conn,
476 // const char *filename);
478 [DllImport("pq")]
479 public static extern int lo_export (IntPtr conn,
480 int lobjId, string filename);
481 // int lo_export(PGconn *conn,
482 // Oid lobjId, const char *filename);
484 [DllImport("pq")]
485 public static extern int PQmblen (string s,
486 int encoding);
487 // int PQmblen(const unsigned char *s,
488 // int encoding);
490 [DllImport("pq")]
491 public static extern int PQenv2encoding ();
492 // int PQenv2encoding(void);
494 #endregion