mysql.vapi 8.38 KB
Newer Older
1 2
/* mysql.vala
 *
3
 * Copyright (C) 2008, 2010 Jukka-Pekka Iivonen
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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:
 * 	Jukka-Pekka Iivonen <jp0409@jippii.fi>
 */

[CCode (lower_case_cprefix = "mysql_", cheader_filename = "mysql/mysql.h")]
namespace Mysql {
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
	[CCode (cname = "unsigned long", cprefix = "CLIENT_", has_type_id = false)]
	public enum ClientFlag {
		LONG_PASSWORD,
		FOUND_ROWS,
		LONG_FLAG,
		CONNECT_WITH_DB,
		NO_SCHEMA,
		COMPRESS,
		ODBC,
		LOCAL_FILES,
		IGNORE_SPACE,
		PROTOCOL_41,
		INTERACTIVE,
		SSL,
		IGNORE_SIGPIPE,
		TRANSACTIONS,
		RESERVED,
		SECURE_CONNECTION,
		MULTI_STATEMENTS,
		MULTI_RESULTS,
		SSL_VERIFY_SERVER_CERT,
		REMEMBER_OPTIONS
	}

	[CCode (cname = "enum_mysql_set_option", cprefix = "MYSQL_OPTION_", has_type_id = false)]
	public enum SetOption {
		MULTI_STATEMENTS_ON,
		MULTI_STATEMENTS_OFF
	}

	[CCode (cname = "mysql_option", cprefix = "MYSQL_", has_type_id = false)]
	public enum Option {
		OPT_CONNECT_TIMEOUT,
		OPT_COMPRESS,
		OPT_NAMED_PIPE,
		INIT_COMMAND,
		READ_DEFAULT_FILE,
		READ_DEFAULT_GROUP,
		SET_CHARSET_DIR,
		SET_CHARSET_NAME,
		OPT_LOCAL_INFILE,
		OPT_PROTOCOL,
		SHARED_MEMORY_BASE_NAME,
		OPT_READ_TIMEOUT,
		OPT_WRITE_TIMEOUT,
		OPT_USE_RESULT,
		OPT_USE_REMOTE_CONNECTION,
		OPT_USE_EMBEDDED_CONNECTION,
		OPT_GUESS_CONNECTION,
		SET_CLIENT_IP,
		SECURE_AUTH,
		REPORT_DATA_TRUNCATION,
		OPT_RECONNECT,
		OPT_SSL_VERIFY_SERVER_CERT
	}

	[CCode (cname = "enum enum_field_types", cprefix = "MYSQL_TYPE_", has_type_id = false)]
	public enum FieldType {
		DECIMAL,
		TINY,
		SHORT,
		LONG,
		FLOAT,
		DOUBLE,
		NULL,
		TIMESTAMP,
		LONGLONG,
		INT24,
		DATE,
		TIME,
		DATETIME,
		YEAR,
		NEWDATE,
		VARCHAR,
		BIT,
		NEWDECIMAL,
		ENUM,
		SET,
		TINY_BLOB,
		MEDIUM_BLOB,
		LONG_BLOB,
		BLOB,
		VAR_STRING,
		STRING,
		GEOMETRY
	}

	[CCode (cname = "guint", has_type_id = false)]
	public enum FieldFlag {
		[CCode (cname = "NOT_NULL_FLAG")]
		NOT_NULL,
		[CCode (cname = "PRI_KEY_FLAG")]
		PRI_KEY,
		[CCode (cname = "UNIQUE_FLAG")]
		UNIQUE_KEY,
		[CCode (cname = "MULTIPLE_KEY_FLAG")]
		MULTIPLE_KEY,
		[CCode (cname = "BLOB_FLAG")]
		BLOB,
		[CCode (cname = "UNSIGNED_FLAG")]
		UNSIGNED,
		[CCode (cname = "ZEROFILL_FLAG")]
		ZEROFILL,
		[CCode (cname = "BINARY_FLAG")]
		BINARY,
		[CCode (cname = "ENUM_FLAG")]
		ENUM,
		[CCode (cname = "AUTO_INCREMENT_FLAG")]
		AUTO_INCREMENT,
		[CCode (cname = "TIMESTAMP_FLAG")]
		TIMESTAMP,
		[CCode (cname = "SET_FLAG")]
		SET,
		[CCode (cname = "NO_DEFAULT_VALUE_FLAG")]
		NO_DEFAULT_VALUE,
		[CCode (cname = "ON_UPDATE_NOW_FLAG")]
		ON_UPDATE_NOW,
		[CCode (cname = "NUM_FLAG")]
		NUM,
		[CCode (cname = "PART_KEY_FLAG")]
		PART_KEY,
		[CCode (cname = "GROUP_FLAG")]
		GROUP,
		[CCode (cname = "UNIQUE_FLAG")]
		UNIQUE,
		[CCode (cname = "BINCMP_FLAG")]
		BINCMP,
		[CCode (cname = "GET_FIXED_FIELDS_FLAG")]
		GET_FIXED_FIELDS,
		[CCode (cname = "FIELD_IN_PART_FUNC_FLAG")]
		FIELD_IN_PART_FUNC,
		[CCode (cname = "FIELD_IN_ADD_INDEX")]
		FIELD_IN_ADD_INDEX,
		[CCode (cname = "FIELD_IS_RENAMED")]
		FIELD_IS_RENAMED
	}

162
	[CCode (cname = "enum_cursor_type", cprefix = "CURSOR_TYPE_", has_type_id = false)]
163 164 165 166 167 168 169
	public enum CursorType {
		NO_CURSOR,
		READ_ONLY,
		FOR_UPDATE,
		SCROLLABLE
	}

170 171 172
	[Compact]
	[CCode (free_function = "mysql_close", cname = "MYSQL", cprefix = "mysql_")]
	public class Database {
173 174
		[CCode (cname = "mysql_init")]
		public Database (Database? mysql = null);
175 176 177

