~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/common.h

  • Committer: Monty Taylor
  • Date: 2008-12-13 00:15:23 UTC
  • mfrom: (642.1.24 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 676.
  • Revision ID: monty@inaugust.com-20081213001523-5eh5tsaunt0yqgl9
MergedĀ fromĀ Lee.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
** Common definition between mysql server & client
22
22
*/
23
23
 
24
 
#ifndef DRIZZLED_COMMON_H
25
 
#define DRIZZLED_COMMON_H
 
24
#ifndef DRIZZLED_DRIZZLE_COMMON_H
 
25
#define DRIZZLED_DRIZZLE_COMMON_H
26
26
 
27
27
#include <unistd.h>
28
28
#include <stdint.h>
29
29
#include <drizzled/korr.h>
30
30
 
 
31
#if !defined(__cplusplus)
 
32
# include <stdbool.h>
 
33
#endif
 
34
 
31
35
/*
32
36
   This is included in the server and in the client.
33
37
   Options for select set by the yacc parser (stored in lex->options).
38
42
   values, or it will break replication between version.
39
43
 
40
44
   context is encoded as following:
41
 
   SELECT - Select_Lex_Node::options
 
45
   SELECT - SELECT_LEX_NODE::options
42
46
   THD    - THD::options
43
47
   intern - neither. used only as
44
48
            func(..., select_node->options | thd->options | OPTION_XXX, ...)
55
59
#define SELECT_NO_JOIN_CACHE    (UINT64_C(1) << 7)     // intern
56
60
#define OPTION_BIG_TABLES       (UINT64_C(1) << 8)     // THD, user
57
61
#define OPTION_BIG_SELECTS      (UINT64_C(1) << 9)     // THD, user
 
62
#define OPTION_LOG_OFF          (UINT64_C(1) << 10)    // THD, user
 
63
#define OPTION_QUOTE_SHOW_CREATE (UINT64_C(1) << 11)   // THD, user, unused
58
64
#define TMP_TABLE_ALL_COLUMNS   (UINT64_C(1) << 12)    // SELECT, intern
59
65
#define OPTION_WARNINGS         (UINT64_C(1) << 13)    // THD, user
60
66
#define OPTION_AUTO_IS_NULL     (UINT64_C(1) << 14)    // THD, user, binlog
61
67
#define OPTION_FOUND_COMMENT    (UINT64_C(1) << 15)    // SELECT, intern, parser
 
68
#define OPTION_SAFE_UPDATES     (UINT64_C(1) << 16)    // THD, user
62
69
#define OPTION_BUFFER_RESULT    (UINT64_C(1) << 17)    // SELECT, user
 
70
#define OPTION_BIN_LOG          (UINT64_C(1) << 18)    // THD, user
63
71
#define OPTION_NOT_AUTOCOMMIT   (UINT64_C(1) << 19)    // THD, user
64
72
#define OPTION_BEGIN            (UINT64_C(1) << 20)    // THD, intern
 
73
#define OPTION_TABLE_LOCK       (UINT64_C(1) << 21)    // THD, intern
 
74
#define OPTION_QUICK            (UINT64_C(1) << 22)    // SELECT (for DELETE)
 
75
#define OPTION_KEEP_LOG         (UINT64_C(1) << 23)    // THD, user
65
76
 
66
77
/* The following is used to detect a conflict with DISTINCT */
67
78
#define SELECT_ALL              (UINT64_C(1) << 24)    // SELECT, user, parser
73
84
   key checks in some cases */
74
85
#define OPTION_RELAXED_UNIQUE_CHECKS    (UINT64_C(1) << 27) // THD, user, binlog
75
86
#define SELECT_NO_UNLOCK                (UINT64_C(1) << 28) // SELECT, intern
 
87
#define OPTION_SCHEMA_TABLE             (UINT64_C(1) << 29) // SELECT, intern
76
88
/** Flag set if setup_tables already done */
77
89
#define OPTION_SETUP_TABLES_DONE        (UINT64_C(1) << 30) // intern
78
90
/** If not set then the thread will ignore all warnings with level notes. */
79
91
#define OPTION_SQL_NOTES                (UINT64_C(1) << 31) // THD, user
 
92
/**
 
93
  Force the used temporary table to be a MyISAM table (because we will use
 
94
  fulltext functions when reading from it.
 
95
*/
 
96
#define TMP_TABLE_FORCE_MYISAM          (UINT64_C(1) << 32)
 
97
#define OPTION_PROFILING                (UINT64_C(1) << 33)
 
98
 
 
99
/*
 
100
  Dont report errors for individual rows,
 
101
  But just report error on commit (or read ofcourse)
 
102
*/
 
103
#define OPTION_ALLOW_BATCH              (UINT64_C(1) << 33) // THD, intern (slave)
80
104
 
81
105
/**
82
106
  Maximum length of time zone name that we support
89
113
#define USERNAME_CHAR_LENGTH 16
90
114
#define NAME_CHAR_LEN   64              /* Field/table name length */
91
115
#define NAME_LEN                (NAME_CHAR_LEN*SYSTEM_CHARSET_MBMAXLEN)
92
 
#define MAXIMUM_IDENTIFIER_LENGTH NAME_LEN
93
116
#define USERNAME_LENGTH         (USERNAME_CHAR_LENGTH*SYSTEM_CHARSET_MBMAXLEN)
94
117
 
95
118
#define SERVER_VERSION_LENGTH 60
96
119
#define SQLSTATE_LENGTH 5
97
120
 
98
121
/*
 
122
  Maximum length of comments
 
123
*/
 
124
#define TABLE_COMMENT_MAXLEN 2048
 
125
#define COLUMN_COMMENT_MAXLEN 1024
 
126
#define INDEX_COMMENT_MAXLEN 1024
 
127
 
 
128
/* The length of the header part for each virtual column in the .frm file. */
 
129
#define FRM_VCOL_HEADER_SIZE 3
 
130
/*
 
131
  Maximum length of the expression statement defined for virtual columns.
 
132
*/
 
133
#define VIRTUAL_COLUMN_EXPRESSION_MAXLEN 255 - FRM_VCOL_HEADER_SIZE
 
134
 
 
135
/*
99
136
  USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain
100
137
  username and hostname parts of the user identifier with trailing zero in
101
138
  MySQL standard format:
103
140
*/
104
141
#define USER_HOST_BUFF_SIZE HOSTNAME_LENGTH + USERNAME_LENGTH + 2
105
142
 
 
143
#define LOCAL_HOST      "localhost"
 
144
#define LOCAL_HOST_NAMEDPIPE "."
 
145
 
106
146
/*
107
147
  You should add new commands to the end of this list, otherwise old
108
148
  servers won't be able to handle them as 'unsupported'.
109
149
*/
110
150
 
 
151
enum enum_server_command
 
152
{
 
153
  COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY, COM_FIELD_LIST,
 
154
  COM_CREATE_DB, COM_DROP_DB, COM_REFRESH, COM_SHUTDOWN,
 
155
  COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL, COM_PING,
 
156
  COM_TIME, COM_CHANGE_USER, COM_BINLOG_DUMP,
 
157
  COM_CONNECT_OUT, COM_REGISTER_SLAVE,
 
158
  COM_SET_OPTION, COM_DAEMON,
 
159
  /* don't forget to update const char *command_name[] in sql_parse.cc */
 
160
 
 
161
  /* Must be last */
 
162
  COM_END
 
163
};
 
164
 
 
165
 
111
166
/*
112
167
  Length of random string sent by server on handshake; this is also length of
113
168
  obfuscated password, recieved from client
114
169
*/
115
170
#define SCRAMBLE_LENGTH 20
116
171
#define SCRAMBLE_LENGTH_323 8
 
172
/* length of password stored in the db: new passwords are preceeded with '*' */
 
173
#define SCRAMBLED_PASSWORD_CHAR_LENGTH (SCRAMBLE_LENGTH*2+1)
 
174
#define SCRAMBLED_PASSWORD_CHAR_LENGTH_323 (SCRAMBLE_LENGTH_323*2)
 
175
 
117
176
 
118
177
#define NOT_NULL_FLAG   1               /* Field can't be NULL */
119
178
#define PRI_KEY_FLAG    2               /* Field is part of a primary key */
121
180
#define MULTIPLE_KEY_FLAG 8             /* Field is part of a key */
122
181
#define BLOB_FLAG       16              /* Field is a blob */
123
182
#define UNSIGNED_FLAG   32              /* Field is unsigned */
 
183
#define DECIMAL_FLAG    64              /* Field is zerofill */
124
184
#define BINARY_FLAG     128             /* Field is binary   */
125
185
 
126
186
/* The following are only sent to new clients */
127
187
#define ENUM_FLAG       256             /* field is an enum */
128
188
#define AUTO_INCREMENT_FLAG 512         /* field is a autoincrement field */
129
 
#define FUNCTION_DEFAULT_FLAG   1024            /* Field is a timestamp, uses a function to generate the value. */
 
189
#define TIMESTAMP_FLAG  1024            /* Field is a timestamp */
 
190
#define SET_FLAG        2048            /* field is a set */
130
191
#define NO_DEFAULT_VALUE_FLAG 4096      /* Field doesn't have default value */
131
192
#define ON_UPDATE_NOW_FLAG 8192         /* Field is set to NOW on UPDATE */
 
193
#define NUM_FLAG        32768           /* Field is num (for clients) */
132
194
#define PART_KEY_FLAG   16384           /* Intern; Part of some key */
133
195
#define GROUP_FLAG      32768           /* Intern: Group field */
134
196
#define UNIQUE_FLAG     65536           /* Intern: Used by sql_yacc */
135
197
#define BINCMP_FLAG     131072          /* Intern: Used by sql_yacc */
 
198
#define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */
 
199
#define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
 
200
#define FIELD_IN_ADD_INDEX (1<< 20)     /* Intern: Field used in ADD INDEX */
 
201
#define FIELD_IS_RENAMED (1<< 21)       /* Intern: Field is being renamed */
 
202
#define FIELD_STORAGE_FLAGS 22          /* Storage type: bit 22, 23 and 24 */
136
203
#define COLUMN_FORMAT_FLAGS 25          /* Column format: bit 25, 26 and 27 */
137
 
#define COLUMN_FORMAT_MASK 7
 
204
 
 
205
#define REFRESH_GRANT           1       /* Refresh grant tables */
 
206
#define REFRESH_LOG             2       /* Start on new log file */
 
207
#define REFRESH_TABLES          4       /* close all tables */
 
208
#define REFRESH_HOSTS           8       /* Flush host cache */
 
209
#define REFRESH_STATUS          16      /* Flush status variables */
 
210
#define REFRESH_THREADS         32      /* Flush thread cache */
 
211
#define REFRESH_SLAVE           64      /* Reset master info and restart slave
 
212
                                           thread */
 
213
#define REFRESH_MASTER          128     /* Remove all bin logs in the index
 
214
                                           and truncate the index */
 
215
 
 
216
/* The following can't be set with mysql_refresh() */
 
217
#define REFRESH_READ_LOCK       16384   /* Lock tables for read */
 
218
#define REFRESH_FAST            32768   /* Intern flag */
 
219
 
 
220
/* RESET (remove all queries) from query cache */
 
221
#define REFRESH_QUERY_CACHE     65536
 
222
#define REFRESH_QUERY_CACHE_FREE 0x20000L /* pack query cache */
 
223
#define REFRESH_DES_KEY_FILE    0x40000L
 
224
#define REFRESH_USER_RESOURCES  0x80000L
 
225
 
 
226
#define CLIENT_LONG_PASSWORD    1       /* new more secure passwords */
 
227
#define CLIENT_FOUND_ROWS       2       /* Found instead of affected rows */
 
228
#define CLIENT_LONG_FLAG        4       /* Get all column flags */
 
229
#define CLIENT_CONNECT_WITH_DB  8       /* One can specify db on connect */
 
230
#define CLIENT_NO_SCHEMA        16      /* Don't allow database.table.column */
 
231
#define CLIENT_COMPRESS         32      /* Can use compression protocol */
 
232
#define CLIENT_ODBC             64      /* Odbc client */
 
233
#define CLIENT_LOCAL_FILES      128     /* Can use LOAD DATA LOCAL */
 
234
#define CLIENT_IGNORE_SPACE     256     /* Ignore spaces before '(' */
 
235
#define UNUSED_CLIENT_PROTOCOL_41       512     /* New 4.1 protocol */
 
236
#define CLIENT_INTERACTIVE      1024    /* This is an interactive client */
 
237
#define CLIENT_SSL              2048    /* Switch to SSL after handshake */
 
238
#define CLIENT_IGNORE_SIGPIPE   4096    /* IGNORE sigpipes */
 
239
#define CLIENT_TRANSACTIONS     8192    /* Client knows about transactions */
 
240
#define CLIENT_RESERVED         16384   /* Old flag for 4.1 protocol  */
 
241
#define CLIENT_SECURE_CONNECTION 32768  /* New 4.1 authentication */
 
242
#define CLIENT_MULTI_STATEMENTS (1UL << 16) /* Enable/disable multi-stmt support */
 
243
#define CLIENT_MULTI_RESULTS    (1UL << 17) /* Enable/disable multi-results */
 
244
 
 
245
#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
 
246
#define CLIENT_REMEMBER_OPTIONS (1UL << 31)
 
247
 
 
248
/* Gather all possible capabilites (flags) supported by the server */
 
249
#define CLIENT_ALL_FLAGS  (CLIENT_LONG_PASSWORD | \
 
250
                           CLIENT_FOUND_ROWS | \
 
251
                           CLIENT_LONG_FLAG | \
 
252
                           CLIENT_CONNECT_WITH_DB | \
 
253
                           CLIENT_NO_SCHEMA | \
 
254
                           CLIENT_COMPRESS | \
 
255
                           CLIENT_ODBC | \
 
256
                           CLIENT_LOCAL_FILES | \
 
257
                           CLIENT_IGNORE_SPACE | \
 
258
                           CLIENT_INTERACTIVE | \
 
259
                           CLIENT_SSL | \
 
260
                           CLIENT_IGNORE_SIGPIPE | \
 
261
                           CLIENT_TRANSACTIONS | \
 
262
                           CLIENT_RESERVED | \
 
263
                           CLIENT_SECURE_CONNECTION | \
 
264
                           CLIENT_MULTI_STATEMENTS | \
 
265
                           CLIENT_MULTI_RESULTS | \
 
266
                           CLIENT_SSL_VERIFY_SERVER_CERT | \
 
267
                           CLIENT_REMEMBER_OPTIONS)
 
