home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 Autumn / INTERNET109.ISO / pc / software / windows / building / mysql / data1.cab / Development / include / mysql_com.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-08-03  |  8.9 KB  |  257 lines

  1. /* Copyright (C) 2000 MySQL AB
  2.  
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2 of the License, or
  6.    (at your option) any later version.
  7.  
  8.    This program 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
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  16.  
  17. /*
  18. ** Common definition between mysql server & client
  19. */
  20.  
  21. #ifndef _mysql_com_h
  22. #define _mysql_com_h
  23.  
  24. #define NAME_LEN    64        /* Field/table name length */
  25. #define HOSTNAME_LENGTH 60
  26. #define USERNAME_LENGTH 16
  27. #define SERVER_VERSION_LENGTH 60
  28.  
  29. #define LOCAL_HOST    "localhost"
  30. #define LOCAL_HOST_NAMEDPIPE "."
  31.  
  32. #if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
  33. #define MYSQL_NAMEDPIPE "MySQL"
  34. #define MYSQL_SERVICENAME "MySql"
  35. #endif /* __WIN__ */
  36.  
  37. enum enum_server_command {
  38.   COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
  39.   COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN,  COM_STATISTICS,
  40.   COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
  41.   COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
  42.   COM_TABLE_DUMP,  COM_CONNECT_OUT, COM_REGISTER_SLAVE,
  43.   COM_END                    /* Must be last! */
  44. };
  45.  
  46. #define NOT_NULL_FLAG    1        /* Field can't be NULL */
  47. #define PRI_KEY_FLAG    2        /* Field is part of a primary key */
  48. #define UNIQUE_KEY_FLAG 4        /* Field is part of a unique key */
  49. #define MULTIPLE_KEY_FLAG 8        /* Field is part of a key */
  50. #define BLOB_FLAG    16        /* Field is a blob */
  51. #define UNSIGNED_FLAG    32        /* Field is unsigned */
  52. #define ZEROFILL_FLAG    64        /* Field is zerofill */
  53. #define BINARY_FLAG    128
  54. /* The following are only sent to new clients */
  55. #define ENUM_FLAG    256        /* field is an enum */
  56. #define AUTO_INCREMENT_FLAG 512        /* field is a autoincrement field */
  57. #define TIMESTAMP_FLAG    1024        /* Field is a timestamp */
  58. #define SET_FLAG    2048        /* field is a set */
  59. #define NUM_FLAG    32768        /* Field is num (for clients) */
  60. #define PART_KEY_FLAG    16384        /* Intern; Part of some key */
  61. #define GROUP_FLAG    32768        /* Intern: Group field */
  62. #define UNIQUE_FLAG    65536        /* Intern: Used by sql_yacc */
  63.  
  64. #define REFRESH_GRANT        1    /* Refresh grant tables */
  65. #define REFRESH_LOG        2    /* Start on new log file */
  66. #define REFRESH_TABLES        4    /* close all tables */
  67. #define REFRESH_HOSTS        8    /* Flush host cache */
  68. #define REFRESH_STATUS        16    /* Flush status variables */
  69. #define REFRESH_THREADS        32    /* Flush thread cache */
  70. #define REFRESH_SLAVE           64      /* Reset master info and restart slave
  71.                        thread */
  72. #define REFRESH_MASTER          128     /* Remove all bin logs in the index
  73.                        and truncate the index */
  74.  
  75. /* The following can't be set with mysql_refresh() */
  76. #define REFRESH_READ_LOCK    16384    /* Lock tables for read */
  77. #define REFRESH_FAST        32768    /* Intern flag */
  78.  
  79. /* RESET (remove all queries) from query cache */
  80. #define REFRESH_QUERY_CACHE    65536
  81. #define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
  82. #define REFRESH_DES_KEY_FILE    0x40000L
  83. #define REFRESH_USER_RESOURCES    0x80000L
  84.  
  85. #define CLIENT_LONG_PASSWORD    1    /* new more secure passwords */
  86. #define CLIENT_FOUND_ROWS    2    /* Found instead of affected rows */
  87. #define CLIENT_LONG_FLAG    4    /* Get all column flags */
  88. #define CLIENT_CONNECT_WITH_DB    8    /* One can specify db on connect */
  89. #define CLIENT_NO_SCHEMA    16    /* Don't allow database.table.column */
  90. #define CLIENT_COMPRESS        32    /* Can use compression protocol */
  91. #define CLIENT_ODBC        64    /* Odbc client */
  92. #define CLIENT_LOCAL_FILES    128    /* Can use LOAD DATA LOCAL */
  93. #define CLIENT_IGNORE_SPACE    256    /* Ignore spaces before '(' */
  94. #define CLIENT_INTERACTIVE    1024    /* This is an interactive client */
  95. #define CLIENT_SSL              2048     /* Switch to SSL after handshake */
  96. #define CLIENT_IGNORE_SIGPIPE   4096     /* IGNORE sigpipes */
  97. #define CLIENT_TRANSACTIONS    8192    /* Client knows about transactions */
  98.  
  99. #define SERVER_STATUS_IN_TRANS  1    /* Transaction has started */
  100. #define SERVER_STATUS_AUTOCOMMIT 2    /* Server in auto_commit mode */
  101.  
  102. #define MYSQL_ERRMSG_SIZE    200
  103. #define NET_READ_TIMEOUT    30        /* Timeout on read */
  104. #define NET_WRITE_TIMEOUT    60        /* Timeout on write */
  105. #define NET_WAIT_TIMEOUT    8*60*60        /* Wait for new query */
  106.  
  107. struct st_vio;                    /* Only C */
  108. typedef struct st_vio Vio;
  109.  
  110. #define MAX_CHAR_WIDTH        255    /* Max length for a CHAR colum */
  111. #define MAX_BLOB_WIDTH        8192    /* Default width for blob */
  112.  
  113. typedef struct st_net {
  114.   Vio* vio;
  115.   unsigned char *buff,*buff_end,*write_pos,*read_pos;
  116.   my_socket fd;                    /* For Perl DBI/dbd */
  117.   unsigned long max_packet,max_packet_size;
  118.   unsigned int last_errno,pkt_nr,compress_pkt_nr;
  119.   unsigned int write_timeout, read_timeout, retry_count;
  120.   int fcntl;
  121.   char last_error[MYSQL_ERRMSG_SIZE];
  122.   unsigned char error;
  123.   my_bool return_errno,compress;
  124.   /*
  125.     The following variable is set if we are doing several queries in one
  126.     command ( as in LOAD TABLE ... FROM MASTER ),
  127.     and do not want to confuse the client with OK at the wrong time
  128.   */
  129.   unsigned long remain_in_buf,length, buf_length, where_b;
  130.   unsigned int *return_status;
  131.   unsigned char reading_or_writing;
  132.   char save_char;
  133.   my_bool no_send_ok;
  134.   gptr query_cache_query;
  135. } NET;
  136.  
  137. #define packet_error (~(unsigned long) 0)
  138.  
  139. enum enum_field_types { FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
  140.             FIELD_TYPE_SHORT,  FIELD_TYPE_LONG,
  141.             FIELD_TYPE_FLOAT,  FIELD_TYPE_DOUBLE,
  142.             FIELD_TYPE_NULL,   FIELD_TYPE_TIMESTAMP,
  143.             FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
  144.             FIELD_TYPE_DATE,   FIELD_TYPE_TIME,
  145.             FIELD_TYPE_DATETIME, FIELD_TYPE_YEAR,
  146.             FIELD_TYPE_NEWDATE,
  147.             FIELD_TYPE_ENUM=247,
  148.             FIELD_TYPE_SET=248,
  149.             FIELD_TYPE_TINY_BLOB=249,
  150.             FIELD_TYPE_MEDIUM_BLOB=250,
  151.             FIELD_TYPE_LONG_BLOB=251,
  152.             FIELD_TYPE_BLOB=252,
  153.             FIELD_TYPE_VAR_STRING=253,
  154.             FIELD_TYPE_STRING=254,
  155.             FIELD_TYPE_GEOMETRY=255
  156. };
  157.  
  158. #define FIELD_TYPE_CHAR FIELD_TYPE_TINY        /* For compability */
  159. #define FIELD_TYPE_INTERVAL FIELD_TYPE_ENUM    /* For compability */
  160.  
  161. #define net_new_transaction(net) ((net)->pkt_nr=0)
  162.  
  163. #ifdef __cplusplus
  164. extern "C" {
  165. #endif
  166.  
  167. int    my_net_init(NET *net, Vio* vio);
  168. void    my_net_local_init(NET *net);
  169. void    net_end(NET *net);
  170. void    net_clear(NET *net);
  171. int    net_flush(NET *net);
  172. int    my_net_write(NET *net,const char *packet,unsigned long len);
  173. int    net_write_command(NET *net,unsigned char command,const char *packet,
  174.               unsigned long len);
  175. int    net_real_write(NET *net,const char *packet,unsigned long len);
  176. unsigned long my_net_read(NET *net);
  177.  
  178. /* The following function is not meant for normal usage */
  179. struct sockaddr;
  180. int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
  181.            unsigned int timeout);
  182.  
  183. struct rand_struct {
  184.   unsigned long seed1,seed2,max_value;
  185.   double max_value_dbl;
  186. };
  187.  
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191.  
  192.   /* The following is for user defined functions */
  193.  
  194. enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT};
  195.  
  196. typedef struct st_udf_args
  197. {
  198.   unsigned int arg_count;        /* Number of arguments */
  199.   enum Item_result *arg_type;        /* Pointer to item_results */
  200.   char **args;                /* Pointer to argument */
  201.   unsigned long *lengths;        /* Length of string arguments */
  202.   char *maybe_null;            /* Set to 1 for all maybe_null args */
  203. } UDF_ARGS;
  204.  
  205.   /* This holds information about the result */
  206.  
  207. typedef struct st_udf_init
  208. {
  209.   my_bool maybe_null;            /* 1 if function can return NULL */
  210.   unsigned int decimals;        /* for real functions */
  211.   unsigned long max_length;        /* For string functions */
  212.   char      *ptr;                /* free pointer for function data */
  213.   my_bool const_item;            /* 0 if result is independent of arguments */
  214. } UDF_INIT;
  215.  
  216.   /* Constants when using compression */
  217. #define NET_HEADER_SIZE 4        /* standard header size */
  218. #define COMP_HEADER_SIZE 3        /* compression header extra size */
  219.  
  220.   /* Prototypes to password functions */
  221.  
  222. #ifdef __cplusplus
  223. extern "C" {
  224. #endif
  225.  
  226. extern unsigned long max_allowed_packet;
  227. extern unsigned long net_buffer_length;
  228.  
  229. void randominit(struct rand_struct *,unsigned long seed1,
  230.         unsigned long seed2);
  231. double my_rnd(struct rand_struct *);
  232. void make_scrambled_password(char *to,const char *password);
  233. void get_salt_from_password(unsigned long *res,const char *password);
  234. void make_password_from_salt(char *to, unsigned long *hash_res);
  235. char *scramble(char *to,const char *message,const char *password,
  236.            my_bool old_ver);
  237. my_bool check_scramble(const char *, const char *message,
  238.                unsigned long *salt,my_bool old_ver);
  239. char *get_tty_password(char *opt_message);
  240. void hash_password(unsigned long *result, const char *password);
  241.  
  242. /* Some other useful functions */
  243.  
  244. void my_init(void);
  245. void load_defaults(const char *conf_file, const char **groups,
  246.            int *argc, char ***argv);
  247. my_bool my_thread_init(void);
  248. void my_thread_end(void);
  249.  
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253.  
  254. #define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
  255.  
  256. #endif
  257.