~ubuntu-branches/ubuntu/vivid/mariadb-5.5/vivid

« back to all changes in this revision

Viewing changes to storage/pbxt/src/datadic_xt.h

  • Committer: Package Import Robot
  • Author(s): James Page, Otto Kekäläinen
  • Date: 2014-02-17 16:51:52 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140217165152-k315d3175g865kkx
Tags: 5.5.35-1
[ Otto Kekäläinen ]
* New upstream release, fixing the following security issues:
  - Buffer overflow in client/mysql.cc (Closes: #737597).
    - CVE-2014-0001
  - http://www.oracle.com/technetwork/topics/security/cpujan2014-1972949.html
    - CVE-2013-5891
    - CVE-2013-5908
    - CVE-2014-0386
    - CVE-2014-0393
    - CVE-2014-0401
    - CVE-2014-0402
    - CVE-2014-0412
    - CVE-2014-0420
    - CVE-2014-0437
* Upstream https://mariadb.atlassian.net/browse/MDEV-4902
  fixes compatibility with Bison 3.0 (Closes: #733002)
* Updated Russian debconf translation (Closes: #734426)
* Updated Japanese debconf translation (Closes: #735284)
* Updated French debconf translation (Closes: #736480)
* Renamed SONAME properly (Closes: #732967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2005 PrimeBase Technologies GmbH
2
 
 *
3
 
 * PrimeBase XT
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
 
 *
19
 
 * 2004-01-03   Paul McCullagh
20
 
 *
21
 
 * H&G2JCtL
22
 
 *
23
 
 * Implementation of the PBXT internal data dictionary.
24
 
 */
25
 
 
26
 
#ifndef __datadic_xt_h__
27
 
#define __datadic_xt_h__
28
 
 
29
 
#include <stddef.h>
30
 
#include <limits.h>
31
 
 
32
 
#include "ccutils_xt.h"
33
 
#include "util_xt.h"
34
 
 
35
 
struct XTDatabase;
36
 
struct XTTable;
37
 
struct XTIndex;
38
 
struct XTOpenTable;
39
 
struct XTIndex;
40
 
 
41
 
/* Constraint types: */
42
 
#define XT_DD_UNKNOWN                           ((u_int) -1)
43
 
#define XT_DD_INDEX                                     0
44
 
#define XT_DD_INDEX_UNIQUE                      1
45
 
#define XT_DD_KEY_PRIMARY                       2
46
 
#define XT_DD_KEY_FOREIGN                       3
47
 
 
48
 
#define XT_KEY_ACTION_RESTRICT          1
49
 
#define XT_KEY_ACTION_CASCADE           2
50
 
#define XT_KEY_ACTION_SET_NULL          3
51
 
#define XT_KEY_ACTION_SET_DEFAULT       4
52
 
#define XT_KEY_ACTION_NO_ACTION         5               /* Like RESTRICT, but check at end of statement. */ 
53
 
 
54
 
class XTDDEnumerableColumn;
55
 
class XTDDColumnFactory;
56
 
 
57
 
class XTDDColumn : public XTObject {
58
 
 
59
 
protected:
60
 
 
61
 
        XTDDColumn() : XTObject(),
62
 
                dc_name(NULL),
63
 
                dc_data_type(NULL),
64
 
                dc_null_ok(true),
65
 
                dc_auto_inc(false) {
66
 
        }
67
 
 
68
 
public:
69
 
        char    *dc_name;
70
 
        char    *dc_data_type;
71
 
        bool    dc_null_ok;
72
 
        bool    dc_auto_inc;
73
 
 
74
 
        virtual XTObject *factory(XTThreadPtr self) {
75
 
                XTObject *new_obj;
76
 
                
77
 
                if (!(new_obj = new XTDDColumn()))
78
 
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
79
 
                return new_obj;
80
 
        }
81
 
 
82
 
        virtual void init(XTThreadPtr self) { 
83
 
                XTObject::init(self);
84
 
        }
85
 
        virtual void init(XTThreadPtr self, XTObject *obj);
86
 
        virtual void finalize(XTThreadPtr self);
87
 
        virtual void loadString(XTThreadPtr self, XTStringBufferPtr sb);
88
 
 
89
 
        virtual XTDDEnumerableColumn *castToEnumerable() { 
90
 
                return NULL;
91
 
        }
92
 
 
93
 
        friend class XTDDColumnFactory;
94
 
};
95
 
 
96
 
/*
97
 
 * subclass for ENUMs and SETs
98
 
 */
99
 
class XTDDEnumerableColumn : public XTDDColumn {
100
 
 
101
 
protected:
102
 
        XTDDEnumerableColumn() : XTDDColumn(), 
103
 
                enum_size(0), is_enum(0) {
104
 
        }
105
 
 
106
 
public:
107
 
        int enum_size;  /* number of elements in the ENUM or SET */
108
 
        xtBool is_enum; /* TRUE if this is ENUM, FALSE if SET */
109
 
 
110
 
        virtual XTObject *factory(XTThreadPtr self) {
111
 
                XTObject *new_obj;
112
 
                
113
 
                if (!(new_obj = new XTDDEnumerableColumn()))
114
 
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
115
 
                return new_obj;
116
 
        }
117
 
 
118
 
        virtual XTDDEnumerableColumn *castToEnumerable() { 
119
 
                return this;
120
 
        }
121
 
 
122
 
        friend class XTDDColumnFactory;
123
 
};
124
 
 
125
 
class XTDDColumnRef : public XTObject {
126
 
        public:
127
 
        char                                    *cr_col_name;
128
 
 
129
 
        XTDDColumnRef() : XTObject(), cr_col_name(NULL) { }
130
 
 
131
 
        virtual XTObject *factory(XTThreadPtr self) {
132
 
                XTObject *new_obj;
133
 
                
134
 
                if (!(new_obj = new XTDDColumnRef()))
135
 
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
136
 
                return new_obj;
137
 
        }
138
 
 
139
 
        virtual void init(XTThreadPtr self) { XTObject::init(self); }
140
 
        virtual void init(XTThreadPtr self, XTObject *obj);
141
 
        virtual void finalize(XTThreadPtr self);
142
 
};
143
 
 
144
 
class XTDDConstraint : public XTObject {
145
 
        public:
146
 
        class XTDDTable                 *co_table;                                                              /* The table of this constraint (non-referenced). */
147
 
        u_int                                   co_type;
148
 
        char                                    *co_name;
149
 
        char                                    *co_ind_name;
150
 
        XTList<XTDDColumnRef>   co_cols;
151
 
 
152
 
        XTDDConstraint(u_int t) : XTObject(),
153
 
                co_table(NULL),
154
 
                co_type(t),
155
 
                co_name(NULL),
156
 
                co_ind_name(NULL) {
157
 
        }
158
 
 
159
 
        virtual void init(XTThreadPtr self) { XTObject::init(self); }
160
 
        virtual void init(XTThreadPtr self, XTObject *obj);
161
 
        virtual void finalize(XTThreadPtr self) {
162
 
                if (co_name)
163
 
                        xt_free(self, co_name);
164
 
                if (co_ind_name)
165
 
                        xt_free(self, co_ind_name);
166
 
                co_cols.deleteAll(self);
167
 
                XTObject::finalize(self);
168
 
        }
169
 
        virtual void loadString(XTThreadPtr self, XTStringBufferPtr sb);
170
 
        virtual void alterColumnName(XTThreadPtr self, char *from_name, char *to_name);
171
 
        void getColumnList(char *buffer, size_t size);
172
 
        bool sameColumns(XTDDConstraint *co);
173
 
        bool samePrefixColumns(XTDDConstraint *co);
174
 
        bool attachColumns();
175
 
};
176
 
 
177
 
class XTDDTableRef : public XTObject {
178
 
        public:
179
 
        class XTDDTableRef              *tr_next;                                                               /* The next reference in the list. */
180
 
        class XTDDForeignKey    *tr_fkey;                                                               /* The foreign key that references this table (if not-NULL). */
181
 
 
182
 
        XTDDTableRef() : XTObject(), tr_next(NULL), tr_fkey(NULL) { }
183
 
        virtual void finalize(XTThreadPtr self);
184
 
        bool modifyRow(struct XTOpenTable *tab, xtWord1 *before, xtWord1 *after, XTThreadPtr thread);
185
 
        bool checkReference(xtWord1 *before, XTThreadPtr thread);
186
 
        void deleteAllRows(XTThreadPtr self);
187
 
};
188
 
 
189
 
class XTDDIndex : public XTDDConstraint {       
190
 
        public:
191
 
        u_int                                   in_index;
192
 
 
193
 
        XTDDIndex(u_int type) : XTDDConstraint(type), in_index((u_int) -1) { }
194
 
 
195
 
        virtual XTObject *factory(XTThreadPtr self) {
196
 
                XTObject *new_obj;
197
 
                
198
 
                if (!(new_obj = new XTDDIndex(XT_DD_UNKNOWN)))
199
 
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
200
 
                return new_obj;
201
 
        }
202
 
 
203
 
        virtual void init(XTThreadPtr self) { XTDDConstraint::init(self); };
204
 
        virtual void init(XTThreadPtr self, XTObject *obj);
205
 
        struct XTIndex *getIndexPtr();
206
 
};
207
 
 
208
 
/*
209
 
 * A foreign key is based on a local index.
210
 
 */
211
 
class XTDDForeignKey : public XTDDIndex {
212
 
        public:
213
 
        XTPathStrPtr                    fk_ref_tab_name;
214
 
        XTDDTable                               *fk_ref_table;
215
 
        u_int                                   fk_ref_index;                                                   /* The index on which this foreign key references. */
216
 
        XTList<XTDDColumnRef>   fk_ref_cols;
217
 
        int                                             fk_on_delete;
218
 
        int                                             fk_on_update;
219
 
 
220
 
        XTDDForeignKey() : XTDDIndex(XT_DD_KEY_FOREIGN),
221
 
                fk_ref_tab_name(NULL),
222
 
                fk_ref_table(NULL),
223
 
                fk_ref_index(UINT_MAX),
224
 
                fk_on_delete(0),
225
 
                fk_on_update(0) {
226
 
        }
227
 
 
228
 
        virtual XTObject *factory(XTThreadPtr self) {
229
 
                XTObject *new_obj;
230
 
                
231
 
                if (!(new_obj = new XTDDForeignKey()))
232
 
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
233
 
                return new_obj;
234
 
        }
235
 
 
236
 
        virtual void init(XTThreadPtr self) { XTDDIndex::init(self); }
237
 
        virtual void init(XTThreadPtr self, XTObject *obj);
238
 
        virtual void finalize(XTThreadPtr self);
239
 
        virtual void loadString(XTThreadPtr self, XTStringBufferPtr sb);
240
 
        void getReferenceList(char *buffer, size_t size);
241
 
        struct XTIndex *getReferenceIndexPtr();
242
 
        bool sameReferenceColumns(XTDDConstraint *co);
243
 
        bool samePrefixReferenceColumns(XTDDConstraint *co);
244
 
        bool checkReferencedTypes(XTDDTable *dt);
245
 
        void removeReference(XTThreadPtr self);
246
 
        bool insertRow(xtWord1 *before, xtWord1 *after, XTThreadPtr thread);
247
 
        bool updateRow(xtWord1 *before, xtWord1 *after, XTThreadPtr thread);
248
 
 
249
 
        static const char *actionTypeToString(int action);
250
 
};
251
 
 
252
 
class XTDDTable : public XTObject {
253
 
        private:
254
 
 
255
 
        public:
256
 
        struct XTTable                  *dt_table;
257
 
 
258
 
        XTList<XTDDColumn>              dt_cols;
259
 
        XTList<XTDDIndex>               dt_indexes;
260
 
 
261
 
        XTRecurRWLockRec                dt_ref_lock;                    /* The lock for adding and using references. */
262
 
        XTList<XTDDForeignKey>  dt_fkeys;                               /* The foreign keys on this table. */
263
 
        XTDDTableRef                    *dt_trefs;                              /* A list of tables that reference this table. */
264
 
 
265
 
        virtual XTObject *factory(XTThreadPtr self) {
266
 
                XTObject *new_obj;
267
 
                
268
 
                if (!(new_obj = new XTDDTable()))
269
 
                        xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
270
 
                return new_obj;
271
 
        }
272
 
 
273
 
        virtual void init(XTThreadPtr self);
274
 
        virtual void init(XTThreadPtr self, XTObject *obj);
275
 
        virtual void finalize(XTThreadPtr self);
276
 
 
277
 
        XTDDColumn *findColumn(char *name);
278
 
        void loadString(XTThreadPtr self, XTStringBufferPtr sb);
279
 
        void loadForeignKeyString(XTThreadPtr self, XTStringBufferPtr sb);
280
 
        void checkForeignKeyReference(XTThreadPtr self, XTDDForeignKey *fk);
281
 
        void attachReferences(XTThreadPtr self, struct XTDatabase *db);
282
 
        void attachReference(XTThreadPtr self, XTDDForeignKey *fk);
283
 
        void alterColumnName(XTThreadPtr self, char *from_name, char *to_name);
284
 
        void attachReference(XTThreadPtr self, XTDDTable *dt);
285
 
        void removeReferences(XTThreadPtr self);
286
 
        void removeReference(XTThreadPtr self, XTDDForeignKey *fk);
287
 
        void checkForeignKeys(XTThreadPtr self, bool temp_table);
288
 
        XTDDIndex *findIndex(XTDDConstraint *co);
289
 
        XTDDIndex *findReferenceIndex(XTDDForeignKey *fk);
290
 
        bool insertRow(struct XTOpenTable *rec_ot, xtWord1 *buffer);
291
 
        bool checkNoAction(struct XTOpenTable *ot, xtRecordID rec_id);
292
 
        xtBool checkCanDrop(xtBool drop_db);
293
 
        bool deleteRow(struct XTOpenTable *rec_ot, xtWord1 *buffer);
294
 
        void deleteAllRows(XTThreadPtr self);
295
 
        bool updateRow(struct XTOpenTable *rec_ot, xtWord1 *before, xtWord1 *after);
296
 
};
297
 
 
298
 
XTDDTable *xt_ri_create_table(XTThreadPtr self, bool convert, XTPathStrPtr tab_path, char *sql, XTDDTable *my_tab);
299
 
 
300
 
#endif