home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / mysql-c.zip / mysql.h < prev    next >
C/C++ Source or Header  |  1999-12-18  |  8KB  |  235 lines

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