libpq.vapi 14.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* libpq.vapi
 *
 * Copyright (C) 2009 Jukka-Pekka Iivonen
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
20
 *	Jukka-Pekka Iivonen <jp0409@jippii.fi>
21 22
 */

23 24 25
#if LIBPQ_9_3
[CCode (cprefix = "PQ", cheader_filename = "libpq-fe.h")]
#else
26
[CCode (cprefix = "PQ", cheader_filename = "postgresql/libpq-fe.h")]
27
#endif
28 29
namespace Postgres {

30
	[CCode (cname = "ConnStatusType", cprefix = "CONNECTION_", has_type_id = false)]
31 32 33 34 35 36 37 38 39 40 41 42
	public enum ConnectionStatus {
		OK,
		BAD,
		STARTED,
		MADE,
		AWAITING_RESPONSE,
		AUTH_OK,
		SETENV,
		SSL_STARTUP,
		NEEDED
	}

43
	[CCode (cname = "PostgresPollingStatusType", cprefix = "PGRES_POLLING_", has_type_id = false)]
44 45 46 47 48 49 50 51
	public enum PollingStatus {
		FAILED,
		READING,
		WRITING,
		OK,
		ACTIVE
	}

52
	[CCode (cname = "ExecStatusType", cprefix = "PGRES_", has_type_id = false)]
53 54 55 56 57 58 59 60 61 62 63
	public enum ExecStatus {
		EMPTY_QUERY,
		COMMAND_OK,
		TUPLES_OK,
		COPY_OUT,
		COPY_IN,
		BAD_RESPONSE,
		NONFATAL_ERROR,
		FATAL_ERROR
	}

64
	[CCode (cname = "PGTransactionStatusType", cprefix = "PQTRANS_", has_type_id = false)]
65 66 67 68 69 70 71 72
	public enum TransactionStatus {
		IDLE,
		ACTIVE,
		INTRANS,
		INERROR,
		UNKNOWN
	}

73
	[CCode (cname = "PGVerbosity", cprefix = "PQERRORS_", has_type_id = false)]
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
	public enum Verbosity {
		TERSE,
		DEFAULT,
		VERBOSE
	}

	[CCode (cname = "int", cprefix = "PG_DIAG_", has_type_id = false)]
	public enum FieldCode {
		SEVERITY,
		SQLSTATE,
		MESSAGE_PRIMARY,
		MESSAGE_DETAIL,
		MESSAGE_HINT,
		STATEMENT_POSITION,
		INTERNAL_POSITION,
		INTERNAL_QUERY,
		CONTEXT,
		SOURCE_FILE,
		SOURCE_LINE,
		SOURCE_FUNCTION
	}

96 97 98 99 100 101 102 103
	[CCode (cname = "PGPing", cprefix = "PQPING_", has_type_id = false)]
	public enum Ping {
		OK,
		REJECT,
		NO_RESPONCE,
		NO_ATTEMPT
	}

104 105 106
	[Compact]
	[CCode (cname = "PGnotify", free_function = "PQfreemem")]
	public class Notify {
107 108 109
		public string relname;
		public int    be_pid;
		public string extra;
110 111

		private Notify ();
112 113 114 115 116 117 118 119
	}

	[CCode (cname = "PQnoticeReceiver")]
	public delegate void NoticeReceiverFunc (void* arg, Result res);

	[CCode (cname = "PQnoticeProcessor")]
	public delegate void NoticeProcessorFunc (void* arg, string message);

120
	[CCode (cname = "PQprintOpt", has_type_id = false)]
121 122 123 124 125 126 127 128 129 130 131 132 133 134
	public struct PrintOpt {
		public bool     header;
		public bool     align;
		public bool     standard;
		public bool     html3;
		public bool     expanded;
		public bool     pager;
		public string   fieldSep;
		public string   tableOpt;
		public string   caption;
		public string[] fieldName;
	}

