root/trunk/dep/include/mysql/mysql_com.h @ 2

Revision 2, 17.0 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
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; version 2 of the License.
6
7   This program is distributed in the hope that it will be useful,
8   but WITHOUT ANY WARRANTY; without even the implied warranty of
9   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10   GNU General Public License for more details.
11
12   You should have received a copy of the GNU General Public License
13   along with this program; if not, write to the Free Software
14   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16/*
17** Common definition between mysql server & client
18*/
19
20#ifndef _mysql_com_h
21#define _mysql_com_h
22
23#define NAME_LEN        64              /* Field/table name length */
24#define HOSTNAME_LENGTH 60
25#define USERNAME_LENGTH 16
26#define SERVER_VERSION_LENGTH 60
27#define SQLSTATE_LENGTH 5
28
29/*
30  USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain
31  username and hostname parts of the user identifier with trailing zero in
32  MySQL standard format:
33  user_name_part@host_name_part\0
34*/
35#define USER_HOST_BUFF_SIZE HOSTNAME_LENGTH + USERNAME_LENGTH + 2
36
37#define LOCAL_HOST      "localhost"
38#define LOCAL_HOST_NAMEDPIPE "."
39
40
41#if defined(__WIN__) && !defined( _CUSTOMCONFIG_)
42#define MYSQL_NAMEDPIPE "MySQL"
43#define MYSQL_SERVICENAME "MySQL"
44#endif /* __WIN__ */
45
46/*
47  You should add new commands to the end of this list, otherwise old
48  servers won't be able to handle them as 'unsupported'.
49*/
50
51enum enum_server_command
52{
53  COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
54  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN, COM_STATISTICS,
55  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_DEBUG, COM_PING,
56  COM_TIME, COM_DELAYED_INSERT, COM_CHANGE_USER, COM_BINLOG_DUMP,
57  COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
58  COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
59  COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH,
60  /* don't forget to update const char *command_name[] in sql_parse.cc */
61
62  /* Must be last */
63  COM_END
64};
65
66
67/*
68  Length of random string sent by server on handshake; this is also length of
69  obfuscated password, recieved from client
70*/
71#define SCRAMBLE_LENGTH 20
72#define SCRAMBLE_LENGTH_323 8
73/* length of password stored in the db: new passwords are preceeded with '*' */
74#define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1)
75#define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2)
76
77
78#define NOT_NULL_FLAG   1               /* Field can't be NULL */
79#define PRI_KEY_FLAG    2               /* Field is part of a primary key */
80#define UNIQUE_KEY_FLAG 4               /* Field is part of a unique key */
81#define MULTIPLE_KEY_FLAG 8             /* Field is part of a key */
82#define BLOB_FLAG       16              /* Field is a blob */
83#define UNSIGNED_FLAG   32              /* Field is unsigned */
84#define ZEROFILL_FLAG   64              /* Field is zerofill */
85#define BINARY_FLAG     128             /* Field is binary   */
86
87/* The following are only sent to new clients */
88#define ENUM_FLAG       256             /* field is an enum */
89#define AUTO_INCREMENT_FLAG 512         /* field is a autoincrement field */
90#define TIMESTAMP_FLAG  1024            /* Field is a timestamp */
91#define SET_FLAG        2048            /* field is a set */
92#define NO_DEFAULT_VALUE_FLAG 4096      /* Field doesn't have default value */
93#define NUM_FLAG        32768           /* Field is num (for clients) */
94#define PART_KEY_FLAG   16384           /* Intern; Part of some key */
95#define GROUP_FLAG      32768           /* Intern: Group field */
96#define UNIQUE_FLAG     65536           /* Intern: Used by sql_yacc */
97#define BINCMP_FLAG     131072          /* Intern: Used by sql_yacc */
98
99#define REFRESH_GRANT           1       /* Refresh grant tables */
100#define REFRESH_LOG             2       /* Start on new log file */
101#define REFRESH_TABLES          4       /* close all tables */
102#define REFRESH_HOSTS           8       /* Flush host cache */
103#define REFRESH_STATUS          16      /* Flush status variables */
104#define REFRESH_THREADS         32      /* Flush thread cache */
105#define REFRESH_SLAVE           64      /* Reset master info and restart slave
106                                           thread */
107#define REFRESH_MASTER          128     /* Remove all bin logs in the index
108                                           and truncate the index */
109
110/* The following can't be set with mysql_refresh() */
111#define REFRESH_READ_LOCK       16384   /* Lock tables for read */
112#define REFRESH_FAST            32768   /* Intern flag */
113
114/* RESET (remove all queries) from query cache */
115#define REFRESH_QUERY_CACHE     65536
116#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
117#define REFRESH_DES_KEY_FILE    0x40000L
118#define REFRESH_USER_RESOURCES  0x80000L
119
120#define CLIENT_LONG_PASSWORD    1       /* new more secure passwords */
121#define CLIENT_FOUND_ROWS       2       /* Found instead of affected rows */
122#define CLIENT_LONG_FLAG        4       /* Get all column flags */
123#define CLIENT_CONNECT_WITH_DB  8       /* One can specify db on connect */
124#define CLIENT_NO_SCHEMA        16      /* Don't allow database.table.column */
125#define CLIENT_COMPRESS         32      /* Can use compression protocol */
126#define CLIENT_ODBC             64      /* Odbc client */
127#define CLIENT_LOCAL_FILES      128     /* Can use LOAD DATA LOCAL */
128#define CLIENT_IGNORE_SPACE     256     /* Ignore spaces before '(' */
129#define CLIENT_PROTOCOL_41      512     /* New 4.1 protocol */
130#define CLIENT_INTERACTIVE      1024    /* This is an interactive client */
131#define CLIENT_SSL              2048    /* Switch to SSL after handshake */
132#define CLIENT_IGNORE_SIGPIPE   4096    /* IGNORE sigpipes */
133#define CLIENT_TRANSACTIONS     8192    /* Client knows about transactions */
134#define CLIENT_RESERVED         16384   /* Old flag for 4.1 protocol  */
135#define CLIENT_SECURE_CONNECTION 32768  /* New 4.1 authentication */
136#define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
137#define CLIENT_MULTI_RESULTS    (1UL << 17) /* Enable/disable multi-results */
138
139#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
140#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
141
142#define SERVER_STATUS_IN_TRANS     1    /* Transaction has started */
143#define SERVER_STATUS_AUTOCOMMIT   2    /* Server in auto_commit mode */
144#define SERVER_MORE_RESULTS_EXISTS 8    /* Multi query - next query exists */
145#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
146#define SERVER_QUERY_NO_INDEX_USED      32
147/*
148  The server was able to fulfill the clients request and opened a
149  read-only non-scrollable cursor for a query. This flag comes
150  in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
151*/
152#define SERVER_STATUS_CURSOR_EXISTS 64
153/*
154  This flag is sent when a read-only cursor is exhausted, in reply to
155  COM_STMT_FETCH command.
156*/
157#define SERVER_STATUS_LAST_ROW_SENT 128
158#define SERVER_STATUS_DB_DROPPED        256 /* A database was dropped */
159#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
160
161#define MYSQL_ERRMSG_SIZE       512
162#define NET_READ_TIMEOUT        30              /* Timeout on read */
163#define NET_WRITE_TIMEOUT       60              /* Timeout on write */
164#define NET_WAIT_TIMEOUT        8*60*60         /* Wait for new query */
165
166#define ONLY_KILL_QUERY         1
167
168struct st_vio;                                  /* Only C */
169typedef struct st_vio Vio;
170
171#define MAX_TINYINT_WIDTH       3       /* Max width for a TINY w.o. sign */
172#define MAX_SMALLINT_WIDTH      5       /* Max width for a SHORT w.o. sign */
173#define MAX_MEDIUMINT_WIDTH     8       /* Max width for a INT24 w.o. sign */
174#define MAX_INT_WIDTH           10      /* Max width for a LONG w.o. sign */
175#define MAX_BIGINT_WIDTH        20      /* Max width for a LONGLONG */
176#define MAX_CHAR_WIDTH          255     /* Max length for a CHAR colum */
177#define MAX_BLOB_WIDTH          8192    /* Default width for blob */
178
179typedef struct st_net {
180#if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
181  Vio* vio;
182  unsigned char *buff,*buff_end,*write_pos,*read_pos;
183  my_socket fd;                                 /* For Perl DBI/dbd */
184  unsigned long max_packet,max_packet_size;
185  unsigned int pkt_nr,compress_pkt_nr;
186  unsigned int write_timeout, read_timeout, retry_count;
187  int fcntl;
188  my_bool compress;
189  /*
190    The following variable is set if we are doing several queries in one
191    command ( as in LOAD TABLE ... FROM MASTER ),
192    and do not want to confuse the client with OK at the wrong time
193  */
194  unsigned long remain_in_buf,length, buf_length, where_b;
195  unsigned int *return_status;
196  unsigned char reading_or_writing;
197  char save_char;
198  my_bool no_send_ok;  /* For SPs and other things that do multiple stmts */
199  my_bool no_send_eof; /* For SPs' first version read-only cursors */
200  /*
201    Set if OK packet is already sent, and we do not need to send error
202    messages
203  */
204  my_bool no_send_error;
205  /*
206    Pointer to query object in query cache, do not equal NULL (0) for
207    queries in cache that have not stored its results yet
208  */
209#endif
210  char last_error[MYSQL_ERRMSG_SIZE], sqlstate[SQLSTATE_LENGTH+1];
211  unsigned int last_errno;
212  unsigned char error;
213
214  /*
215    'query_cache_query' should be accessed only via query cache
216    functions and methods to maintain proper locking.
217  */
218  gptr query_cache_query;
219
220  my_bool report_error; /* We should report error (we have unreported error) */
221  my_bool return_errno;
222} NET;
223
224#define packet_error (~(unsigned long) 0)
225
226enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
227                        MYSQL_TYPE_SHORT,  MYSQL_TYPE_LONG,
228                        MYSQL_TYPE_FLOAT,  MYSQL_TYPE_DOUBLE,
229                        MYSQL_TYPE_NULL,   MYSQL_TYPE_TIMESTAMP,
230                        MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24,
231                        MYSQL_TYPE_DATE,   MYSQL_TYPE_TIME,
232                        MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
233                        MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
234                        MYSQL_TYPE_BIT,
235                        MYSQL_TYPE_NEWDECIMAL=246,
236                        MYSQL_TYPE_ENUM=247,
237                        MYSQL_TYPE_SET=248,
238                        MYSQL_TYPE_TINY_BLOB=249,
239                        MYSQL_TYPE_MEDIUM_BLOB=250,
240                        MYSQL_TYPE_LONG_BLOB=251,
241                        MYSQL_TYPE_BLOB=252,
242                        MYSQL_TYPE_VAR_STRING=253,
243                        MYSQL_TYPE_STRING=254,
244                        MYSQL_TYPE_GEOMETRY=255
245
246};
247
248/* For backward compatibility */
249#define CLIENT_MULTI_QUERIES    CLIENT_MULTI_STATEMENTS   
250#define FIELD_TYPE_DECIMAL     MYSQL_TYPE_DECIMAL
251#define FIELD_TYPE_NEWDECIMAL  MYSQL_TYPE_NEWDECIMAL
252#define FIELD_TYPE_TINY        MYSQL_TYPE_TINY
253#define FIELD_TYPE_SHORT       MYSQL_TYPE_SHORT
254#define FIELD_TYPE_LONG        MYSQL_TYPE_LONG
255#define FIELD_TYPE_FLOAT       MYSQL_TYPE_FLOAT
256#define FIELD_TYPE_DOUBLE      MYSQL_TYPE_DOUBLE
257#define FIELD_TYPE_NULL        MYSQL_TYPE_NULL
258#define FIELD_TYPE_TIMESTAMP   MYSQL_TYPE_TIMESTAMP
259#define FIELD_TYPE_LONGLONG    MYSQL_TYPE_LONGLONG
260#define FIELD_TYPE_INT24       MYSQL_TYPE_INT24
261#define FIELD_TYPE_DATE        MYSQL_TYPE_DATE
262#define FIELD_TYPE_TIME        MYSQL_TYPE_TIME
263#define FIELD_TYPE_DATETIME    MYSQL_TYPE_DATETIME
264#define FIELD_TYPE_YEAR        MYSQL_TYPE_YEAR
265#define FIELD_TYPE_NEWDATE     MYSQL_TYPE_NEWDATE
266#define FIELD_TYPE_ENUM        MYSQL_TYPE_ENUM
267#define FIELD_TYPE_SET         MYSQL_TYPE_SET
268#define FIELD_TYPE_TINY_BLOB   MYSQL_TYPE_TINY_BLOB
269#define FIELD_TYPE_MEDIUM_BLOB MYSQL_TYPE_MEDIUM_BLOB
270#define FIELD_TYPE_LONG_BLOB   MYSQL_TYPE_LONG_BLOB
271#define FIELD_TYPE_BLOB        MYSQL_TYPE_BLOB
272#define FIELD_TYPE_VAR_STRING  MYSQL_TYPE_VAR_STRING
273#define FIELD_TYPE_STRING      MYSQL_TYPE_STRING
274#define FIELD_TYPE_CHAR        MYSQL_TYPE_TINY
275#define FIELD_TYPE_INTERVAL    MYSQL_TYPE_ENUM
276#define FIELD_TYPE_GEOMETRY    MYSQL_TYPE_GEOMETRY
277#define FIELD_TYPE_BIT         MYSQL_TYPE_BIT
278
279
280/* Shutdown/kill enums and constants */ 
281
282/* Bits for THD::killable. */
283#define MYSQL_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
284#define MYSQL_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
285#define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
286#define MYSQL_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
287
288enum mysql_enum_shutdown_level {
289  /*
290    We want levels to be in growing order of hardness (because we use number
291    comparisons). Note that DEFAULT does not respect the growing property, but
292    it's ok.
293  */
294  SHUTDOWN_DEFAULT = 0,
295  /* wait for existing connections to finish */
296  SHUTDOWN_WAIT_CONNECTIONS= MYSQL_SHUTDOWN_KILLABLE_CONNECT,
297  /* wait for existing trans to finish */
298  SHUTDOWN_WAIT_TRANSACTIONS= MYSQL_SHUTDOWN_KILLABLE_TRANS,
299  /* wait for existing updates to finish (=> no partial MyISAM update) */
300  SHUTDOWN_WAIT_UPDATES= MYSQL_SHUTDOWN_KILLABLE_UPDATE,
301  /* flush InnoDB buffers and other storage engines' buffers*/
302  SHUTDOWN_WAIT_ALL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1),
303  /* don't flush InnoDB buffers, flush other storage engines' buffers*/
304  SHUTDOWN_WAIT_CRITICAL_BUFFERS= (MYSQL_SHUTDOWN_KILLABLE_UPDATE << 1) + 1,
305  /* Now the 2 levels of the KILL command */
306#if MYSQL_VERSION_ID >= 50000
307  KILL_QUERY= 254,
308#endif
309  KILL_CONNECTION= 255
310};
311
312
313enum enum_cursor_type
314{
315  CURSOR_TYPE_NO_CURSOR= 0,
316  CURSOR_TYPE_READ_ONLY= 1,
317  CURSOR_TYPE_FOR_UPDATE= 2,
318  CURSOR_TYPE_SCROLLABLE= 4
319};
320
321
322/* options for mysql_set_option */
323enum enum_mysql_set_option
324{
325  MYSQL_OPTION_MULTI_STATEMENTS_ON,
326  MYSQL_OPTION_MULTI_STATEMENTS_OFF
327};
328
329#define net_new_transaction(net) ((net)->pkt_nr=0)
330
331#ifdef __cplusplus
332extern "C" {
333#endif
334
335my_bool my_net_init(NET *net, Vio* vio);
336void    my_net_local_init(NET *net);
337void    net_end(NET *net);
338void    net_clear(NET *net);
339my_bool net_realloc(NET *net, unsigned long length);
340my_bool net_flush(NET *net);
341my_bool my_net_write(NET *net,const char *packet,unsigned long len);
342my_bool net_write_command(NET *net,unsigned char command,
343                          const char *header, unsigned long head_len,
344                          const char *packet, unsigned long len);
345int     net_real_write(NET *net,const char *packet,unsigned long len);
346unsigned long my_net_read(NET *net);
347
348#ifdef _global_h
349void my_net_set_write_timeout(NET *net, uint timeout);
350void my_net_set_read_timeout(NET *net, uint timeout);
351#endif
352
353/*
354  The following function is not meant for normal usage
355  Currently it's used internally by manager.c
356*/
357struct sockaddr;
358int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
359               unsigned int timeout);
360
361struct rand_struct {
362  unsigned long seed1,seed2,max_value;
363  double max_value_dbl;
364};
365
366#ifdef __cplusplus
367}
368#endif
369
370  /* The following is for user defined functions */
371
372enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
373                  DECIMAL_RESULT};
374
375typedef struct st_udf_args
376{
377  unsigned int arg_count;               /* Number of arguments */
378  enum Item_result *arg_type;           /* Pointer to item_results */
379  char **args;                          /* Pointer to argument */
380  unsigned long *lengths;               /* Length of string arguments */
381  char *maybe_null;                     /* Set to 1 for all maybe_null args */
382  char **attributes;                    /* Pointer to attribute name */
383  unsigned long *attribute_lengths;     /* Length of attribute arguments */
384} UDF_ARGS;
385
386  /* This holds information about the result */
387
388typedef struct st_udf_init
389{
390  my_bool maybe_null;          /* 1 if function can return NULL */
391  unsigned int decimals;       /* for real functions */
392  unsigned long max_length;    /* For string functions */
393  char *ptr;                   /* free pointer for function data */
394  my_bool const_item;          /* 1 if function always returns the same value */
395} UDF_INIT;
396/*
397  TODO: add a notion for determinism of the UDF.
398  See Item_udf_func::update_used_tables ()
399*/
400
401  /* Constants when using compression */
402#define NET_HEADER_SIZE 4               /* standard header size */
403#define COMP_HEADER_SIZE 3              /* compression header extra size */
404
405  /* Prototypes to password functions */
406
407#ifdef __cplusplus
408extern "C" {
409#endif
410
411/*
412  These functions are used for authentication by client and server and
413  implemented in sql/password.c
414*/
415
416void randominit(struct rand_struct *, unsigned long seed1,
417                unsigned long seed2);
418double my_rnd(struct rand_struct *);
419void create_random_string(char *to, unsigned int length, struct rand_struct *rand_st);
420
421void hash_password(unsigned long *to, const char *password, unsigned int password_len);
422void make_scrambled_password_323(char *to, const char *password);
423void scramble_323(char *to, const char *message, const char *password);
424my_bool check_scramble_323(const char *, const char *message,
425                           unsigned long *salt);
426void get_salt_from_password_323(unsigned long *res, const char *password);
427void make_password_from_salt_323(char *to, const unsigned long *salt);
428
429void make_scrambled_password(char *to, const char *password);
430void scramble(char *to, const char *message, const char *password);
431my_bool check_scramble(const char *reply, const char *message,
432                       const unsigned char *hash_stage2);
433void get_salt_from_password(unsigned char *res, const char *password);
434void make_password_from_salt(char *to, const unsigned char *hash_stage2);
435char *octet2hex(char *to, const char *str, unsigned int len);
436
437/* end of password.c */
438
439char *get_tty_password(char *opt_message);
440const char *mysql_errno_to_sqlstate(unsigned int mysql_errno);
441
442/* Some other useful functions */
443
444my_bool my_init(void);
445extern int modify_defaults_file(const char *file_location, const char *option,
446                                const char *option_value,
447                                const char *section_name, int remove_option);
448int load_defaults(const char *conf_file, const char **groups,
449                  int *argc, char ***argv);
450my_bool my_thread_init(void);
451void my_thread_end(void);
452
453#ifdef _global_h
454ulong STDCALL net_field_length(uchar **packet);
455my_ulonglong net_field_length_ll(uchar **packet);
456char *net_store_length(char *pkg, ulonglong length);
457#endif
458
459#ifdef __cplusplus
460}
461#endif
462
463#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
464#define MYSQL_STMT_HEADER       4
465#define MYSQL_LONG_DATA_HEADER  6
466
467#endif
Note: See TracBrowser for help on using the browser.