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