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) 2008 PrimeBase Technologies GmbH, Germany
|
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
2 |
*
|
3 |
* PrimeBase Media Stream for MySQL
|
|
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 |
* Paul McCullagh
|
|
20 |
*
|
|
21 |
* 2007-05-20
|
|
22 |
*
|
|
23 |
* H&G2JCtL
|
|
24 |
*
|
|
25 |
* Table handler.
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
||
29 |
#ifdef USE_PRAGMA_IMPLEMENTATION
|
|
30 |
#pragma implementation // gcc: Class implementation |
|
31 |
#endif
|
|
32 |
||
33 |
#include "xt_config.h" |
|
34 |
||
35 |
#include <stdlib.h> |
|
36 |
#include <time.h> |
|
37 |
||
38 |
#ifdef DRIZZLED
|
|
39 |
#include <fcntl.h> |
|
40 |
#endif
|
|
41 |
||
42 |
#include "ha_xtsys.h" |
|
43 |
#include "ha_pbxt.h" |
|
44 |
||
45 |
#include "strutil_xt.h" |
|
46 |
#include "database_xt.h" |
|
47 |
#include "discover_xt.h" |
|
48 |
#include "systab_xt.h" |
|
49 |
#include "xt_defs.h" |
|
50 |
||
51 |
/* Note: mysql_priv.h messes with new, which caused a crash. */
|
|
52 |
#ifdef new
|
|
53 |
#undef new
|
|
54 |
#endif
|
|
55 |
||
56 |
/*
|
|
57 |
* ---------------------------------------------------------------
|
|
58 |
* HANDLER INTERFACE
|
|
59 |
*/
|
|
60 |
||
1510.1.1
by Paul McCullagh
Merged with 1.1 trunk |
61 |
#ifdef DRIZZLED
|
1869.1.4
by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy |
62 |
ha_xtsys::ha_xtsys(handlerton *hton, Table& table_arg): |
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
63 |
handler(*hton, table_arg), |
1510.1.1
by Paul McCullagh
Merged with 1.1 trunk |
64 |
ha_open_tab(NULL) |
65 |
{
|
|
66 |
}
|
|
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
67 |
#else
|
1510.1.1
by Paul McCullagh
Merged with 1.1 trunk |
68 |
ha_xtsys::ha_xtsys(handlerton *hton, TABLE_SHARE *table_arg): |
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
69 |
handler(hton, table_arg), |
70 |
ha_open_tab(NULL) |
|
71 |
{
|
|
72 |
init(); |
|
1510.1.1
by Paul McCullagh
Merged with 1.1 trunk |
73 |
}
|
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
74 |
#endif
|
75 |
||
76 |
static const char *ha_pbms_exts[] = { |
|
77 |
"", |
|
78 |
NullS
|
|
79 |
};
|
|
80 |
||
81 |
const char **ha_xtsys::bas_ext() const |
|
82 |
{
|
|
83 |
return ha_pbms_exts; |
|
84 |
}
|
|
85 |
||
86 |
int ha_xtsys::open(const char *table_path, int XT_UNUSED(mode), uint XT_UNUSED(test_if_locked)) |
|
87 |
{
|
|
88 |
THD *thd = current_thd; |
|
89 |
XTExceptionRec e; |
|
90 |
XTThreadPtr self; |
|
91 |
int err = 0; |
|
92 |
||
93 |
if (!(self = xt_ha_set_current_thread(thd, &e))) |
|
94 |
return xt_ha_pbxt_to_mysql_error(e.e_xt_err); |
|
95 |
||
96 |
try_(a) { |
|
97 |
xt_ha_open_database_of_table(self, (XTPathStrPtr) table_path); |
|
98 |
||
1869.1.5
by Brian Aker
getTable() |
99 |
ha_open_tab = XTSystemTableShare::openSystemTable(self, table_path, getTable()); |
1753.3.1
by Paul McCullagh
Merged with 1.1 trunk |
100 |
MYSQL_INIT_LOCK(ha_lock, ha_open_tab->ost_share->sts_my_lock); |
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
101 |
ref_length = ha_open_tab->getRefLen(); |
102 |
}
|
|
103 |
catch_(a) { |
|
104 |
err = xt_ha_pbxt_thread_error_for_mysql(thd, self, FALSE); |
|
105 |
if (ha_open_tab) { |
|
106 |
ha_open_tab->release(self); |
|
107 |
ha_open_tab = NULL; |
|
108 |
}
|
|
109 |
}
|
|
110 |
cont_(a); |
|
111 |
||
112 |
return err; |
|
113 |
}
|
|
114 |
||
115 |
int ha_xtsys::close(void) |
|
116 |
{
|
|
117 |
THD *thd = current_thd; |
|
118 |
XTExceptionRec e; |
|
119 |
volatile XTThreadPtr self = NULL; |
|
120 |
int err = 0; |
|
121 |
||
122 |
if (thd) |
|
123 |
self = xt_ha_set_current_thread(thd, &e); |
|
124 |
else { |
|
125 |
if (!(self = xt_create_thread("TempForClose", FALSE, TRUE, &e))) { |
|
126 |
xt_log_exception(NULL, &e, XT_LOG_DEFAULT); |
|
127 |
return 0; |
|
128 |
}
|
|
129 |
}
|
|
130 |
||
131 |
if (self) { |
|
132 |
try_(a) { |
|
133 |
if (ha_open_tab) { |
|
134 |
ha_open_tab->release(self); |
|
135 |
ha_open_tab = NULL; |
|
136 |
}
|
|
137 |
}
|
|
138 |
catch_(a) { |
|
139 |
err = xt_ha_pbxt_thread_error_for_mysql(thd, self, FALSE); |
|
140 |
}
|
|
141 |
cont_(a); |
|
142 |
||
143 |
if (!thd) |
|
144 |
xt_free_thread(self); |
|
145 |
}
|
|
146 |
else
|
|
147 |
xt_log(XT_NS_CONTEXT, XT_LOG_WARNING, "Unable to release table reference\n"); |
|
148 |
||
149 |
return err; |
|
150 |
}
|
|
151 |
||
1753.3.1
by Paul McCullagh
Merged with 1.1 trunk |
152 |
#ifdef DRIZZLED
|
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
153 |
int ha_xtsys::doStartTableScan(bool XT_UNUSED(scan)) |
1753.3.1
by Paul McCullagh
Merged with 1.1 trunk |
154 |
#else
|
155 |
int ha_xtsys::rnd_init(bool XT_UNUSED(scan)) |
|
156 |
#endif
|
|
1455.3.1
by Vladimir Kolesnikov
lp:drizzle + pbxt 1.1 + test results |
157 |
{
|
158 |
int err = 0; |
|
159 |
||
160 |
if (!ha_open_tab->seqScanInit()) |
|
161 |
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE); |
|
162 |
||
163 |
return err; |
|
164 |
}
|
|
165 |
||
166 |
int ha_xtsys::rnd_next(byte *buf) |
|
167 |
{
|
|
168 |
bool eof; |
|
169 |
int err = 0; |
|
170 |
||
171 |
if (!ha_open_tab->seqScanNext((char *) buf, &eof)) { |
|
172 |
if (eof) |
|
173 |
err = HA_ERR_END_OF_FILE; |
|
174 |
else
|
|
175 |
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE); |
|
176 |
}
|
|
177 |
||
178 |
return err; |
|
179 |
}
|
|
180 |
||
181 |
void ha_xtsys::position(const byte *record) |
|
182 |
{
|
|
183 |
xtWord4 rec_id; |
|
184 |
rec_id = ha_open_tab->seqScanPos((xtWord1 *) record); |
|
185 |
mi_int4store((xtWord1 *) ref, rec_id); |
|
186 |
}
|
|
187 |
||
188 |
int ha_xtsys::rnd_pos(byte * buf, byte *pos) |
|
189 |
{
|
|
190 |
int err = 0; |
|
191 |
xtWord4 rec_id; |
|
192 |
||
193 |
rec_id = mi_uint4korr((xtWord1 *) pos); |
|
194 |
if (!ha_open_tab->seqScanRead(rec_id, (char *) buf)) |
|
195 |
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE); |
|
196 |
||
197 |
return err; |
|
198 |
}
|
|
199 |
||
200 |
int ha_xtsys::info(uint XT_UNUSED(flag)) |
|
201 |
{
|
|
202 |
return 0; |
|
203 |
}
|
|
204 |
||
205 |
int ha_xtsys::external_lock(THD *thd, int lock_type) |
|
206 |
{
|
|
207 |
XTExceptionRec e; |
|
208 |
XTThreadPtr self; |
|
209 |
int err = 0; |
|
210 |
bool ok; |
|
211 |
||
212 |
if (!(self = xt_ha_set_current_thread(thd, &e))) |
|
213 |
return xt_ha_pbxt_to_mysql_error(e.e_xt_err); |
|
214 |
||
215 |
if (lock_type == F_UNLCK) |
|
216 |
ok = ha_open_tab->unuse(); |
|
217 |
else
|
|
218 |
ok = ha_open_tab->use(); |
|
219 |
||
220 |
if (!ok) |
|
221 |
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE); |
|
222 |
||
223 |
return err; |
|
224 |
}
|
|
225 |
||
226 |
THR_LOCK_DATA **ha_xtsys::store_lock(THD *XT_UNUSED(thd), THR_LOCK_DATA **to, enum thr_lock_type lock_type) |
|
227 |
{
|
|
228 |
if (lock_type != TL_IGNORE && ha_lock.type == TL_UNLOCK) |
|
229 |
ha_lock.type = lock_type; |
|
230 |
*to++ = &ha_lock; |
|
231 |
return to; |
|
232 |
}
|
|
233 |
||
234 |
/* Note: ha_pbxt::delete_system_table is called instead. */
|
|
235 |
int ha_xtsys::delete_table(const char *XT_UNUSED(table_path)) |
|
236 |
{
|
|
237 |
/* Should never be called */
|
|
238 |
return 0; |
|
239 |
}
|
|
240 |
||
241 |
int ha_xtsys::create(const char *XT_UNUSED(name), TABLE *XT_UNUSED(table_arg), HA_CREATE_INFO *XT_UNUSED(create_info)) |
|
242 |
{
|
|
243 |
/* Allow the table to be created.
|
|
244 |
* This is required after a dump is restored.
|
|
245 |
*/
|
|
246 |
return 0; |
|
247 |
}
|
|
248 |
||
249 |
bool ha_xtsys::get_error_message(int XT_UNUSED(error), String *buf) |
|
250 |
{
|
|
251 |
THD *thd = current_thd; |
|
252 |
XTExceptionRec e; |
|
253 |
XTThreadPtr self; |
|
254 |
||
255 |
if (!(self = xt_ha_set_current_thread(thd, &e))) |
|
256 |
return FALSE; |
|
257 |
||
258 |
if (!self->t_exception.e_xt_err) |
|
259 |
return FALSE; |
|
260 |
||
261 |
buf->copy(self->t_exception.e_err_msg, strlen(self->t_exception.e_err_msg), system_charset_info); |
|
262 |
return TRUE; |
|
263 |
}
|
|
264 |