	[Compact]
135
	[CCode (cname = "PQconninfoOption", free_function = "PQconninfoFree")]
136 137 138 139 140 141 142 143 144 145
	public class ConnectionOptions {
		public string keyword;
		public string envvar;
		public string compiled;
		public string val;
		public string label;
		public string dispchar;
		public int    dispsize;
	}

146
	[CCode (cname = "PQArgBlock", has_type_id = false)]
147 148 149 150 151 152
	public struct ArgBlock {
		public int len;
		public int isint;
	}

	[SimpleType]
153
	[CCode (cname = "uint", default_value = "0U", type_signature = "u", has_type_id = false)]
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	public struct Oid {
	}

	[CCode (cname = "InvalidOid")]
	public const uint InvalidOid;

	[CCode (cname = "PQconnectStart")]
	public Database connect_start (string conninfo);

	[CCode (cname = "PQconnectdb")]
	public Database connect_db (string conninfo);

	[CCode (cname = "PQsetdbLogin")]
	public Database set_db_login (string host, string port, string options, string gtty, string db_name, string login, string pwd);

	[CCode (cname = "PQsetdb")]
	public Database set_db (string host, string port, string options, string gtty, string db_name);

	[CCode (cname = "PQconndefaults")]
	public ConnectionOptions get_default_options ();

	[CCode (cname = "PQinitSSL")]
	public void init_ssl (int do_init);

	[CCode (cname = "PQisthreadsafe")]
	public int is_thread_safe ();

	[CCode (cname = "PQresStatus")]
	public unowned string result_status (ExecStatus status);

	[Compact]
	[CCode (free_function = "PQfreeCancel", cname = "PGcancel", cprefix = "PQ")]
	public class Cancel {
		[CCode (cname = "PQcancel")]
		public bool cancel (char[] errbuf, int errbufsize);
	}

	/* Database Connection Handle */
	[Compact]
	[CCode (free_function = "PQfinish", cname = "PGconn", cprefix = "PQ")]
	public class Database {
		[CCode (cname = "PQconnectPoll")]
		public PollingStatus connect_poll ();

		[CCode (cname = "PQresetStart")]
		public int reset_start ();

		[CCode (cname = "PQresetPoll")]
		public PollingStatus reset_poll ();

		[CCode (cname = "PQreset")]
		public void reset ();

		[CCode (cname = "PQgetCancel")]
		public Cancel get_cancel ();

		[CCode (cname = "PQrequestCancel")]
		public int request_cancel ();

		[CCode (cname = "PQdb")]
		public unowned string get_db ();

		[CCode (cname = "PQuser")]
		public unowned string get_user ();

		[CCode (cname = "PQpass")]
		public unowned string get_passwd ();

		[CCode (cname = "PQhost")]
		public unowned string get_host ();

		[CCode (cname = "PQport")]
		public unowned string get_port ();

		[CCode (cname = "PQtty")]
		public unowned string get_tty ();

		[CCode (cname = "PQoptions")]
		public unowned string get_options ();

		[CCode (cname = "PQstatus")]
		public ConnectionStatus get_status ();

		[CCode (cname = "PQtransactionStatus")]
		public TransactionStatus get_transaction_status ();

		[CCode (cname = "PQparameterStatus")]
		public unowned string get_parameter_status (string param_name);

		[CCode (cname = "PQprotocolVersion")]
		public int get_protocol_Version ();

		[CCode (cname = "PQserverVersion")]
		public int get_server_version ();

		[CCode (cname = "PQerrorMessage")]
		public unowned string get_error_message ();

		[CCode (cname = "PQsocket")]
		public int get_socket ();

		[CCode (cname = "PQbackendPID")]
		public int get_backend_pid ();

		[CCode (cname = "PQconnectionNeedsPassword")]
		public int connection_needs_password ();

		[CCode (cname = "PQconnectionUsedPassword")]
		public int connection_used_password ();

		[CCode (cname = "PQclientEncoding")]
		public int get_client_encoding ();

		[CCode (cname = "PQsetClientEncoding")]
		public int set_client_encoding (string encoding);

		[CCode (cname = "PQgetssl")]
		public void* get_ssl ();

