~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/structs.h

Replace MAX_(DATE|TIME).*_WIDTH defines in definitions.h with real (and correct) static const members to Temporal types.

This fixes the buffer overflow in https://bugs.launchpad.net/drizzle/+bug/373468

It also removes a handwritten snprintf in field/datetime.cc
However... this caused us to have to change Temporal to have a way to not
"convert" the int64_t value (so 20090101 becomes 20090101000000 etc) as it
has already been converted and we just want the Temporal type to do the
to_string conversion.

This still causes a failure in 'metadata' test due to size of timestamp type. I need feedback from Jay on when the usecond code comes into play to know the correct fix for this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#ifndef DRIZZLED_STRUCTS_H
24
24
#define DRIZZLED_STRUCTS_H
25
25
 
26
 
#include "drizzled/base.h"
27
 
#include "drizzled/definitions.h"
28
 
#include "drizzled/lex_string.h"
29
 
#include "drizzled/thr_lock.h"
30
 
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
namespace internal
35
 
{
36
 
typedef struct st_io_cache IO_CACHE;
37
 
}
 
26
#include <drizzled/base.h>
 
27
#include <mysys/definitions.h>
 
28
#include <drizzled/lex_string.h>
38
29
 
39
30
class Table;
40
31
class Field;
 
32
typedef struct st_io_cache IO_CACHE;
41
33
 
42
34
typedef struct st_keyfile_info {        /* used with ha_info() */
43
35
  unsigned char ref[MAX_REFLENGTH];             /* Pointer to current row */
44
36
  unsigned char dupp_ref[MAX_REFLENGTH];        /* Pointer to dupp row */
45
37
  uint32_t ref_length;                  /* Length of ref (1-8) */
46
38
  uint32_t block_size;                  /* index block size */
47
 
  int filenr;                           /* (uniq) filenr for table */
 
39
  File filenr;                          /* (uniq) filenr for table */
48
40
  ha_rows records;                      /* Records i datafilen */
49
41
  ha_rows deleted;                      /* Deleted records */
50
42
  uint64_t data_file_length;            /* Length off data file */
63
55
 
64
56
typedef struct st_key_part_info {       /* Info about a key part */
65
57
  Field *field;
66
 
  unsigned int  offset;                         /* offset in record (from 0) */
67
 
  unsigned int  null_offset;                    /* Offset to null_bit in record */
 
58
  uint  offset;                         /* offset in record (from 0) */
 
59
  uint  null_offset;                    /* Offset to null_bit in record */
68
60
  /* Length of key part in bytes, excluding NULL flag and length bytes */
69
61
  uint16_t length;
70
62
  /*
85
77
 
86
78
 
87
79
typedef struct st_key {
88
 
  unsigned int  key_length;             /* Tot length of key */
 
80
  uint  key_length;                     /* Tot length of key */
89
81
  enum  ha_key_alg algorithm;
90
 
  unsigned long flags;                  /* dupp key and pack flags */
91
 
  unsigned int key_parts;               /* How many key_parts */
 
82
  ulong flags;                          /* dupp key and pack flags */
 
83
  uint  key_parts;                      /* How many key_parts */
92
84
  uint32_t  extra_length;
93
 
  unsigned int usable_key_parts;        /* Should normally be = key_parts */
 
85
  uint  usable_key_parts;               /* Should normally be = key_parts */
94
86
  uint32_t  block_size;
95
87
  KEY_PART_INFO *key_part;
96
88
  char  *name;                          /* Name of key */
105
97
} KEY;
106
98
 
107
99
 
108
 
class JoinTable;
 
100
struct st_join_table;
109
101
 
110
102
struct RegInfo {                /* Extra info about reg */
111
 
  JoinTable *join_tab;  /* Used by SELECT() */
 
103
  struct st_join_table *join_tab;       /* Used by SELECT() */
112
104
  enum thr_lock_type lock_type;         /* How database is used */
113
105
  bool not_exists_optimize;
114
106
  bool impossible_range;
125
117
};
126
118
 
127
119
struct st_read_record;                          /* For referense later */
 
120
class SQL_SELECT;
128
121
class Session;
129
 
class Cursor;
130
 
namespace optimizer { class SqlSelect; }
 
122
class handler;
 
123
struct st_join_table;
131
124
 
132
125
typedef struct st_read_record {                 /* Parameter to read_record */
133
126
  Table *table;                 /* Head-form */
134
 
  Cursor *cursor;
 
127
  handler *file;
135
128
  Table **forms;                        /* head and ref forms */
136
129
  int (*read_record)(struct st_read_record *);
137
130
  Session *session;
138
 
  optimizer::SqlSelect *select;
 
131
  SQL_SELECT *select;
139
132
  uint32_t cache_records;
140
133
  uint32_t ref_length,struct_length,reclength,rec_cache_size,error_offset;
141
134
  uint32_t index;
143
136
  unsigned char *record;
144
137
  unsigned char *rec_buf;                /* to read field values  after filesort */
145
138
  unsigned char *cache,*cache_pos,*cache_end,*read_positions;
146
 
  internal::IO_CACHE *io_cache;
 
139
  IO_CACHE *io_cache;
147
140
  bool print_error, ignore_not_found_rows;
148
 
  JoinTable *do_insideout_scan;
 
141
  struct st_join_table *do_insideout_scan;
149
142
} READ_RECORD;
150
143
 
151
 
typedef int *(*update_var)(Session *, struct drizzle_show_var *);
152
 
 
153
 
} /* namespace drizzled */
 
144
 
 
145
typedef struct {
 
146
  uint32_t year;
 
147
  uint32_t month;
 
148
  uint32_t day;
 
149
  uint32_t hour;
 
150
  uint64_t minute,second,second_part;
 
151
  bool neg;
 
152
} INTERVAL;
 
153
 
 
154
extern const char *show_comp_option_name[];
 
155
 
 
156
typedef int *(*update_var)(Session *, struct st_mysql_show_var *);
 
157
 
 
158
        /* Bits in form->update */
 
159
#define REG_MAKE_DUPP           1       /* Make a copy of record when read */
 
160
#define REG_NEW_RECORD          2       /* Write a new record if not found */
 
161
#define REG_UPDATE              4       /* Uppdate record */
 
162
#define REG_DELETE              8       /* Delete found record */
 
163
#define REG_PROG                16      /* User is updating database */
 
164
#define REG_CLEAR_AFTER_WRITE   32
 
165
#define REG_MAY_BE_UPDATED      64
 
166
#define REG_AUTO_UPDATE         64      /* Used in D-forms for scroll-tables */
 
167
#define REG_OVERWRITE           128
 
168
#define REG_SKIP_DUP            256
154
169
 
155
170
        /* Bits in form->status */
156
171
#define STATUS_NO_RECORD        (1+2)   /* Record isn't usably */