| 1 | /* Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
|
|---|
| 2 | This file is public domain and comes with NO WARRANTY of any kind */
|
|---|
| 3 |
|
|---|
| 4 | /* defines for libmysql */
|
|---|
| 5 |
|
|---|
| 6 | #ifndef _mysql_h
|
|---|
| 7 | #define _mysql_h
|
|---|
| 8 | #ifdef __cplusplus
|
|---|
| 9 | extern "C" {
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | #ifndef _global_h /* If not standard header */
|
|---|
| 13 | #include <sys/types.h>
|
|---|
| 14 | typedef char my_bool;
|
|---|
| 15 | #if !defined(WIN32)
|
|---|
| 16 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
|---|
| 17 | #define STDCALL _System
|
|---|
| 18 | #else
|
|---|
| 19 | #define STDCALL
|
|---|
| 20 | #endif
|
|---|
| 21 | #else
|
|---|
| 22 | #define STDCALL __stdcall
|
|---|
| 23 | #endif
|
|---|
| 24 | typedef char * gptr;
|
|---|
| 25 |
|
|---|
| 26 | #ifndef ST_USED_MEM_DEFINED
|
|---|
| 27 | #define ST_USED_MEM_DEFINED
|
|---|
| 28 | typedef struct st_used_mem { /* struct for once_alloc */
|
|---|
| 29 | struct st_used_mem *next; /* Next block in use */
|
|---|
| 30 | unsigned int left; /* memory left in block */
|
|---|
| 31 | unsigned int size; /* size of block */
|
|---|
| 32 | } USED_MEM;
|
|---|
| 33 | typedef struct st_mem_root {
|
|---|
| 34 | USED_MEM *free;
|
|---|
| 35 | USED_MEM *used;
|
|---|
| 36 | unsigned int min_malloc;
|
|---|
| 37 | unsigned int block_size;
|
|---|
| 38 | void (*error_handler)(void);
|
|---|
| 39 | } MEM_ROOT;
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| 42 | #ifndef my_socket_defined
|
|---|
| 43 | #ifdef WIN32
|
|---|
| 44 | #define my_socket SOCKET
|
|---|
| 45 | #else
|
|---|
| 46 | typedef int my_socket;
|
|---|
| 47 | #endif
|
|---|
| 48 | #endif
|
|---|
| 49 | #endif
|
|---|
| 50 | #include "mysql_com.h"
|
|---|
| 51 | #include "mysql_version.h"
|
|---|
| 52 |
|
|---|
| 53 | extern unsigned int mysql_port;
|
|---|
| 54 | extern char *mysql_unix_port;
|
|---|
| 55 |
|
|---|
| 56 | #define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
|
|---|
| 57 | #define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
|
|---|
| 58 | #define IS_BLOB(n) ((n) & BLOB_FLAG)
|
|---|
| 59 | #define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
|
|---|
| 60 |
|
|---|
| 61 | typedef struct st_mysql_field {
|
|---|
| 62 | char *name; /* Name of column */
|
|---|
| 63 | char *table; /* Table of column if column was a field */
|
|---|
| 64 | char *def; /* Default value (set by mysql_list_fields) */
|
|---|
| 65 | enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
|
|---|
| 66 | unsigned int length; /* Width of column */
|
|---|
| 67 | unsigned int max_length; /* Max width of selected set */
|
|---|
| 68 | unsigned int flags; /* Div flags */
|
|---|
| 69 | unsigned int decimals; /* Number of decimals in field */
|
|---|
| 70 | } MYSQL_FIELD;
|
|---|
| 71 |
|
|---|
| 72 | typedef char **MYSQL_ROW; /* return data as array of strings */
|
|---|
| 73 | typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
|
|---|
| 74 |
|
|---|
| 75 | #if defined(NO_CLIENT_LONG_LONG)
|
|---|
| 76 | typedef unsigned long my_ulonglong;
|
|---|
| 77 | #elif defined (WIN32)
|
|---|
| 78 | typedef unsigned __int64 my_ulonglong;
|
|---|
| 79 | #else
|
|---|
| 80 | typedef unsigned long long my_ulonglong;
|
|---|
| 81 | #endif
|
|---|
| 82 |
|
|---|
| 83 | #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
|
|---|
| 84 |
|
|---|
| 85 | typedef struct st_mysql_rows {
|
|---|
| 86 | struct st_mysql_rows *next; /* list of rows */
|
|---|
| 87 | MYSQL_ROW data;
|
|---|
| 88 | } MYSQL_ROWS;
|
|---|
| 89 |
|
|---|
| 90 | typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
|
|---|
| 91 |
|
|---|
| 92 | typedef struct st_mysql_data {
|
|---|
| 93 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
|---|
| 94 | unsigned long rows;
|
|---|
| 95 | unsigned long rows_;
|
|---|
| 96 | #else
|
|---|
| 97 | my_ulonglong rows;
|
|---|
| 98 | #endif
|
|---|
| 99 | unsigned int fields;
|
|---|
| 100 | MYSQL_ROWS *data;
|
|---|
| 101 | MEM_ROOT alloc;
|
|---|
| 102 | } MYSQL_DATA;
|
|---|
| 103 |
|
|---|
| 104 | struct st_mysql_options {
|
|---|
| 105 | unsigned int connect_timeout,client_flag;
|
|---|
| 106 | my_bool compress,named_pipe;
|
|---|
| 107 | unsigned int port;
|
|---|
| 108 | char *host,*init_command,*user,*password,*unix_socket,*db;
|
|---|
| 109 | char *my_cnf_file,*my_cnf_group;
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
|
|---|
| 113 | MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
|
|---|
| 114 | MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP };
|
|---|
| 115 |
|
|---|
| 116 | enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
|
|---|
| 117 | MYSQL_STATUS_USE_RESULT};
|
|---|
| 118 |
|
|---|
| 119 | typedef struct st_mysql {
|
|---|
| 120 | NET net; /* Communication parameters */
|
|---|
| 121 | char *host,*user,*passwd,*unix_socket,*server_version,*host_info,
|
|---|
| 122 | *info,*db;
|
|---|
| 123 | unsigned int port,client_flag,server_capabilities;
|
|---|
| 124 | unsigned int protocol_version;
|
|---|
| 125 | unsigned int field_count;
|
|---|
| 126 | unsigned long thread_id; /* Id for connection in server */
|
|---|
| 127 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
|---|
| 128 | unsigned long affected_rows;
|
|---|
| 129 | unsigned long _affected_rows;
|
|---|
| 130 | unsigned long insert_id; /* id if insert on table with NEXTNR */
|
|---|
| 131 | unsigned long _insert_id; /* id if insert on table with NEXTNR */
|
|---|
| 132 | unsigned long extra_info; /* Used by mysqlshow */
|
|---|
| 133 | unsigned long _extra_info; /* Used by mysqlshow */
|
|---|
| 134 | #else
|
|---|
| 135 | my_ulonglong affected_rows;
|
|---|
| 136 | my_ulonglong insert_id; /* id if insert on table with NEXTNR */
|
|---|
| 137 | my_ulonglong extra_info; /* Used by mysqlshow */
|
|---|
| 138 | #endif
|
|---|
| 139 |
|
|---|
| 140 | unsigned long packet_length;
|
|---|
| 141 | enum mysql_status status;
|
|---|
| 142 | MYSQL_FIELD *fields;
|
|---|
| 143 | MEM_ROOT field_alloc;
|
|---|
| 144 | my_bool free_me; /* If free in mysql_close */
|
|---|
| 145 | my_bool reconnect; /* set to 1 if automatic reconnect */
|
|---|
| 146 | struct st_mysql_options options;
|
|---|
| 147 | } MYSQL;
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | typedef struct st_mysql_res {
|
|---|
| 151 | #if defined(__IBMC__) || defined(__IBMCPP__)
|
|---|
| 152 | unsigned long row_count;
|
|---|
| 153 | unsigned long _row_count;
|
|---|
| 154 | #else
|
|---|
| 155 | my_ulonglong row_count;
|
|---|
| 156 | #endif
|
|---|
| 157 | unsigned int field_count, current_field;
|
|---|
| 158 | MYSQL_FIELD *fields;
|
|---|
| 159 | MYSQL_DATA *data;
|
|---|
| 160 | MYSQL_ROWS *data_cursor;
|
|---|
| 161 | MEM_ROOT field_alloc;
|
|---|
| 162 | MYSQL_ROW row; /* If unbuffered read */
|
|---|
| 163 | MYSQL_ROW current_row; /* buffer to current row */
|
|---|
| 164 | unsigned long *lengths; /* column lengths of current row */
|
|---|
| 165 | MYSQL *handle; /* for unbuffered reads */
|
|---|
| 166 | my_bool eof; /* Used my mysql_fetch_row */
|
|---|
| 167 | } MYSQL_RES;
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 | #define mysql_num_rows(res) (res)->row_count
|
|---|
| 171 | #define mysql_num_fields(res) (res)->field_count
|
|---|
| 172 | #define mysql_eof(res) (res)->eof
|
|---|
| 173 | #define mysql_fetch_field_direct(res,fieldnr) (&(res)->fields[fieldnr])
|
|---|
| 174 | #define mysql_fetch_fields(res) (res)->fields
|
|---|
| 175 | #define mysql_row_tell(res) (res)->data_cursor
|
|---|
| 176 | #define mysql_field_tell(res) (res)->current_field
|
|---|
| 177 |
|
|---|
| 178 | #define mysql_field_count(mysql) (mysql)->field_count
|
|---|
| 179 | #define mysql_affected_rows(mysql) (mysql)->affected_rows
|
|---|
| 180 | #define mysql_insert_id(mysql) (mysql)->insert_id
|
|---|
| 181 | #define mysql_error(mysql) (mysql)->net.last_error
|
|---|
| 182 | #define mysql_errno(mysql) (mysql)->net.last_errno
|
|---|
| 183 | #define mysql_info(mysql) (mysql)->info
|
|---|
| 184 | #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
|
|---|
| 185 | #define mysql_thread_id(mysql) (mysql)->thread_id
|
|---|
| 186 |
|
|---|
| 187 | MYSQL * STDCALL mysql_init(MYSQL *mysql);
|
|---|
| 188 | MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
|
|---|
| 189 | const char *user, const char *passwd);
|
|---|
| 190 | #if MYSQL_VERSION_ID >= 32200
|
|---|
| 191 | MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
|
|---|
| 192 | const char *user,
|
|---|
| 193 | const char *passwd,
|
|---|
| 194 | const char *db,
|
|---|
| 195 | unsigned int port,
|
|---|
| 196 | const char *unix_socket,
|
|---|
| 197 | unsigned int clientflag);
|
|---|
| 198 | #else
|
|---|
| 199 | MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
|
|---|
| 200 | const char *user,
|
|---|
| 201 | const char *passwd,
|
|---|
| 202 | unsigned int port,
|
|---|
| 203 | const char *unix_socket,
|
|---|
| 204 | unsigned int clientflag);
|
|---|
| 205 | #endif
|
|---|
| 206 | void STDCALL mysql_close(MYSQL *sock);
|
|---|
| 207 | int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
|
|---|
| 208 | int STDCALL mysql_query(MYSQL *mysql, const char *q);
|
|---|
| 209 | int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
|
|---|
| 210 | unsigned int length);
|
|---|
| 211 | int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
|
|---|
| 212 | int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
|
|---|
| 213 | int STDCALL mysql_shutdown(MYSQL *mysql);
|
|---|
| 214 | int STDCALL mysql_dump_debug_info(MYSQL *mysql);
|
|---|
| 215 | int STDCALL mysql_refresh(MYSQL *mysql,
|
|---|
| 216 | unsigned int refresh_options);
|
|---|
| 217 | int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
|
|---|
| 218 | int STDCALL mysql_ping(MYSQL *mysql);
|
|---|
| 219 | char * STDCALL mysql_stat(MYSQL *mysql);
|
|---|
| 220 | char * STDCALL mysql_get_server_info(MYSQL *mysql);
|
|---|
| 221 | char * STDCALL mysql_get_client_info(void);
|
|---|
| 222 | char * STDCALL mysql_get_host_info(MYSQL *mysql);
|
|---|
| 223 | unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
|
|---|
| 224 | MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
|
|---|
| 225 | MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
|
|---|
| 226 | MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
|
|---|
| 227 | const char *wild);
|
|---|
| 228 | MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
|
|---|
| 229 | MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
|
|---|
| 230 | MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
|
|---|
| 231 | int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
|
|---|
| 232 | const char *arg);
|
|---|
| 233 | void STDCALL mysql_free_result(MYSQL_RES *result);
|
|---|
| 234 | void STDCALL mysql_data_seek(MYSQL_RES *result,unsigned int offset);
|
|---|
| 235 | MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET);
|
|---|
| 236 | MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
|
|---|
| 237 | MYSQL_FIELD_OFFSET offset);
|
|---|
| 238 | MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
|
|---|
| 239 | unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
|
|---|
| 240 | MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result);
|
|---|
| 241 | unsigned int STDCALL mysql_escape_string(char *to,const char *from,
|
|---|
| 242 | unsigned int from_length);
|
|---|
| 243 | void STDCALL mysql_debug(const char *debug);
|
|---|
| 244 |
|
|---|
| 245 | /* new api functions */
|
|---|
| 246 |
|
|---|
| 247 | #define HAVE_MYSQL_REAL_CONNECT
|
|---|
| 248 |
|
|---|
| 249 | #ifdef __cplusplus
|
|---|
| 250 | }
|
|---|
| 251 | #endif
|
|---|
| 252 | #endif
|
|---|