		[CCode (cname = "PQsetErrorVerbosity")]
		public Verbosity set_error_verbosity (Verbosity verbosity);

		[CCode (cname = "PQtrace")]
		public void trace (GLib.FileStream debug_port);

		[CCode (cname = "PQuntrace")]
		public void untrace ();

		[CCode (cname = "PQsetNoticeReceiver")]
		public NoticeReceiverFunc set_notice_receiver (NoticeReceiverFunc proc_func, void* arg);

		[CCode (cname = "PQsetNoticeProcessor")]
		public NoticeProcessorFunc set_notice_processor (NoticeProcessorFunc proc_func, void* arg);

		[CCode (cname = "PQexec")]
		public Result exec (string query);

291 292
		[CCode (cname = "PQexecParams")]
		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);
293

294 295
		[CCode (cname = "PQprepare")]
		public Result prepare (string stmt_name, string query, [CCode (array_length_pos = 2.9)] Oid[]? param_types);
296

297 298
		[CCode (cname = "PQexecPrepared")]
		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);
299 300 301 302

		[CCode (cname = "PQsendQuery")]
		public int send_query (string query);

303 304
		[CCode (cname = "PQsendQueryParams")]
		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);
305

306 307
		[CCode (cname = "PQsendPrepare")]
		public int send_prepare (string stmt_name, string query, [CCode (array_length_pos = 2.9)] Oid[]? param_types);
308

309 310
		[CCode (cname = "PQsendQueryPrepared")]
		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);
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

		[CCode (cname = "PQgetResult")]
		public Result get_result ();

		[CCode (cname = "PQisBusy")]
		public int is_busy ();

		[CCode (cname = "PQconsumeInput")]
		public int consume_input ();

		[CCode (cname = "PQnotifies")]
		public Notify get_notifies ();

		[CCode (cname = "PQputCopyData")]
		public int put_copy_data (string buffer, int nbytes);

		[CCode (cname = "PQputCopyEnd")]
		public int put_copy_end (string error_msg);

		[CCode (cname = "PQgetCopyData")]
		public int get_copy_data (string[] buffer, int async);

		[CCode (cname = "PQsetnonblocking")]
		public int set_non_blocking (int arg);

		[CCode (cname = "PQisnonblocking")]
		public int is_non_blocking ();

339
		[CCode (cname = "PQping")]