		public ulong affected_rows ();
		public bool autocommit (bool mode);
178
		public bool change_user (string username, string passwd, string? dbname = null);
179
		public unowned string character_set_name ();
180 181 182
		public bool commit ();
		public int dump_debug_info ();
		public uint errno ();
183 184
		public unowned string error ();
		public unowned string get_host_info ();
185
		public uint get_proto_info ();
186
		public unowned string get_server_info ();
187
		public ulong get_server_version ();
188 189
		public unowned string get_ssl_cipher ();
		public unowned string info ();
190 191
		public ulong insert_id ();
		public int kill (ulong pid);
192 193 194 195
		public Result? list_dbs (string? wild = null);
		public Result? list_fields (string table, string? wild = null);
		public Result? list_processes ();
		public Result? list_tables (string? wild = null);
196 197
		public bool more_results ();
		public int next_result ();
198
		public int options (Option option, string arg);
199 200
		public int ping ();
		public int query (string stmt_str);
201
		public bool real_connect (string? host = null, string? username = null, string? passwd = null, string? dbname = null, uint port = 0, string? unix_socket = null, ClientFlag client_flag = 0);
202 203 204 205 206 207 208
		public ulong real_escape_string (string to, string from, ulong length);
		public int real_query (string query, ulong len);
		public int reload ();
		public bool rollback ();
		public int select_db (string dbname);
		public int set_character_set (string csname);
		public void set_local_infile_default ();
209
		public int set_server_option (SetOption option);
210
		public unowned string sqlstate ();
211 212
		public int shutdown (int shutdown_level);
		public bool ssl_set (string key, string cert, string ca, string capath, string cipher);
213
		public unowned string stat ();
214 215
		public Result? store_result ();
		public ulong thread_id ();
216
		public Result? use_result ();
217 218
		public uint warning_count ();
	}
219

220 221 222 223
	[Compact]
	[CCode (free_function = "mysql_free_result", cname = "MYSQL_RES", cprefix = "mysql_")]
	public class Result {
		public bool eof ();
224 225
		public Field* fetch_field ();
		public Field* fetch_field_direct (uint field_nbr);
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

		[CCode (cname = "mysql_fetch_fields", array_length = false)]
		public unowned Field[] _fetch_fields ();
		[CCode (cname = "_vala_mysql_fetch_fields")]
		public unowned Field[] fetch_fields () {
			unowned Field[] fields = this._fetch_fields ();
			fields.length = (int) this.num_fields ();
			return fields;
		}

		[CCode (cname = "mysql_fetch_lengths", array_length = false)]
		public unowned ulong[] _fetch_lengths ();
		[CCode (cname = "_vala_mysql_fetch_lengths")]
		public unowned ulong[] fetch_lengths () {
			unowned ulong[] lengths = this._fetch_lengths ();
			lengths.length = (int) this.num_fields ();
			return lengths;
		}

		[CCode (cname = "mysql_fetch_row", array_length = false)]
		public unowned string[]? _fetch_row ();
		[CCode (cname = "_vala_mysql_fetch_row")]
		public unowned string[]? fetch_row () {
			unowned string[]? row = this._fetch_row ();
			row.length = (int) this.num_fields ();
			return row;
		}

254 255 256
		public uint fetch_count ();
		public uint num_fields ();
		public uint num_rows ();
257

258 259
		public bool data_seek (ulong offset);
	}
260
	[CCode (cname = "MYSQL_FIELD", has_type_id = false)]
261
	public struct Field {
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
		public unowned string name;
		public unowned string org_name;
		public unowned string table;
		public unowned string org_table;
		public unowned string db;
		public unowned string catalog;
		public unowned string def;
		public ulong length;
		public ulong max_length;
		public uint name_length;
		public uint org_name_length;
		public uint table_length;
		public uint org_table_length;
		public uint db_length;
		public uint catalog_length;
		public uint def_length;
		public uint flags;
		public uint decimals;
		public uint charsetnr;
		public FieldType type;
		public void *extension;
283
	}
284

285
	public unowned string get_client_info ();
286 287 288 289
	public ulong get_client_version ();
	public void debug (string msg);
	public ulong hex_string (string to, string from, ulong length);
	public void library_end ();
290
	public int library_init ([CCode (array_length_pos = 0.1)] string[] argv, [CCode (array_length = false, array_null_terminated = true)] string[]? groups = null);
291
	public void server_end ();
292
	public int server_init ([CCode (array_length_pos = 0.1)] string[] argv, [CCode (array_length = false, array_null_terminated = true)] string[]? groups = null);
293 294 295 296 297
	public void thread_end ();
	public bool thread_init ();
	public uint thread_safe ();
}