1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
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.
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.
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
29
#ifdef USE_PRAGMA_IMPLEMENTATION
30
#pragma implementation // gcc: Class implementation
33
#include "xt_config.h"
45
#include "strutil_xt.h"
46
#include "database_xt.h"
47
#include "discover_xt.h"
48
#include "systab_xt.h"
51
/* Note: mysql_priv.h messes with new, which caused a crash. */
57
* ---------------------------------------------------------------
62
ha_xtsys::ha_xtsys(handlerton *hton, TableShare& table_arg):
63
handler(*hton, table_arg),
68
ha_xtsys::ha_xtsys(handlerton *hton, TABLE_SHARE *table_arg):
69
handler(hton, table_arg),
76
static const char *ha_pbms_exts[] = {
81
const char **ha_xtsys::bas_ext() const
86
int ha_xtsys::open(const char *table_path, int XT_UNUSED(mode), uint XT_UNUSED(test_if_locked))
88
THD *thd = current_thd;
93
if (!(self = xt_ha_set_current_thread(thd, &e)))
94
return xt_ha_pbxt_to_mysql_error(e.e_xt_err);
97
xt_ha_open_database_of_table(self, (XTPathStrPtr) table_path);
99
ha_open_tab = XTSystemTableShare::openSystemTable(self, table_path, table);
100
ha_lock.init(ha_open_tab->ost_share->sts_my_lock);
101
ref_length = ha_open_tab->getRefLen();
104
err = xt_ha_pbxt_thread_error_for_mysql(thd, self, FALSE);
106
ha_open_tab->release(self);
115
int ha_xtsys::close(void)
117
THD *thd = current_thd;
119
volatile XTThreadPtr self = NULL;
123
self = xt_ha_set_current_thread(thd, &e);
125
if (!(self = xt_create_thread("TempForClose", FALSE, TRUE, &e))) {
126
xt_log_exception(NULL, &e, XT_LOG_DEFAULT);
134
ha_open_tab->release(self);
139
err = xt_ha_pbxt_thread_error_for_mysql(thd, self, FALSE);
144
xt_free_thread(self);
147
xt_log(XT_NS_CONTEXT, XT_LOG_WARNING, "Unable to release table reference\n");
152
int ha_xtsys::doStartTableScan(bool XT_UNUSED(scan))
156
if (!ha_open_tab->seqScanInit())
157
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
162
int ha_xtsys::rnd_next(byte *buf)
167
if (!ha_open_tab->seqScanNext((char *) buf, &eof)) {
169
err = HA_ERR_END_OF_FILE;
171
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
177
void ha_xtsys::position(const byte *record)
180
rec_id = ha_open_tab->seqScanPos((xtWord1 *) record);
181
mi_int4store((xtWord1 *) ref, rec_id);
184
int ha_xtsys::rnd_pos(byte * buf, byte *pos)
189
rec_id = mi_uint4korr((xtWord1 *) pos);
190
if (!ha_open_tab->seqScanRead(rec_id, (char *) buf))
191
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
196
int ha_xtsys::info(uint XT_UNUSED(flag))
201
int ha_xtsys::external_lock(THD *thd, int lock_type)
208
if (!(self = xt_ha_set_current_thread(thd, &e)))
209
return xt_ha_pbxt_to_mysql_error(e.e_xt_err);
211
if (lock_type == F_UNLCK)
212
ok = ha_open_tab->unuse();
214
ok = ha_open_tab->use();
217
err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
222
THR_LOCK_DATA **ha_xtsys::store_lock(THD *XT_UNUSED(thd), THR_LOCK_DATA **to, enum thr_lock_type lock_type)
224
if (lock_type != TL_IGNORE && ha_lock.type == TL_UNLOCK)
225
ha_lock.type = lock_type;
230
/* Note: ha_pbxt::delete_system_table is called instead. */
231
int ha_xtsys::delete_table(const char *XT_UNUSED(table_path))
233
/* Should never be called */
237
int ha_xtsys::create(const char *XT_UNUSED(name), TABLE *XT_UNUSED(table_arg), HA_CREATE_INFO *XT_UNUSED(create_info))
239
/* Allow the table to be created.
240
* This is required after a dump is restored.
245
bool ha_xtsys::get_error_message(int XT_UNUSED(error), String *buf)
247
THD *thd = current_thd;
251
if (!(self = xt_ha_set_current_thread(thd, &e)))
254
if (!self->t_exception.e_xt_err)
257
buf->copy(self->t_exception.e_err_msg, strlen(self->t_exception.e_err_msg), system_charset_info);