340 341 342 343 344
		public Ping ping();
		 
		[CCode (cname = "PQpingParams")]
		public Ping ping_params(string keywords, string values, int expand_dbname);

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
		[CCode (cname = "PQflush")]
		public int flush ();

		[CCode (cname = "PQfn")]
		public Result fn (int fnid, int[] result_buf, out int result_len, int result_is_int, ArgBlock args, int nargs);

		[CCode (cname = "PQdescribePrepared")]
		public Result describe_prepared (string stmt);

		[CCode (cname = "PQdescribePortal")]
		public Result describe_portal (string portal);

		[CCode (cname = "PQsendDescribePrepared")]
		public int send_describe_prepared (string stmt);

		[CCode (cname = "PQsendDescribePortal")]
		public int send_describe_portal (string portal);

		[CCode (cname = "PQmakeEmptyPGresult")]
		public Result make_empty_result (ExecStatus status);

		[CCode (cname = "PQescapeStringConn")]
		public size_t escape_string_conn (string to, string from, size_t length, out int error);

		[CCode (cname = "PQescapeByteaConn")]
		public uchar[] escape_bytea_conn (string from, size_t from_length, out size_t to_length);

		[CCode (cname = "lo_open")]
		public int lo_open (int lobj_id, int mode);

		[CCode (cname = "lo_close")]
		public int lo_close (int fd);

		[CCode (cname = "lo_read")]
		public int lo_read (int fd, string buf, size_t len);

		[CCode (cname = "lo_write")]
		public int lo_write (int fd, string buf, size_t len);

		[CCode (cname = "lo_lseek")]
		public int lo_lseek (int fd, int offset, int whence);

		[CCode (cname = "lo_creat")]
		public int lo_creat (int mode);

		[CCode (cname = "lo_create")]
		public int lo_create (int lobj_id);

		[CCode (cname = "lo_tell")]
		public int lo_tell (int fd);

		[CCode (cname = "lo_truncate")]
		public int lo_truncate (int fd, size_t len);

		[CCode (cname = "lo_unlink")]
		public int lo_unlink (int lobj_id);

		[CCode (cname = "lo_import")]
		public int lo_import (string filename);

		[CCode (cname = "lo_export")]
		public int lo_export (int lobj_id, string filename);
	}

	[CCode (cname = "pgthreadlock_t")]
	public delegate void ThreadLockFunc (int acquire);

	[CCode (cname = "PQregisterThreadLock")]
	public ThreadLockFunc register_thread_lock (ThreadLockFunc newhandler);

	[CCode (cname = "PQunescapeBytea")]
	public uchar[] unescape_bytea (uchar[] strtext, out size_t retbuflen);

	[Compact]
	[CCode (free_function = "PQclear", cname = "PGresult", cprefix = "PQ")]
	public class Result {
		[CCode (cname = "PQresultStatus")]
		public ExecStatus get_status ();

		[CCode (cname = "PQresultErrorMessage")]
		public unowned string get_error_message ();

		[CCode (cname = "PQresultErrorField")]
		public unowned string get_error_field (FieldCode field_code);

		[CCode (cname = "PQntuples")]
		public int get_n_tuples ();

		[CCode (cname = "PQnfields")]
		public int get_n_fields ();

		[CCode (cname = "PQbinaryTuples")]
		public bool is_binary_tuples ();

		[CCode (cname = "PQfname")]
		public unowned string get_field_name (int field_num);

		[CCode (cname = "PQfnumber")]
		public int get_field_number (string field_name);

		[CCode (cname = "PQftable")]
		public Oid get_field_table (int field_num);

		[CCode (cname = "PQftablecol")]
		public int get_field_table_col (int field_num);

		[CCode (cname = "PQfformat")]
		public int get_field_format (int field_num);

		[CCode (cname = "PQftype")]
		public Oid get_field_type (int field_num);

		[CCode (cname = "PQfsize")]
		public int get_fsize (int field_num);

		[CCode (cname = "PQfmod")]
		public int get_field_mod (int field_num);

		[CCode (cname = "PQcmdStatus")]
		public unowned string get_cmd_status ();

		[CCode (cname = "PQoidValue")]
		public Oid get_oid_value ();

		[CCode (cname = "PQcmdTuples")]
		public unowned string get_cmd_tuples ();

		[CCode (cname = "PQgetvalue")]
		public unowned string get_value (int tup_num, int field_num);

		[CCode (cname = "PQgetlength")]
		public int get_length (int tup_num, int field_num);

		[CCode (cname = "PQgetisnull")]
		public bool is_null (int tup_num, int field_num);

		[CCode (cname = "PQnparams")]
		public int get_n_params ();

		[CCode (cname = "PQparamtype")]
		public int get_param_type (int param_num);
	}

	[CCode (cname = "PQfreemem")]
	public void free_mem (void* ptr);

	[CCode (cname = "PQprint")]
	public void print (GLib.FileStream fout, Result res, PrintOpt ps);

	[CCode (cname = "PQmblen")]
	public int mb_len (string s, int encoding);

	[CCode (cname = "PQdsplen")]
	public int dsp_len (string s, int encoding);

	[CCode (cname = "PQenv2encoding")]
	public int env2encoding ();

	[CCode (cname = "PQencryptPassword")]
	public unowned string encrypt_password (string passwd, string user);

	[CCode (cname = "pg_char_to_encoding")]
	public int char_to_encoding (string name);

	[CCode (cname = "pg_encoding_to_char")]
	public unowned string encoding_to_char (int encoding);

	[CCode (cname = "pg_valid_server_encoding_id")]
	public int valid_server_encoding_id (int encoding);
}