268
 
 
269
/*
 
270
  Switch off the flags that are optional and depending on build flags
 
271
  If any of the optional flags is supported by the build it will be switched
 
272
  on before sending to the client during the connection handshake.
 
273
*/
 
274
#define CLIENT_BASIC_FLAGS (((CLIENT_ALL_FLAGS & ~CLIENT_SSL) \
 
275
                                               & ~CLIENT_COMPRESS) \
 
276
                                               & ~CLIENT_SSL_VERIFY_SERVER_CERT)
138
277
 
139
278
#define SERVER_STATUS_IN_TRANS     1    /* Transaction has started */
140
279
#define SERVER_STATUS_AUTOCOMMIT   2    /* Server in auto_commit mode */
141
280
#define SERVER_MORE_RESULTS_EXISTS 8    /* Multi query - next query exists */
142
281
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
143
282
#define SERVER_QUERY_NO_INDEX_USED      32
 
283
/*
 
284
  The server was able to fulfill the clients request and opened a
 
285
  read-only non-scrollable cursor for a query. This flag comes
 
286
  in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands.
 
287
*/
 
288
#define SERVER_STATUS_CURSOR_EXISTS 64
 
289
/*
 
290
  This flag is sent when a read-only cursor is exhausted, in reply to
 
291
  COM_STMT_FETCH command.
 
292
*/
 
