[7882] | 1 | /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
---|
| 2 |
|
---|
| 3 | This library is free software; you can redistribute it and/or
|
---|
| 4 | modify it under the terms of the GNU Library General Public
|
---|
| 5 | License as published by the Free Software Foundation; either
|
---|
| 6 | version 2 of the License, or (at your option) any later version.
|
---|
| 7 |
|
---|
| 8 | This library is distributed in the hope that it will be useful,
|
---|
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 11 | Library General Public License for more details.
|
---|
| 12 |
|
---|
| 13 | You should have received a copy of the GNU Library General Public
|
---|
| 14 | License along with this library; if not, write to the Free
|
---|
| 15 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
---|
| 16 | MA 02111-1307, USA */
|
---|
[828] | 17 |
|
---|
[7882] | 18 | /* defines for the libmysql library */
|
---|
[828] | 19 |
|
---|
| 20 | #ifndef _mysql_h
|
---|
| 21 | #define _mysql_h
|
---|
[7882] | 22 |
|
---|
| 23 | #ifdef __CYGWIN__ /* CYGWIN implements a UNIX API */
|
---|
| 24 | #undef WIN
|
---|
| 25 | #undef _WIN
|
---|
| 26 | #undef _WIN32
|
---|
| 27 | #undef _WIN64
|
---|
| 28 | #undef __WIN__
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
| 31 | #ifndef MYSQL_SERVER
|
---|
| 32 | #ifdef __cplusplus
|
---|
[828] | 33 | extern "C" {
|
---|
| 34 | #endif
|
---|
[7882] | 35 | #endif
|
---|
| 36 |
|
---|
| 37 | #ifndef _global_h /* If not standard header */
|
---|
[828] | 38 | #include <sys/types.h>
|
---|
| 39 | typedef char my_bool;
|
---|
[7882] | 40 | #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
|
---|
| 41 | #define __WIN__
|
---|
| 42 | #endif
|
---|
| 43 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
---|
| 44 | #define STDCALL _System _Export
|
---|
| 45 | #elif !defined(__WIN__)
|
---|
| 46 | #define STDCALL
|
---|
[828] | 47 | #else
|
---|
| 48 | #define STDCALL __stdcall
|
---|
| 49 | #endif
|
---|
| 50 | typedef char * gptr;
|
---|
| 51 |
|
---|
| 52 | #ifndef ST_USED_MEM_DEFINED
|
---|
| 53 | #define ST_USED_MEM_DEFINED
|
---|
[7882] | 54 | typedef struct st_used_mem { /* struct for once_alloc */
|
---|
| 55 | struct st_used_mem *next; /* Next block in use */
|
---|
| 56 | unsigned int left; /* memory left in block */
|
---|
| 57 | unsigned int size; /* size of block */
|
---|
[828] | 58 | } USED_MEM;
|
---|
| 59 | typedef struct st_mem_root {
|
---|
| 60 | USED_MEM *free;
|
---|
| 61 | USED_MEM *used;
|
---|
[7882] | 62 | USED_MEM *pre_alloc;
|
---|
| 63 | unsigned int min_malloc;
|
---|
| 64 | unsigned int block_size;
|
---|
| 65 |
|
---|
[828] | 66 | void (*error_handler)(void);
|
---|
| 67 | } MEM_ROOT;
|
---|
| 68 | #endif
|
---|
| 69 |
|
---|
[1936] | 70 | #ifndef my_socket_defined
|
---|
[7882] | 71 | #ifdef __WIN__
|
---|
[1936] | 72 | #define my_socket SOCKET
|
---|
[828] | 73 | #else
|
---|
[1936] | 74 | typedef int my_socket;
|
---|
[828] | 75 | #endif
|
---|
| 76 | #endif
|
---|
| 77 | #endif
|
---|
| 78 | #include "mysql_com.h"
|
---|
| 79 | #include "mysql_version.h"
|
---|
| 80 |
|
---|
| 81 | extern unsigned int mysql_port;
|
---|
| 82 | extern char *mysql_unix_port;
|
---|
| 83 |
|
---|
[7882] | 84 | #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
|
---|
| 85 | #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
|
---|
| 86 | #define IS_BLOB(n) ((n) & BLOB_FLAG)
|
---|
| 87 | #define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
|
---|
| 88 | #define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
|
---|
| 89 | #define INTERNAL_NUM_FIELD(f) (((f)->type <= FIELD_TYPE_INT24 && ((f)->type != FIELD_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == FIELD_TYPE_YEAR)
|
---|
[828] | 90 |
|
---|
| 91 | typedef struct st_mysql_field {
|
---|
[7882] | 92 | char *name; /* Name of column */
|
---|
| 93 | char *table; /* Table of column if column was a field */
|
---|
| 94 | char *def; /* Default value (set by mysql_list_fields) */
|
---|
| 95 | enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
|
---|
| 96 | unsigned int length; /* Width of column */
|
---|
| 97 | unsigned int max_length; /* Max width of selected set */
|
---|
| 98 | unsigned int flags; /* Div flags */
|
---|
| 99 | unsigned int decimals; /* Number of decimals in field */
|
---|
[828] | 100 | } MYSQL_FIELD;
|
---|
| 101 |
|
---|
[7882] | 102 | typedef char **MYSQL_ROW; /* return data as array of strings */
|
---|
[828] | 103 | typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
|
---|
| 104 |
|
---|
[1936] | 105 | #if defined(NO_CLIENT_LONG_LONG)
|
---|
| 106 | typedef unsigned long my_ulonglong;
|
---|
[7882] | 107 | #elif defined (__WIN__)
|
---|
[1936] | 108 | typedef unsigned __int64 my_ulonglong;
|
---|
| 109 | #else
|
---|
| 110 | typedef unsigned long long my_ulonglong;
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
|
---|
| 114 |
|
---|
[828] | 115 | typedef struct st_mysql_rows {
|
---|
[7882] | 116 | struct st_mysql_rows *next; /* list of rows */
|
---|
[828] | 117 | MYSQL_ROW data;
|
---|
| 118 | } MYSQL_ROWS;
|
---|
| 119 |
|
---|
[7882] | 120 | typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
|
---|
[828] | 121 |
|
---|
| 122 | typedef struct st_mysql_data {
|
---|
[1936] | 123 | my_ulonglong rows;
|
---|
[828] | 124 | unsigned int fields;
|
---|
| 125 | MYSQL_ROWS *data;
|
---|
| 126 | MEM_ROOT alloc;
|
---|
| 127 | } MYSQL_DATA;
|
---|
| 128 |
|
---|
[1936] | 129 | struct st_mysql_options {
|
---|
| 130 | unsigned int connect_timeout,client_flag;
|
---|
| 131 | my_bool compress,named_pipe;
|
---|
| 132 | unsigned int port;
|
---|
| 133 | char *host,*init_command,*user,*password,*unix_socket,*db;
|
---|
[7882] | 134 | char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
|
---|
| 135 | my_bool use_ssl; /* if to use SSL or not */
|
---|
| 136 | char *ssl_key; /* PEM key file */
|
---|
| 137 | char *ssl_cert; /* PEM cert file */
|
---|
| 138 | char *ssl_ca; /* PEM CA file */
|
---|
| 139 | char *ssl_capath; /* PEM directory of CA-s? */
|
---|
[1936] | 140 | };
|
---|
| 141 |
|
---|
| 142 | enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
|
---|
[7882] | 143 | MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
|
---|
| 144 | MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
|
---|
| 145 | MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME};
|
---|
[1936] | 146 |
|
---|
[828] | 147 | enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
|
---|
[7882] | 148 | MYSQL_STATUS_USE_RESULT};
|
---|
[828] | 149 |
|
---|
| 150 | typedef struct st_mysql {
|
---|
[7882] | 151 | NET net; /* Communication parameters */
|
---|
| 152 | gptr connector_fd; /* ConnectorFd for SSL */
|
---|
| 153 | char *host,*user,*passwd,*unix_socket,*server_version,*host_info,
|
---|
| 154 | *info,*db;
|
---|
| 155 | unsigned int port,client_flag,server_capabilities;
|
---|
| 156 | unsigned int protocol_version;
|
---|
| 157 | unsigned int field_count;
|
---|
| 158 | unsigned int server_status;
|
---|
| 159 | unsigned long thread_id; /* Id for connection in server */
|
---|
[1936] | 160 | my_ulonglong affected_rows;
|
---|
[7882] | 161 | my_ulonglong insert_id; /* id if insert on table with NEXTNR */
|
---|
| 162 | my_ulonglong extra_info; /* Used by mysqlshow */
|
---|
[1936] | 163 | unsigned long packet_length;
|
---|
[828] | 164 | enum mysql_status status;
|
---|
[7882] | 165 | MYSQL_FIELD *fields;
|
---|
| 166 | MEM_ROOT field_alloc;
|
---|
| 167 | my_bool free_me; /* If free in mysql_close */
|
---|
| 168 | my_bool reconnect; /* set to 1 if automatic reconnect */
|
---|
[1936] | 169 | struct st_mysql_options options;
|
---|
[7882] | 170 | char scramble_buff[9];
|
---|
| 171 | struct charset_info_st *charset;
|
---|
| 172 | unsigned int server_language;
|
---|
[828] | 173 | } MYSQL;
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | typedef struct st_mysql_res {
|
---|
[1936] | 177 | my_ulonglong row_count;
|
---|
[7882] | 178 | unsigned int field_count, current_field;
|
---|
| 179 | MYSQL_FIELD *fields;
|
---|
| 180 | MYSQL_DATA *data;
|
---|
| 181 | MYSQL_ROWS *data_cursor;
|
---|
| 182 | MEM_ROOT field_alloc;
|
---|
| 183 | MYSQL_ROW row; /* If unbuffered read */
|
---|
| 184 | MYSQL_ROW current_row; /* buffer to current row */
|
---|
| 185 | unsigned long *lengths; /* column lengths of current row */
|
---|
| 186 | MYSQL *handle; /* for unbuffered reads */
|
---|
| 187 | my_bool eof; /* Used my mysql_fetch_row */
|
---|
[828] | 188 | } MYSQL_RES;
|
---|
| 189 |
|
---|
[7882] | 190 | /* Functions to get information from the MYSQL and MYSQL_RES structures */
|
---|
| 191 | /* Should definitely be used if one uses shared libraries */
|
---|
[828] | 192 |
|
---|
[7882] | 193 | my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
|
---|
| 194 | unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
|
---|
| 195 | my_bool STDCALL mysql_eof(MYSQL_RES *res);
|
---|
| 196 | MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
|
---|
| 197 | unsigned int fieldnr);
|
---|
| 198 | MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
|
---|
| 199 | MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res);
|
---|
| 200 | unsigned int STDCALL mysql_field_tell(MYSQL_RES *res);
|
---|
[828] | 201 |
|
---|
[7882] | 202 | unsigned int STDCALL mysql_field_count(MYSQL *mysql);
|
---|
| 203 | my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
|
---|
| 204 | my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
|
---|
| 205 | unsigned int STDCALL mysql_errno(MYSQL *mysql);
|
---|
| 206 | char * STDCALL mysql_error(MYSQL *mysql);
|
---|
| 207 | char * STDCALL mysql_info(MYSQL *mysql);
|
---|
| 208 | unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
|
---|
| 209 | const char * STDCALL mysql_character_set_name(MYSQL *mysql);
|
---|
[828] | 210 |
|
---|
[7882] | 211 | MYSQL * STDCALL mysql_init(MYSQL *mysql);
|
---|
| 212 | #ifdef HAVE_OPENSSL
|
---|
| 213 | int STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
|
---|
| 214 | const char *cert, const char *ca,
|
---|
| 215 | const char *capath);
|
---|
| 216 | char * STDCALL mysql_ssl_cipher(MYSQL *mysql);
|
---|
| 217 | int STDCALL mysql_ssl_clear(MYSQL *mysql);
|
---|
| 218 | #endif /* HAVE_OPENSSL */
|
---|
| 219 | MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
|
---|
| 220 | const char *user, const char *passwd);
|
---|
| 221 | my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user,
|
---|
| 222 | const char *passwd, const char *db);
|
---|
[828] | 223 | #if MYSQL_VERSION_ID >= 32200
|
---|
[7882] | 224 | MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
|
---|
| 225 | const char *user,
|
---|
| 226 | const char *passwd,
|
---|
| 227 | const char *db,
|
---|
| 228 | unsigned int port,
|
---|
| 229 | const char *unix_socket,
|
---|
| 230 | unsigned int clientflag);
|
---|
[828] | 231 | #else
|
---|
[7882] | 232 | MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
|
---|
| 233 | const char *user,
|
---|
| 234 | const char *passwd,
|
---|
| 235 | unsigned int port,
|
---|
| 236 | const char *unix_socket,
|
---|
| 237 | unsigned int clientflag);
|
---|
[828] | 238 | #endif
|
---|
[7882] | 239 | void STDCALL mysql_close(MYSQL *sock);
|
---|
| 240 | int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
|
---|
| 241 | int STDCALL mysql_query(MYSQL *mysql, const char *q);
|
---|
| 242 | int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
|
---|
| 243 | unsigned int length);
|
---|
| 244 | int STDCALL mysql_read_query_result(MYSQL *mysql);
|
---|
| 245 | int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
|
---|
| 246 | unsigned int length);
|
---|
| 247 | int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
|
---|
| 248 | int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
|
---|
| 249 | int STDCALL mysql_shutdown(MYSQL *mysql);
|
---|
| 250 | int STDCALL mysql_dump_debug_info(MYSQL *mysql);
|
---|
| 251 | int STDCALL mysql_refresh(MYSQL *mysql,
|
---|
| 252 | unsigned int refresh_options);
|
---|
| 253 | int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
|
---|
| 254 | int STDCALL mysql_ping(MYSQL *mysql);
|
---|
| 255 | char * STDCALL mysql_stat(MYSQL *mysql);
|
---|
| 256 | char * STDCALL mysql_get_server_info(MYSQL *mysql);
|
---|
| 257 | char * STDCALL mysql_get_client_info(void);
|
---|
| 258 | char * STDCALL mysql_get_host_info(MYSQL *mysql);
|
---|
| 259 | unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
|
---|
| 260 | MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
|
---|
| 261 | MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
|
---|
| 262 | MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
|
---|
| 263 | const char *wild);
|
---|
| 264 | MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
|
---|
| 265 | MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
|
---|
| 266 | MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
|
---|
| 267 | int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
|
---|
| 268 | const char *arg);
|
---|
| 269 | void STDCALL mysql_free_result(MYSQL_RES *result);
|
---|
| 270 | void STDCALL mysql_data_seek(MYSQL_RES *result,
|
---|
| 271 | my_ulonglong offset);
|
---|
[1936] | 272 | MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET);
|
---|
| 273 | MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
|
---|
[7882] | 274 | MYSQL_FIELD_OFFSET offset);
|
---|
| 275 | MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
|
---|
[1993] | 276 | unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
|
---|
[7882] | 277 | MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
|
---|
| 278 | unsigned long STDCALL mysql_escape_string(char *to,const char *from,
|
---|
| 279 | unsigned long from_length);
|
---|
| 280 | unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
|
---|
| 281 | char *to,const char *from,
|
---|
| 282 | unsigned long length);
|
---|
| 283 | void STDCALL mysql_debug(const char *debug);
|
---|
| 284 | char * STDCALL mysql_odbc_escape_string(MYSQL *mysql,
|
---|
| 285 | char *to,
|
---|
| 286 | unsigned long to_length,
|
---|
| 287 | const char *from,
|
---|
| 288 | unsigned long from_length,
|
---|
| 289 | void *param,
|
---|
| 290 | char *
|
---|
| 291 | (*extend_buffer)
|
---|
| 292 | (void *, char *to,
|
---|
| 293 | unsigned long *length));
|
---|
| 294 | void STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
|
---|
| 295 | unsigned int STDCALL mysql_thread_safe(void);
|
---|
[828] | 296 |
|
---|
[7882] | 297 |
|
---|
| 298 | #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
|
---|
| 299 |
|
---|
[828] | 300 | /* new api functions */
|
---|
| 301 |
|
---|
| 302 | #define HAVE_MYSQL_REAL_CONNECT
|
---|
| 303 |
|
---|
[7882] | 304 | #ifndef MYSQL_SERVER
|
---|
| 305 | #ifdef __cplusplus
|
---|
[828] | 306 | }
|
---|
| 307 | #endif
|
---|
| 308 | #endif
|
---|
[7882] | 309 |
|
---|
| 310 | #endif
|
---|