3 * Copyright (C) 2009 Jukka-Pekka Iivonen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jukka-Pekka Iivonen <jp0409@jippii.fi>
24 [CCode (cprefix = "PQ", cheader_filename = "libpq-fe.h")]
26 [CCode (cprefix = "PQ", cheader_filename = "postgresql/libpq-fe.h")]
30 [CCode (cname = "ConnStatusType", cprefix = "CONNECTION_", has_type_id = false)]
31 public enum ConnectionStatus {
43 [CCode (cname = "PostgresPollingStatusType", cprefix = "PGRES_POLLING_", has_type_id = false)]
44 public enum PollingStatus {
52 [CCode (cname = "ExecStatusType", cprefix = "PGRES_", has_type_id = false)]
53 public enum ExecStatus {
64 [CCode (cname = "PGTransactionStatusType", cprefix = "PQTRANS_", has_type_id = false)]
65 public enum TransactionStatus {
73 [CCode (cname = "PGVerbosity", cprefix = "PQERRORS_", has_type_id = false)]
74 public enum Verbosity {
80 [CCode (cname = "int", cprefix = "PG_DIAG_", has_type_id = false)]
81 public enum FieldCode {
96 [CCode (cname = "PGPing", cprefix = "PQPING_", has_type_id = false)]
105 [CCode (cname = "PGnotify", free_function = "PQfreemem")]
106 public class Notify {
107 public string relname;
114 [CCode (cname = "PQnoticeReceiver")]
115 public delegate void NoticeReceiverFunc (void* arg, Result res);
117 [CCode (cname = "PQnoticeProcessor")]
118 public delegate void NoticeProcessorFunc (void* arg, string message);
120 [CCode (cname = "PQprintOpt", has_type_id = false)]
121 public struct PrintOpt {
124 public bool standard;
126 public bool expanded;
128 public string fieldSep;
129 public string tableOpt;
130 public string caption;
131 public string[] fieldName;
135 [CCode (cname = "PQconninfoOption", free_function = "PQconninfoFree")]
136 public class ConnectionOptions {
137 public string keyword;
138 public string envvar;
139 public string compiled;
142 public string dispchar;
146 [CCode (cname = "PQArgBlock", has_type_id = false)]
147 public struct ArgBlock {
153 [CCode (cname = "uint", default_value = "0U", type_signature = "u", has_type_id = false)]
157 [CCode (cname = "InvalidOid")]
158 public const uint InvalidOid;
160 [CCode (cname = "PQconnectStart")]
161 public Database connect_start (string conninfo);
163 [CCode (cname = "PQconnectdb")]
164 public Database connect_db (string conninfo);
166 [CCode (cname = "PQsetdbLogin")]
167 public Database set_db_login (string host, string port, string options, string gtty, string db_name, string login, string pwd);
169 [CCode (cname = "PQsetdb")]
170 public Database set_db (string host, string port, string options, string gtty, string db_name);
172 [CCode (cname = "PQconndefaults")]
173 public ConnectionOptions get_default_options ();
175 [CCode (cname = "PQinitSSL")]
176 public void init_ssl (int do_init);
178 [CCode (cname = "PQisthreadsafe")]
179 public int is_thread_safe ();
181 [CCode (cname = "PQresStatus")]
182 public unowned string result_status (ExecStatus status);
185 [CCode (free_function = "PQfreeCancel", cname = "PGcancel", cprefix = "PQ")]
186 public class Cancel {
187 [CCode (cname = "PQcancel")]
188 public bool cancel (char[] errbuf, int errbufsize);
191 /* Database Connection Handle */
193 [CCode (free_function = "PQfinish", cname = "PGconn", cprefix = "PQ")]
194 public class Database {
195 [CCode (cname = "PQconnectPoll")]
196 public PollingStatus connect_poll ();
198 [CCode (cname = "PQresetStart")]
199 public int reset_start ();
201 [CCode (cname = "PQresetPoll")]
202 public PollingStatus reset_poll ();
204 [CCode (cname = "PQreset")]
205 public void reset ();
207 [CCode (cname = "PQgetCancel")]
208 public Cancel get_cancel ();
210 [CCode (cname = "PQrequestCancel")]
211 public int request_cancel ();
213 [CCode (cname = "PQdb")]
214 public unowned string get_db ();
216 [CCode (cname = "PQuser")]
217 public unowned string get_user ();
219 [CCode (cname = "PQpass")]
220 public unowned string get_passwd ();
222 [CCode (cname = "PQhost")]
223 public unowned string get_host ();
225 [CCode (cname = "PQport")]
226 public unowned string get_port ();
228 [CCode (cname = "PQtty")]
229 public unowned string get_tty ();
231 [CCode (cname = "PQoptions")]
232 public unowned string get_options ();
234 [CCode (cname = "PQstatus")]
235 public ConnectionStatus get_status ();
237 [CCode (cname = "PQtransactionStatus")]
238 public TransactionStatus get_transaction_status ();
240 [CCode (cname = "PQparameterStatus")]
241 public unowned string get_parameter_status (string param_name);
243 [CCode (cname = "PQprotocolVersion")]
244 public int get_protocol_Version ();
246 [CCode (cname = "PQserverVersion")]
247 public int get_server_version ();
249 [CCode (cname = "PQerrorMessage")]
250 public unowned string get_error_message ();
252 [CCode (cname = "PQsocket")]
253 public int get_socket ();
255 [CCode (cname = "PQbackendPID")]
256 public int get_backend_pid ();
258 [CCode (cname = "PQconnectionNeedsPassword")]
259 public int connection_needs_password ();
261 [CCode (cname = "PQconnectionUsedPassword")]
262 public int connection_used_password ();
264 [CCode (cname = "PQclientEncoding")]
265 public int get_client_encoding ();
267 [CCode (cname = "PQsetClientEncoding")]
268 public int set_client_encoding (string encoding);
270 [CCode (cname = "PQgetssl")]
271 public void* get_ssl ();
273 [CCode (cname = "PQsetErrorVerbosity")]
274 public Verbosity set_error_verbosity (Verbosity verbosity);
276 [CCode (cname = "PQtrace")]
277 public void trace (GLib.FileStream debug_port);
279 [CCode (cname = "PQuntrace")]
280 public void untrace ();
282 [CCode (cname = "PQsetNoticeReceiver")]
283 public NoticeReceiverFunc set_notice_receiver (NoticeReceiverFunc proc_func, void* arg);
285 [CCode (cname = "PQsetNoticeProcessor")]
286 public NoticeProcessorFunc set_notice_processor (NoticeProcessorFunc proc_func, void* arg);
288 [CCode (cname = "PQexec")]
289 public Result exec (string query);
291 [CCode (cname = "PQexecParams")]
292 public Result exec_params (string command, int n_params, [CCode (array_length = false)] Oid[]? param_types, [CCode (array_length = false)] string[]? param_values, [CCode (array_length = false)] int[]? param_lengths, [CCode (array_length = false)] int[]? param_formats, int result_format);
294 [CCode (cname = "PQprepare")]
295 public Result prepare (string stmt_name, string query, [CCode (array_length_pos = 2.9)] Oid[]? param_types);
297 [CCode (cname = "PQexecPrepared")]
298 public Result exec_prepared (string stmt_name, int n_params, [CCode (array_length = false)] string[]? param_values, [CCode (array_length = false)] int[]? param_lengths, [CCode (array_length = false)] int[]? param_formats, int result_format);
300 [CCode (cname = "PQsendQuery")]
301 public int send_query (string query);
303 [CCode (cname = "PQsendQueryParams")]
304 public int send_query_params (string command, int n_params, [CCode (array_length = false)] Oid[]? param_types, [CCode (array_length = false)] string[]? param_values, [CCode (array_length = false)] int[]? param_lengths, [CCode (array_length = false)] int[]? param_formats, int result_format);
306 [CCode (cname = "PQsendPrepare")]
307 public int send_prepare (string stmt_name, string query, [CCode (array_length_pos = 2.9)] Oid[]? param_types);
309 [CCode (cname = "PQsendQueryPrepared")]
310 public int send_query_prepared (string stmt_name, int n_params, [CCode (array_length = false)] string[]? param_values, [CCode (array_length = false)] int[]? param_lengths, [CCode (array_length = false)] int[]? param_formats, int resultFormat);
312 [CCode (cname = "PQgetResult")]
313 public Result get_result ();
315 [CCode (cname = "PQisBusy")]
316 public int is_busy ();
318 [CCode (cname = "PQconsumeInput")]
319 public int consume_input ();
321 [CCode (cname = "PQnotifies")]
322 public Notify get_notifies ();
324 [CCode (cname = "PQputCopyData")]
325 public int put_copy_data (string buffer, int nbytes);
327 [CCode (cname = "PQputCopyEnd")]
328 public int put_copy_end (string error_msg);
330 [CCode (cname = "PQgetCopyData")]
331 public int get_copy_data (string[] buffer, int async);
333 [CCode (cname = "PQsetnonblocking")]
334 public int set_non_blocking (int arg);
336 [CCode (cname = "PQisnonblocking")]
337 public int is_non_blocking ();
339 [CCode (cname = "PQping")]
342 [CCode (cname = "PQpingParams")]
343 public Ping ping_params(string keywords, string values, int expand_dbname);
345 [CCode (cname = "PQflush")]
348 [CCode (cname = "PQfn")]
349 public Result fn (int fnid, int[] result_buf, out int result_len, int result_is_int, ArgBlock args, int nargs);
351 [CCode (cname = "PQdescribePrepared")]
352 public Result describe_prepared (string stmt);
354 [CCode (cname = "PQdescribePortal")]
355 public Result describe_portal (string portal);
357 [CCode (cname = "PQsendDescribePrepared")]
358 public int send_describe_prepared (string stmt);
360 [CCode (cname = "PQsendDescribePortal")]
361 public int send_describe_portal (string portal);
363 [CCode (cname = "PQmakeEmptyPGresult")]
364 public Result make_empty_result (ExecStatus status);
366 [CCode (cname = "PQescapeStringConn")]
367 public size_t escape_string_conn (string to, string from, size_t length, out int error);
369 [CCode (cname = "PQescapeByteaConn")]
370 public uchar[] escape_bytea_conn (string from, size_t from_length, out size_t to_length);
372 [CCode (cname = "lo_open")]
373 public int lo_open (int lobj_id, int mode);
375 [CCode (cname = "lo_close")]
376 public int lo_close (int fd);
378 [CCode (cname = "lo_read")]
379 public int lo_read (int fd, string buf, size_t len);
381 [CCode (cname = "lo_write")]
382 public int lo_write (int fd, string buf, size_t len);
384 [CCode (cname = "lo_lseek")]
385 public int lo_lseek (int fd, int offset, int whence);
387 [CCode (cname = "lo_creat")]
388 public int lo_creat (int mode);
390 [CCode (cname = "lo_create")]
391 public int lo_create (int lobj_id);
393 [CCode (cname = "lo_tell")]
394 public int lo_tell (int fd);
396 [CCode (cname = "lo_truncate")]
397 public int lo_truncate (int fd, size_t len);
399 [CCode (cname = "lo_unlink")]
400 public int lo_unlink (int lobj_id);
402 [CCode (cname = "lo_import")]
403 public int lo_import (string filename);
405 [CCode (cname = "lo_export")]
406 public int lo_export (int lobj_id, string filename);
409 [CCode (cname = "pgthreadlock_t")]
410 public delegate void ThreadLockFunc (int acquire);
412 [CCode (cname = "PQregisterThreadLock")]
413 public ThreadLockFunc register_thread_lock (ThreadLockFunc newhandler);
415 [CCode (cname = "PQunescapeBytea")]
416 public uchar[] unescape_bytea (uchar[] strtext, out size_t retbuflen);
419 [CCode (free_function = "PQclear", cname = "PGresult", cprefix = "PQ")]
420 public class Result {
421 [CCode (cname = "PQresultStatus")]
422 public ExecStatus get_status ();
424 [CCode (cname = "PQresultErrorMessage")]
425 public unowned string get_error_message ();
427 [CCode (cname = "PQresultErrorField")]
428 public unowned string get_error_field (FieldCode field_code);
430 [CCode (cname = "PQntuples")]
431 public int get_n_tuples ();
433 [CCode (cname = "PQnfields")]
434 public int get_n_fields ();
436 [CCode (cname = "PQbinaryTuples")]
437 public bool is_binary_tuples ();
439 [CCode (cname = "PQfname")]
440 public unowned string get_field_name (int field_num);
442 [CCode (cname = "PQfnumber")]
443 public int get_field_number (string field_name);
445 [CCode (cname = "PQftable")]
446 public Oid get_field_table (int field_num);
448 [CCode (cname = "PQftablecol")]
449 public int get_field_table_col (int field_num);
451 [CCode (cname = "PQfformat")]
452 public int get_field_format (int field_num);
454 [CCode (cname = "PQftype")]
455 public Oid get_field_type (int field_num);
457 [CCode (cname = "PQfsize")]
458 public int get_fsize (int field_num);
460 [CCode (cname = "PQfmod")]
461 public int get_field_mod (int field_num);
463 [CCode (cname = "PQcmdStatus")]
464 public unowned string get_cmd_status ();
466 [CCode (cname = "PQoidValue")]
467 public Oid get_oid_value ();
469 [CCode (cname = "PQcmdTuples")]
470 public unowned string get_cmd_tuples ();
472 [CCode (cname = "PQgetvalue")]
473 public unowned string get_value (int tup_num, int field_num);
475 [CCode (cname = "PQgetlength")]
476 public int get_length (int tup_num, int field_num);
478 [CCode (cname = "PQgetisnull")]
479 public bool is_null (int tup_num, int field_num);
481 [CCode (cname = "PQnparams")]
482 public int get_n_params ();
484 [CCode (cname = "PQparamtype")]
485 public int get_param_type (int param_num);
488 [CCode (cname = "PQfreemem")]
489 public void free_mem (void* ptr);
491 [CCode (cname = "PQprint")]
492 public void print (GLib.FileStream fout, Result res, PrintOpt ps);
494 [CCode (cname = "PQmblen")]
495 public int mb_len (string s, int encoding);
497 [CCode (cname = "PQdsplen")]
498 public int dsp_len (string s, int encoding);
500 [CCode (cname = "PQenv2encoding")]
501 public int env2encoding ();
503 [CCode (cname = "PQencryptPassword")]
504 public unowned string encrypt_password (string passwd, string user);
506 [CCode (cname = "pg_char_to_encoding")]
507 public int char_to_encoding (string name);
509 [CCode (cname = "pg_encoding_to_char")]
510 public unowned string encoding_to_char (int encoding);
512 [CCode (cname = "pg_valid_server_encoding_id")]
513 public int valid_server_encoding_id (int encoding);