293
#define SERVER_STATUS_LAST_ROW_SENT 128
144
294
#define SERVER_STATUS_DB_DROPPED        256 /* A database was dropped */
 
295
#define SERVER_STATUS_NO_BACKSLASH_ESCAPES 512
 
296
/*
 
297
  Tell clients that this query was logged to the slow query log.
 
298
  Not yet set in the server, but interface is defined for applications
 
299
  to use.  See WorkLog 4098.
 
300
*/
 
301
#define SERVER_QUERY_WAS_SLOW           1024
145
302
 
146
303
#define DRIZZLE_ERRMSG_SIZE     512
 
304
#define NET_READ_TIMEOUT        30              /* Timeout on read */
 
305
#define NET_WRITE_TIMEOUT       60              /* Timeout on write */
 
306
#define NET_WAIT_TIMEOUT        8*60*60         /* Wait for new query */
147
307
 
148
308
#define ONLY_KILL_QUERY         1
149
309
 
 
310
#define MAX_TINYINT_WIDTH       3       /* Max width for a TINY w.o. sign */
 
311
#define MAX_SMALLINT_WIDTH      5       /* Max width for a SHORT w.o. sign */
 
312
#define MAX_MEDIUMINT_WIDTH     8       /* Max width for a INT24 w.o. sign */
150
313
#define MAX_INT_WIDTH           10      /* Max width for a LONG w.o. sign */
151
314
#define MAX_BIGINT_WIDTH        20      /* Max width for a LONGLONG */
152
 
