~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/ha_xtsys.cc

Remove dead memset call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
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
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
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
 
 
61
#ifdef DRIZZLED
 
62
ha_xtsys::ha_xtsys(handlerton *hton, TableShare& table_arg):
 
63
handler(*hton, table_arg),
 
64
ha_open_tab(NULL)
 
65
{
 
66
}
 
67
#else
 
68
ha_xtsys::ha_xtsys(handlerton *hton, TABLE_SHARE *table_arg):
 
69
handler(hton, table_arg),
 
70
ha_open_tab(NULL)
 
71
{
 
72
        init();
 
73
}
 
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
 
 
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();
 
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
 
 
152
int ha_xtsys::doStartTableScan(bool XT_UNUSED(scan))
 
153
{
 
154
        int err = 0;
 
155
 
 
156
        if (!ha_open_tab->seqScanInit())
 
157
                err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
 
158
 
 
159
        return err;
 
160
}
 
161
 
 
162
int ha_xtsys::rnd_next(byte *buf)
 
163
{
 
164
        bool    eof;
 
165
        int             err = 0;
 
166
 
 
167
        if (!ha_open_tab->seqScanNext((char *) buf, &eof)) {
 
168
                if (eof)
 
169
                        err = HA_ERR_END_OF_FILE;
 
170
                else
 
171
                        err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
 
172
        }
 
173
 
 
174
        return err;
 
175
}
 
176
 
 
177
void ha_xtsys::position(const byte *record)
 
178
{
 
179
        xtWord4 rec_id;
 
180
        rec_id = ha_open_tab->seqScanPos((xtWord1 *) record);
 
181
        mi_int4store((xtWord1 *) ref, rec_id);
 
182
}
 
183
 
 
184
int ha_xtsys::rnd_pos(byte * buf, byte *pos)
 
185
{
 
186
        int             err = 0;
 
187
        xtWord4 rec_id;
 
188
 
 
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);
 
192
 
 
193
        return err;
 
194
}
 
195
 
 
196
int ha_xtsys::info(uint XT_UNUSED(flag))
 
197
{
 
198
        return 0;
 
199
}
 
200
 
 
201
int ha_xtsys::external_lock(THD *thd, int lock_type)
 
202
{
 
203
        XTExceptionRec  e;
 
204
        XTThreadPtr             self;
 
205
        int                             err = 0;
 
206
        bool                    ok;
 
207
 
 
208
        if (!(self = xt_ha_set_current_thread(thd, &e)))
 
209
                return xt_ha_pbxt_to_mysql_error(e.e_xt_err);
 
210
 
 
211
        if (lock_type == F_UNLCK)
 
212
                ok = ha_open_tab->unuse();
 
213
        else
 
214
                ok = ha_open_tab->use();
 
215
 
 
216
        if (!ok)
 
217
                err = xt_ha_pbxt_thread_error_for_mysql(current_thd, xt_get_self(), FALSE);
 
218
 
 
219
        return err;
 
220
}
 
221
 
 
222
THR_LOCK_DATA **ha_xtsys::store_lock(THD *XT_UNUSED(thd), THR_LOCK_DATA **to, enum thr_lock_type lock_type)
 
223
{
 
224
        if (lock_type != TL_IGNORE && ha_lock.type == TL_UNLOCK)
 
225
                ha_lock.type = lock_type;
 
226
        *to++ = &ha_lock;
 
227
        return to;
 
228
}
 
229
 
 
230
/* Note: ha_pbxt::delete_system_table is called instead. */
 
231
int ha_xtsys::delete_table(const char *XT_UNUSED(table_path))
 
232
{
 
233
        /* Should never be called */
 
234
        return 0;
 
235
}
 
236
 
 
237
int ha_xtsys::create(const char *XT_UNUSED(name), TABLE *XT_UNUSED(table_arg), HA_CREATE_INFO *XT_UNUSED(create_info))
 
238
{
 
239
        /* Allow the table to be created.
 
240
         * This is required after a dump is restored.
 
241
         */
 
242
        return 0;
 
243
}
 
244
 
 
245
bool ha_xtsys::get_error_message(int XT_UNUSED(error), String *buf)
 
246
{
 
247
        THD                             *thd = current_thd;
 
248
        XTExceptionRec  e;
 
249
        XTThreadPtr             self;
 
250
 
 
251
        if (!(self = xt_ha_set_current_thread(thd, &e)))
 
252
                return FALSE;
 
253
 
 
254
        if (!self->t_exception.e_xt_err)
 
255
                return FALSE;
 
256
 
 
257
        buf->copy(self->t_exception.e_err_msg, strlen(self->t_exception.e_err_msg), system_charset_info);
 
258
        return TRUE;
 
259
}
 
260