1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
1 |
/* Copyright (C) 2005 PrimeBase Technologies GmbH
|
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
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 |
struct XTDictionary; |
|
41 |
||
42 |
/* Constraint types: */
|
|
43 |
#define XT_DD_UNKNOWN ((u_int) -1)
|
|
44 |
#define XT_DD_INDEX 0
|
|
45 |
#define XT_DD_INDEX_UNIQUE 1
|
|
46 |
#define XT_DD_KEY_PRIMARY 2
|
|
47 |
#define XT_DD_KEY_FOREIGN 3
|
|
48 |
||
49 |
#define XT_KEY_ACTION_RESTRICT 1
|
|
50 |
#define XT_KEY_ACTION_CASCADE 2
|
|
51 |
#define XT_KEY_ACTION_SET_NULL 3
|
|
52 |
#define XT_KEY_ACTION_SET_DEFAULT 4
|
|
53 |
#define XT_KEY_ACTION_NO_ACTION 5 /* Like RESTRICT, but check at end of statement. */ |
|
54 |
||
55 |
class XTDDEnumerableColumn; |
|
56 |
class XTDDColumnFactory; |
|
57 |
||
58 |
class XTDDColumn : public XTObject { |
|
59 |
||
60 |
protected: |
|
61 |
||
62 |
XTDDColumn() : XTObject(), |
|
63 |
dc_name(NULL), |
|
64 |
dc_data_type(NULL), |
|
65 |
dc_null_ok(true), |
|
66 |
dc_auto_inc(false) { |
|
67 |
}
|
|
68 |
||
69 |
public: |
|
70 |
char *dc_name; |
|
71 |
char *dc_data_type; |
|
72 |
bool dc_null_ok; |
|
73 |
bool dc_auto_inc; |
|
74 |
||
75 |
virtual XTObject *factory(XTThreadPtr self) { |
|
76 |
XTObject *new_obj; |
|
77 |
||
78 |
if (!(new_obj = new XTDDColumn())) |
|
79 |
xt_throw_errno(XT_CONTEXT, XT_ENOMEM); |
|
80 |
return new_obj; |
|
81 |
}
|
|
82 |
||
83 |
virtual void init(XTThreadPtr self) { |
|
84 |
XTObject::init(self); |
|
85 |
}
|
|
86 |
virtual void init(XTThreadPtr self, XTObject *obj); |
|
87 |
virtual void finalize(XTThreadPtr self); |
|
88 |
virtual void loadString(XTThreadPtr self, XTStringBufferPtr sb); |
|
89 |
||
90 |
virtual XTDDEnumerableColumn *castToEnumerable() { |
|
91 |
return NULL; |
|
92 |
}
|
|
93 |
||
94 |
friend class XTDDColumnFactory; |
|
95 |
};
|
|
96 |
||
97 |
/*
|
|
98 |
* subclass for ENUMs and SETs
|
|
99 |
*/
|
|
100 |
class XTDDEnumerableColumn : public XTDDColumn { |
|
101 |
||
102 |
protected: |
|
103 |
XTDDEnumerableColumn() : XTDDColumn(), |
|
104 |
enum_size(0), is_enum(0) { |
|
105 |
}
|
|
106 |
||
107 |
public: |
|
108 |
int enum_size; /* number of elements in the ENUM or SET */ |
|
109 |
xtBool is_enum; /* TRUE if this is ENUM, FALSE if SET */ |
|
110 |
||
111 |
virtual XTObject *factory(XTThreadPtr self) { |
|
112 |
XTObject *new_obj; |
|
113 |
||
114 |
if (!(new_obj = new XTDDEnumerableColumn())) |
|
115 |
xt_throw_errno(XT_CONTEXT, XT_ENOMEM); |
|
116 |
return new_obj; |
|
117 |
}
|
|
118 |
||
119 |
virtual XTDDEnumerableColumn *castToEnumerable() { |
|
120 |
return this; |
|
121 |
}
|
|
122 |
||
123 |
friend class XTDDColumnFactory; |
|
124 |
};
|
|
125 |
||
126 |
class XTDDColumnRef : public XTObject { |
|
127 |
public: |
|
128 |
char *cr_col_name; |
|
129 |
||
130 |
XTDDColumnRef() : XTObject(), cr_col_name(NULL) { } |
|
131 |
||
132 |
virtual XTObject *factory(XTThreadPtr self) { |
|
133 |
XTObject *new_obj; |
|
134 |
||
135 |
if (!(new_obj = new XTDDColumnRef())) |
|
136 |
xt_throw_errno(XT_CONTEXT, XT_ENOMEM); |
|
137 |
return new_obj; |
|
138 |
}
|
|
139 |
||
140 |
virtual void init(XTThreadPtr self) { XTObject::init(self); } |
|
141 |
virtual void init(XTThreadPtr self, XTObject *obj); |
|
142 |
virtual void finalize(XTThreadPtr self); |
|
143 |
};
|
|
144 |
||
145 |
class XTDDConstraint : public XTObject { |
|
146 |
public: |
|
147 |
class XTDDTable *co_table; /* The table of this constraint (non-referenced). */ |
|
148 |
u_int co_type; |
|
149 |
char *co_name; |
|
150 |
char *co_ind_name; |
|
151 |
XTList<XTDDColumnRef> co_cols; |
|
152 |
||
153 |
XTDDConstraint(u_int t) : XTObject(), |
|
154 |
co_table(NULL), |
|
155 |
co_type(t), |
|
156 |
co_name(NULL), |
|
157 |
co_ind_name(NULL) { |
|
158 |
}
|
|
159 |
||
160 |
virtual void init(XTThreadPtr self) { XTObject::init(self); } |
|
161 |
virtual void init(XTThreadPtr self, XTObject *obj); |
|
162 |
virtual void finalize(XTThreadPtr self) { |
|
163 |
if (co_name) |
|
164 |
xt_free(self, co_name); |
|
165 |
if (co_ind_name) |
|
166 |
xt_free(self, co_ind_name); |
|
167 |
co_cols.deleteAll(self); |
|
168 |
XTObject::finalize(self); |
|
169 |
}
|
|
170 |
virtual void loadString(XTThreadPtr self, XTStringBufferPtr sb); |
|
171 |
virtual void alterColumnName(XTThreadPtr self, char *from_name, char *to_name); |
|
172 |
void getColumnList(char *buffer, size_t size); |
|
173 |
bool sameColumns(XTDDConstraint *co); |
|
174 |
bool samePrefixColumns(XTDDConstraint *co); |
|
175 |
bool attachColumns(); |
|
176 |
};
|
|
177 |
||
178 |
class XTDDTableRef : public XTObject { |
|
179 |
public: |
|
180 |
class XTDDTableRef *tr_next; /* The next reference in the list. */ |
|
181 |
class XTDDForeignKey *tr_fkey; /* The foreign key that references this table (if not-NULL). */ |
|
182 |
||
183 |
XTDDTableRef() : XTObject(), tr_next(NULL), tr_fkey(NULL) { } |
|
184 |
virtual void finalize(XTThreadPtr self); |
|
185 |
bool modifyRow(struct XTOpenTable *tab, xtWord1 *before, xtWord1 *after, XTThreadPtr thread); |
|
186 |
bool checkReference(xtWord1 *before, XTThreadPtr thread); |
|
187 |
void deleteAllRows(XTThreadPtr self); |
|
188 |
};
|
|
189 |
||
190 |
class XTDDIndex : public XTDDConstraint { |
|
191 |
public: |
|
192 |
u_int in_index; |
|
193 |
||
194 |
XTDDIndex(u_int type) : XTDDConstraint(type), in_index((u_int) -1) { } |
|
195 |
||
196 |
virtual XTObject *factory(XTThreadPtr self) { |
|
197 |
XTObject *new_obj; |
|
198 |
||
199 |
if (!(new_obj = new XTDDIndex(XT_DD_UNKNOWN))) |
|
200 |
xt_throw_errno(XT_CONTEXT, XT_ENOMEM); |
|
201 |
return new_obj; |
|
202 |
}
|
|
203 |
||
1891.2.1
by Monty Taylor
Fixed things to make things compile with clang |
204 |
virtual void init(XTThreadPtr self) { XTDDConstraint::init(self); } |
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
205 |
virtual void init(XTThreadPtr self, XTObject *obj); |
206 |
struct XTIndex *getIndexPtr(); |
|
207 |
};
|
|
208 |
||
209 |
/*
|
|
210 |
* A foreign key is based on a local index.
|
|
211 |
*/
|
|
212 |
class XTDDForeignKey : public XTDDIndex { |
|
213 |
public: |
|
214 |
XTPathStrPtr fk_ref_tab_name; |
|
215 |
XTDDTable *fk_ref_table; |
|
216 |
u_int fk_ref_index; /* The index on which this foreign key references. */ |
|
217 |
XTList<XTDDColumnRef> fk_ref_cols; |
|
218 |
int fk_on_delete; |
|
219 |
int fk_on_update; |
|
220 |
||
221 |
XTDDForeignKey() : XTDDIndex(XT_DD_KEY_FOREIGN), |
|
222 |
fk_ref_tab_name(NULL), |
|
223 |
fk_ref_table(NULL), |
|
224 |
fk_ref_index(UINT_MAX), |
|
225 |
fk_on_delete(0), |
|
226 |
fk_on_update(0) { |
|
227 |
}
|
|
228 |
||
229 |
virtual XTObject *factory(XTThreadPtr self) { |
|
230 |
XTObject *new_obj; |
|
231 |
||
232 |
if (!(new_obj = new XTDDForeignKey())) |
|
233 |
xt_throw_errno(XT_CONTEXT, XT_ENOMEM); |
|
234 |
return new_obj; |
|
235 |
}
|
|
236 |
||
237 |
virtual void init(XTThreadPtr self) { XTDDIndex::init(self); } |
|
238 |
virtual void init(XTThreadPtr self, XTObject *obj); |
|
239 |
virtual void finalize(XTThreadPtr self); |
|
240 |
virtual void loadString(XTThreadPtr self, XTStringBufferPtr sb); |
|
241 |
void getReferenceList(char *buffer, size_t size); |
|
242 |
struct XTIndex *getReferenceIndexPtr(); |
|
243 |
bool sameReferenceColumns(XTDDConstraint *co); |
|
244 |
bool samePrefixReferenceColumns(XTDDConstraint *co); |
|
245 |
bool checkReferencedTypes(XTDDTable *dt); |
|
246 |
void removeReference(XTThreadPtr self); |
|
247 |
bool insertRow(xtWord1 *before, xtWord1 *after, XTThreadPtr thread); |
|
248 |
bool updateRow(xtWord1 *before, xtWord1 *after, XTThreadPtr thread); |
|
249 |
||
250 |
static const char *actionTypeToString(int action); |
|
251 |
};
|
|
252 |
||
253 |
class XTDDTable : public XTObject { |
|
254 |
private: |
|
255 |
||
256 |
public: |
|
257 |
struct XTTable *dt_table; |
|
258 |
||
259 |
XTList<XTDDColumn> dt_cols; |
|
260 |
XTList<XTDDIndex> dt_indexes; |
|
261 |
||
1753.3.1
by Paul McCullagh
Merged with 1.1 trunk |
262 |
XTRecurRWLockRec dt_ref_lock; /* The lock for adding and using references. */ |
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
263 |
XTList<XTDDForeignKey> dt_fkeys; /* The foreign keys on this table. */ |
264 |
XTDDTableRef *dt_trefs; /* A list of tables that reference this table. */ |
|
265 |
||
266 |
virtual XTObject *factory(XTThreadPtr self) { |
|
267 |
XTObject *new_obj; |
|
268 |
||
269 |
if (!(new_obj = new XTDDTable())) |
|
270 |
xt_throw_errno(XT_CONTEXT, XT_ENOMEM); |
|
271 |
return new_obj; |
|
272 |
}
|
|
273 |
||
274 |
virtual void init(XTThreadPtr self); |
|
275 |
virtual void init(XTThreadPtr self, XTObject *obj); |
|
276 |
virtual void finalize(XTThreadPtr self); |
|
277 |
||
278 |
XTDDColumn *findColumn(char *name); |
|
279 |
void loadString(XTThreadPtr self, XTStringBufferPtr sb); |
|
280 |
void loadForeignKeyString(XTThreadPtr self, XTStringBufferPtr sb); |
|
281 |
void checkForeignKeyReference(XTThreadPtr self, XTDDForeignKey *fk); |
|
282 |
void attachReferences(XTThreadPtr self, struct XTDatabase *db); |
|
283 |
void attachReference(XTThreadPtr self, XTDDForeignKey *fk); |
|
284 |
void alterColumnName(XTThreadPtr self, char *from_name, char *to_name); |
|
285 |
void attachReference(XTThreadPtr self, XTDDTable *dt); |
|
286 |
void removeReferences(XTThreadPtr self); |
|
287 |
void removeReference(XTThreadPtr self, XTDDForeignKey *fk); |
|
288 |
void checkForeignKeys(XTThreadPtr self, bool temp_table); |
|
289 |
XTDDIndex *findIndex(XTDDConstraint *co); |
|
290 |
XTDDIndex *findReferenceIndex(XTDDForeignKey *fk); |
|
291 |
bool insertRow(struct XTOpenTable *rec_ot, xtWord1 *buffer); |
|
292 |
bool checkNoAction(struct XTOpenTable *ot, xtRecordID rec_id); |
|
293 |
xtBool checkCanDrop(xtBool drop_db); |
|
294 |
bool deleteRow(struct XTOpenTable *rec_ot, xtWord1 *buffer); |
|
295 |
void deleteAllRows(XTThreadPtr self); |
|
296 |
bool updateRow(struct XTOpenTable *rec_ot, xtWord1 *before, xtWord1 *after); |
|
297 |
};
|
|
298 |
||
299 |
XTDDTable *xt_ri_create_table(XTThreadPtr self, bool convert, XTPathStrPtr tab_path, char *sql, XTDDTable *my_tab, struct XTDictionary *source_dic); |
|
300 |
||
301 |
#endif
|