#define MAX_BLOB_WIDTH          (uint32_t)16777216      /* Default width for blob */
 
315
#define MAX_CHAR_WIDTH          255     /* Max length for a CHAR colum */
 
316
#define MAX_BLOB_WIDTH          16777216        /* Default width for blob */
153
317
 
154
318
#define DRIZZLE_PROTOCOL_NO_MORE_DATA 0xFE
155
319
 
156
320
 
157
321
 
158
322
 
159
 
#define packet_error UINT32_MAX
160
 
 
161
 
#if defined(__cplusplus)
162
 
 
163
 
namespace drizzled
164
 
{
165
 
 
166
 
enum enum_server_command
167
 
{
168
 
  COM_SLEEP,
169
 
  COM_QUIT,
170
 
  COM_INIT_DB,
171
 
  COM_QUERY,
172
 
  COM_SHUTDOWN,
173
 
  COM_CONNECT,
174
 
  COM_PING,
175
 
  /* don't forget to update const char *command_name[] in sql_parse.cc */
176
 
  /* Must be last */
177
 
  COM_END
178
 
};
179
 
 
180
 
 
181
 
enum enum_field_types { 
 
323
#define packet_error (~(uint32_t) 0)
 
324
 
 
325
 
 
326
/* Shutdown/kill enums and constants */
 
327
 
 
328
/* Bits for THD::killable. */
 
329
#define DRIZZLE_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
 
330
#define DRIZZLE_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
 
331
#define DRIZZLE_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
 
332
#define DRIZZLE_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)
 
333
 
 
334
/* Start TINY at 1 because we removed DECIMAL from off the front of the enum */
 
335
enum enum_field_types { DRIZZLE_TYPE_TINY,
182
336
                        DRIZZLE_TYPE_LONG,
183
337
                        DRIZZLE_TYPE_DOUBLE,
184
338
                        DRIZZLE_TYPE_NULL,
185
339
                        DRIZZLE_TYPE_TIMESTAMP,
186
340
                        DRIZZLE_TYPE_LONGLONG,
 
341
                        DRIZZLE_TYPE_TIME,
187
342
                        DRIZZLE_TYPE_DATETIME,
188
343
                        DRIZZLE_TYPE_DATE,
189
344
                        DRIZZLE_TYPE_VARCHAR,
190
 
                        DRIZZLE_TYPE_DECIMAL,
 
345
                        DRIZZLE_TYPE_VIRTUAL,
 
346
                        DRIZZLE_TYPE_NEWDECIMAL,
191
347
                        DRIZZLE_TYPE_ENUM,
192
348
                        DRIZZLE_TYPE_BLOB,
193
 
                        DRIZZLE_TYPE_UUID
194
 
};
195
 
const int enum_field_types_size= DRIZZLE_TYPE_UUID + 1;
196
 
 
197
 
} /* namespace drizzled */
198
 
 
199
 
#endif /* defined(__cplusplus) */
200
 
 
201
 
#endif /* DRIZZLED_COMMON_H */
 
349
                        DRIZZLE_TYPE_MAX=DRIZZLE_TYPE_BLOB
 
350
};
 
