source: trunk/tools/database/mysql/mysql.h@ 828

Last change on this file since 828 was 828, checked in by bird, 26 years ago

MySQL v3.21.33b libraryies and headers.

File size: 6.7 KB
Line 
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
9extern "C" {
10#endif
11
12#ifndef _global_h /* If not standard header */
13#include <sys/types.h>
14typedef char my_bool;
15#if !defined(__WIN32__) && !defined(WIN32)
16#define STDCALL
17typedef char byte;
18#else
19#define STDCALL __stdcall
20#endif
21typedef char * gptr;
22
23#ifndef ST_USED_MEM_DEFINED
24#define ST_USED_MEM_DEFINED
25typedef struct st_used_mem { /* struct for once_alloc */
26 struct st_used_mem *next; /* Next block in use */
27 unsigned int left; /* memory left in block */
28 unsigned int size; /* size of block */
29} USED_MEM;
30typedef struct st_mem_root {
31 USED_MEM *free;
32 USED_MEM *used;
33 unsigned int min_malloc;
34 unsigned int block_size;
35 void (*error_handler)(void);
36} MEM_ROOT;
37#endif
38
39#ifndef Socket_defined
40#ifdef __WIN32__
41#define Socket SOCKET
42#else
43typedef int Socket;
44#endif
45#endif
46#endif
47#include "mysql_com.h"
48#include "mysql_version.h"
49
50extern unsigned int mysql_port;
51extern char *mysql_unix_port;
52
53#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
54#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
55#define IS_BLOB(n) ((n) & BLOB_FLAG)
56#define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
57
58typedef struct st_mysql_field {
59 char *name; /* Name of column */
60 char *table; /* Table of column if column was a field */
61 char *def; /* Default value (set by mysql_list_fields) */
62 enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
63 unsigned int length; /* Width of column */
64 unsigned int max_length; /* Max width of selected set */
65 unsigned int flags; /* Div flags */
66 unsigned int decimals; /* Number of decimals in field */
67} MYSQL_FIELD;
68
69typedef byte **MYSQL_ROW; /* return data as array of strings */
70typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
71
72typedef struct st_mysql_rows {
73 struct st_mysql_rows *next; /* list of rows */
74 MYSQL_ROW data;
75} MYSQL_ROWS;
76
77typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
78
79typedef struct st_mysql_data {
80 unsigned int rows;
81 unsigned int fields;
82 MYSQL_ROWS *data;
83 MEM_ROOT alloc;
84} MYSQL_DATA;
85
86enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
87 MYSQL_STATUS_USE_RESULT};
88
89typedef struct st_mysql {
90 NET net; /* Communication parameters */
91 char *host,*user,*passwd,*unix_socket,*server_version,*host_info,
92 *info,*db;
93 unsigned int port,client_flag,server_capabilities;
94 unsigned int protocol_version;
95 unsigned int field_count;
96 unsigned long thread_id; /* Id for connection in server */
97 unsigned long affected_rows;
98 unsigned long insert_id; /* id if insert on table with NEXTNR */
99 unsigned long extra_info; /* Used by mysqlshow */
100 enum mysql_status status;
101 MYSQL_FIELD *fields;
102 MEM_ROOT field_alloc;
103 my_bool free_me; /* If free in mysql_close */
104 my_bool reconnect; /* set to 1 if automatic reconnect */
105} MYSQL;
106
107
108typedef struct st_mysql_res {
109 unsigned long row_count;
110 unsigned int field_count, current_field;
111 MYSQL_FIELD *fields;
112 MYSQL_DATA *data;
113 MYSQL_ROWS *data_cursor;
114 MEM_ROOT field_alloc;
115 MYSQL_ROW row; /* If unbuffered read */
116 MYSQL_ROW current_row; /* buffer to current row */
117 unsigned int *lengths; /* column lengths of current row */
118 MYSQL *handle; /* for unbuffered reads */
119 my_bool eof; /* Used my mysql_fetch_row */
120} MYSQL_RES;
121
122
123#define mysql_num_rows(res) (res)->row_count
124#define mysql_num_fields(res) (res)->field_count
125#define mysql_eof(res) (res)->eof
126#define mysql_fetch_field_direct(res,fieldnr) ((res)->fields[fieldnr])
127#define mysql_fetch_fields(res) (res)->fields
128#define mysql_row_tell(res) (res)->data_cursor
129#define mysql_field_tell(res) (res)->current_field
130
131#define mysql_affected_rows(mysql) (mysql)->affected_rows
132#define mysql_insert_id(mysql) (mysql)->insert_id
133#define mysql_error(mysql) (mysql)->net.last_error
134#define mysql_errno(mysql) (mysql)->net.last_errno
135#define mysql_info(mysql) (mysql)->info
136#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
137#define mysql_thread_id(mysql) (mysql)->thread_id
138
139 /* void STDCALL mysql_init(MYSQL *mysql); */
140MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host,
141 const char *user, const char *passwd);
142#if MYSQL_VERSION_ID >= 32200
143MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
144 const char *user,
145 const char *passwd,
146 const char *db,
147 unsigned int port,
148 const char *unix_socket,
149 unsigned int clientflag);
150#else
151MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
152 const char *user,
153 const char *passwd,
154 unsigned int port,
155 const char *unix_socket,
156 unsigned int clientflag);
157#endif
158void STDCALL mysql_close(MYSQL *sock);
159int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
160int STDCALL mysql_query(MYSQL *mysql, const char *q);
161int STDCALL mysql_real_query(MYSQL *mysql, const char *q,
162 unsigned int length);
163int STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
164int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
165int STDCALL mysql_shutdown(MYSQL *mysql);
166int STDCALL mysql_dump_debug_info(MYSQL *mysql);
167int STDCALL mysql_refresh(MYSQL *mysql,
168 unsigned int refresh_options);
169int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
170char * STDCALL mysql_stat(MYSQL *mysql);
171char * STDCALL mysql_get_server_info(MYSQL *mysql);
172char * STDCALL mysql_get_client_info(void);
173char * STDCALL mysql_get_host_info(MYSQL *mysql);
174unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql);
175MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
176MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
177MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
178 const char *wild);
179MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql);
180MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql);
181MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
182void STDCALL mysql_free_result(MYSQL_RES *result);
183void STDCALL mysql_data_seek(MYSQL_RES *mysql,unsigned int offset);
184MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *mysql, MYSQL_ROW_OFFSET);
185MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *mysql,
186 MYSQL_FIELD_OFFSET offset);
187MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *mysql);
188unsigned int * STDCALL mysql_fetch_lengths(MYSQL_RES *mysql);
189MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *handle);
190unsigned int STDCALL mysql_escape_string(char *to,const char *from,
191 unsigned int from_length);
192void STDCALL mysql_debug(char *debug);
193
194/* new api functions */
195
196#define HAVE_MYSQL_REAL_CONNECT
197
198#ifdef __cplusplus
199}
200#endif
201#endif
Note: See TracBrowser for help on using the repository browser.