351
 
 
352
 
 
353
enum enum_cursor_type
 
354
{
 
355
  CURSOR_TYPE_NO_CURSOR= 0,
 
356
  CURSOR_TYPE_READ_ONLY= 1,
 
357
  CURSOR_TYPE_FOR_UPDATE= 2,
 
358
  CURSOR_TYPE_SCROLLABLE= 4
 
359
};
 
360
 
 
361
 
 
362
/* options for mysql_set_option */
 
363
enum enum_drizzle_set_option
 
364
{
 
365
  DRIZZLE_OPTION_MULTI_STATEMENTS_ON,
 
366
  DRIZZLE_OPTION_MULTI_STATEMENTS_OFF
 
367
};
 
368
 
 
369
#define net_new_transaction(net) ((net)->pkt_nr=0)
 
370
 
 
371
 
 
372
  /* The following is for user defined functions */
 
373
 
 
374
enum Item_result {STRING_RESULT=0, REAL_RESULT, INT_RESULT, ROW_RESULT,
 
375
                  DECIMAL_RESULT};
 
376
 
 
377
typedef struct st_udf_args
 
378
{
 
379
  unsigned int arg_count;               /* Number of arguments */
 
380
  enum Item_result *arg_type;           /* Pointer to item_results */
 
381
  char **args;                          /* Pointer to argument */
 
382
  unsigned long *lengths;               /* Length of string arguments */
 
383
  char *maybe_null;                     /* Set to 1 for all maybe_null args */
 
384
  char **attributes;                    /* Pointer to attribute name */
 
385
  unsigned long *attribute_lengths;     /* Length of attribute arguments */
 
386
  void *extension;
 
387
} UDF_ARGS;
 
388
 
 
389
  /* This holds information about the result */
 
390
 
 
391
typedef struct st_udf_init
 
392
{
 
393
  bool maybe_null;          /* 1 if function can return NULL */
 
394
  unsigned int decimals;       /* for real functions */
 
395
  unsigned long max_length;    /* For string functions */
 
396
  char *ptr;                   /* free pointer for function data */
 
397
  bool const_item;          /* 1 if function always returns the same value */
 
398
  void *extension;
 
399
} UDF_INIT;
 
400
/*
 
401
  TODO: add a notion for determinism of the UDF.
 
402
  See Item_udf_func::update_used_tables ()
 
403
*/
 
404
 
 
405
  /* Constants when using compression */
 
406
#define NET_HEADER_SIZE 4               /* standard header size */
 
407
#define COMP_HEADER_SIZE 3              /* compression header extra size */
 
408
 
 
409
 
 
410
#define NULL_LENGTH UINT32_MAX /* For net_store_length */
 
411
 
 
412
#endif