~drizzle-trunk/drizzle/development

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
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
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
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
18
 *
19
 * Original author: Paul McCullagh
20
 * Continued development: Barry Leslie
21
 *
22
 * 2007-05-20
23
 *
24
 * H&G2JCtL
25
 *
26
 * Table handler.
27
 *
28
 */
29
30
#ifdef USE_PRAGMA_IMPLEMENTATION
31
#pragma implementation				// gcc: Class implementation
32
#endif
33
34
#ifdef DRIZZLED
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
35
#include "config.h"
36
#include <drizzled/common.h>
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
37
#include <drizzled/plugin.h>
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
38
#include <drizzled/field.h>
39
#include <drizzled/session.h>
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
40
#include <drizzled/data_home.h>
41
#include <drizzled/error.h>
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
42
#include <drizzled/table.h>
43
#include <drizzled/plugin/transactional_storage_engine.h>
44
45
#define my_strdup(a,b) strdup(a)
46
using namespace drizzled;
47
using namespace drizzled::plugin;
48
49
50
51
#include "cslib/CSConfig.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
52
#else
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
53
#include "cslib/CSConfig.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
54
#include "mysql_priv.h"
55
#include <mysql/plugin.h>
56
#include <my_dir.h>
57
#endif 
58
59
#include <stdlib.h>
60
#include <time.h>
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
61
#include <inttypes.h>
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
62
63
1548.2.10 by Barry.Leslie at PrimeBase
Merge from trunk.
64
#include "defs_ms.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
65
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
66
#include "cslib/CSDefs.h"
67
#include "cslib/CSObject.h"
68
#include "cslib/CSGlobal.h"
69
#include "cslib/CSThread.h"
70
#include "cslib/CSStrUtil.h"
71
#include "cslib/CSLog.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
72
1548.2.10 by Barry.Leslie at PrimeBase
Merge from trunk.
73
#include "engine_ms.h"	
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
74
#include "ha_pbms.h"
1548.2.10 by Barry.Leslie at PrimeBase
Merge from trunk.
75
#include "network_ms.h"
76
#include "connection_handler_ms.h"
77
#include "open_table_ms.h"
78
#include "database_ms.h"
79
#include "temp_log_ms.h"
80
#include "system_table_ms.h"
81
#include "mysql_ms.h"
82
#include "discover_ms.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
83
#include "metadata_ms.h"
1548.2.10 by Barry.Leslie at PrimeBase
Merge from trunk.
84
#include "transaction_ms.h"
85
#include "systab_httpheader_ms.h"
86
#include "system_table_ms.h"
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
87
#include "parameters_ms.h"
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
88
#include "pbmsdaemon_ms.h"
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
89
#include "version_ms.h"
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
90
91
/* Note: 'new' used here is NOT CSObject::new which is a DEBUG define*/
92
#ifdef new
93
#undef new
94
#endif
95
96
97
#ifdef DRIZZLED
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
98
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
99
static int pbms_done_func(void *);
100
101
class PBMSStorageEngine : public drizzled::plugin::TransactionalStorageEngine {
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
102
public:
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
103
	PBMSStorageEngine()
104
	: TransactionalStorageEngine(std::string("PBMS"), HTON_NO_FLAGS | HTON_HIDDEN) {}
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
105
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
106
	~PBMSStorageEngine()
107
	{
108
		pbms_done_func(NULL);
109
	}
110
	
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
111
	int close_connection(Session *);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
112
	
113
	int doStartTransaction(Session *session, start_transaction_option_t options);
114
	int doCommit(Session *, bool);
115
	int doRollback(Session *, bool);
1869.1.4 by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy
116
	Cursor *create(Table& table);
1643.1.6 by Monty Taylor
Fix two signature change releated merge issues.
117
	bool doDropSchema(const drizzled::SchemaIdentifier&);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
118
	
119
	/*
120
	* Indicates to a storage engine the start of a
121
	* new SQL statement.
122
	*/
123
	void doStartStatement(Session *session)
124
	{
125
		(void) session;
126
	}
127
128
	/*
129
	* Indicates to a storage engine the end of
130
	* the current SQL statement in the supplied
131
	* Session.
132
	*/
133
	void doEndStatement(Session *session)
134
	{
135
		(void) session;
136
	}
137
	
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
138
	int doCreateTable(Session&, Table&, const TableIdentifier& ident, drizzled::message::Table& );	
139
	int doDropTable(Session &, const TableIdentifier& );
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
140
	
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
141
	int doRenameTable(Session&, const TableIdentifier &from, const TableIdentifier &to);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
142
	
1966.2.4 by Brian Aker
Style cleanup.
143
        void doGetTableIdentifiers(drizzled::CachedDirectory &dir,
144
                                   const drizzled::SchemaIdentifier &schema,
145
                                   drizzled::TableIdentifier::vector &set_of_identifiers) 
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
146
	{
147
		std::set<std::string> set_of_names;
148
		
149
		doGetTableNames(dir, schema, set_of_names);
150
		for (std::set<std::string>::iterator set_iter = set_of_names.begin(); set_iter != set_of_names.end(); ++set_iter)
151
		{
152
			set_of_identifiers.push_back(TableIdentifier(schema, *set_iter));
153
		}
154
	}
155
	
156
	void doGetTableNames(CachedDirectory&, 
1643.1.6 by Monty Taylor
Fix two signature change releated merge issues.
157
					const SchemaIdentifier &schema, 
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
158
					std::set<std::string> &set_of_names) 
159
	{
160
		bool isPBMS = schema.compare("PBMS");
161
		
162
		if (isPBMS || PBMSParameters::isBLOBDatabase(schema.getSchemaName().c_str()))
163
			PBMSSystemTables::getSystemTableNames(isPBMS, set_of_names);
164
	}
165
166
	int doSetSavepoint(Session *thd, NamedSavepoint &savepoint);
167
	int doRollbackToSavepoint(Session *session, NamedSavepoint &savepoint);
168
	int doReleaseSavepoint(Session *session, NamedSavepoint &savepoint);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
169
	const char **bas_ext() const;
170
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
171
  int doGetTableDefinition(Session&, const TableIdentifier &identifier,
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
172
                                          drizzled::message::Table &table_proto)
173
  {
174
		int err;
175
		const char *tab_name = identifier.getTableName().c_str();
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
176
177
		// Set some required table proto info:
178
 		table_proto.set_schema(identifier.getSchemaName().c_str());
179
		table_proto.set_creation_timestamp(0);
180
		table_proto.set_update_timestamp(0);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
181
		
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
182
		err = PBMSSystemTables::getSystemTableInfo(tab_name, table_proto);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
183
		if (err)
184
			return err;
185
			
186
		return EEXIST;
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
187
  }
188
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
189
	bool doDoesTableExist(Session&, const TableIdentifier &identifier)
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
190
	{
191
		const char *tab_name = identifier.getTableName().c_str();
192
		const char *db_name = identifier.getSchemaName().c_str();
193
		bool isPBMS = identifier.getSchemaName().compare("PBMS");
194
		
195
		if (isPBMS || PBMSParameters::isBLOBDatabase(db_name)) {
196
			return PBMSSystemTables::isSystemTable(isPBMS, tab_name);									 
197
		}
198
		
199
		return false;		
200
	}
201
202
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
203
};
204
205
PBMSStorageEngine	*pbms_hton;
206
#else
207
handlerton		*pbms_hton;
208
#endif
209
210
static const char *ha_pbms_exts[] = {
211
	NullS
212
};
213
214
/*
215
 * ---------------------------------------------------------------
216
 * UTILITIES
217
 */
218
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
219
#ifndef DRIZZLED
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
220
void pbms_take_part_in_transaction(void *thread)
221
{
222
	THD			*thd;
223
	if ((thd = (THD *) thread)) {
224
		trans_register_ha(thd, true, pbms_hton); 
225
	}
226
}
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
227
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
228
229
#ifdef DRIZZLED
230
const char **PBMSStorageEngine::bas_ext() const
231
#else
232
const char **ha_pbms::bas_ext() const
233
#endif
234
{
235
	return ha_pbms_exts;
236
}
237
238
#ifdef DRIZZLED
239
int PBMSStorageEngine::close_connection(Session *thd)
240
{
241
#else
242
static int pbms_close_connection(handlerton *hton, THD* thd)
243
{
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
244
	(void)hton;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
245
#endif
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
246
	MSEngine::closeConnection(thd);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
247
	return 0;
248
}
249
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
250
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
251
252
/*
253
 * ---------------------------------------------------------------
254
 * HANDLER INTERFACE
255
 */
256
257
258
#ifdef DRIZZLED
1869.1.4 by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy
259
Cursor *PBMSStorageEngine::create(Table& table)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
260
{
261
	PBMSStorageEngine * const hton = this;
1680.6.1 by Brian Aker
Remove call for using special new for a cursor.
262
	return new ha_pbms(hton, table);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
263
}
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
264
#else
265
static handler *pbms_create_handler(handlerton *hton, TABLE_SHARE *table, MEM_ROOT *mem_root)
266
{
267
	return new (mem_root) ha_pbms(hton, table);
268
}
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
269
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
270
271
#ifdef DRIZZLED
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
272
int PBMSStorageEngine::doStartTransaction(Session *thd, start_transaction_option_t options)
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
273
{
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
274
	(void)thd;
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
275
	(void)options;
276
	return 0;
277
}
278
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
279
int PBMSStorageEngine::doCommit(Session *thd, bool all)
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
280
{
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
281
#else
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
282
static int pbms_commit(handlerton *, THD *thd, bool all)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
283
{
284
#endif
285
	int			err = 0;
286
	CSThread	*self;
287
	PBMSResultRec result;
288
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
289
	// I am not interesed in single statement transactions.
290
	if (all == false)
291
		return 0;
292
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
293
	if (MSEngine::enterConnection(thd, &self, &result, false))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
294
		return 0;
295
	inner_();
296
	try_(a) {
297
		MSTransactionManager::commit();
298
	}
299
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
300
		err = MSEngine::exceptionToResult(&self->myException, &result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
301
	}
302
	cont_(a);
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
303
	self->myIsAutoCommit = true;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
304
	return_(err);
305
}
306
307
#ifdef DRIZZLED
1548.2.28 by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro.
308
int PBMSStorageEngine::doRollback(THD *thd, bool all)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
309
{
310
#else
1548.2.28 by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro.
311
static int pbms_rollback(handlerton *, THD *thd, bool all)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
312
{
313
#endif
314
	int			err = 0;
315
	CSThread	*self;
316
	PBMSResultRec result;
1548.2.28 by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro.
317
	
318
	UNUSED(all);
319
	
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
320
	if (MSEngine::enterConnection(thd, &self, &result, false))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
321
		return 0;
322
	inner_();
323
	try_(a) {
324
		MSTransactionManager::rollback();
325
	}
326
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
327
		err = MSEngine::exceptionToResult(&self->myException, &result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
328
	}
329
	cont_(a);
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
330
	self->myIsAutoCommit = true;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
331
	return_(err);
332
}
333
334
#ifdef DRIZZLED
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
335
int PBMSStorageEngine::doSetSavepoint(Session *thd, NamedSavepoint &savepoint)
336
{
337
	int			err = 0;
338
	CSThread	*self;
339
	PBMSResultRec result;
340
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
341
	if (MSEngine::enterConnection(thd, &self, &result, false))
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
342
		return 0;
343
	
344
	inner_();
345
	try_(a) {
346
		MSTransactionManager::setSavepoint(savepoint.getName().c_str());
347
	}
348
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
349
		err = MSEngine::exceptionToResult(&self->myException, &result);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
350
	}
351
	cont_(a);
352
	return_(err);
353
	
354
}
355
356
int PBMSStorageEngine::doRollbackToSavepoint(Session *session, NamedSavepoint &savepoint)
357
{
358
	int			err = 0;
359
	CSThread	*self;
360
	PBMSResultRec result;
361
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
362
	if (MSEngine::enterConnection(session, &self, &result, false))
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
363
		return 0;
364
	inner_();
365
	try_(a) {
366
		MSTransactionManager::rollbackTo(savepoint.getName().c_str());
367
	}
368
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
369
		err = MSEngine::exceptionToResult(&self->myException, &result);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
370
	}
371
	cont_(a);
372
	return_(err);
373
}
374
375
376
int PBMSStorageEngine::doReleaseSavepoint(Session *session, NamedSavepoint &savepoint)
377
{
378
	int			err = 0;
379
	CSThread	*self;
380
	PBMSResultRec result;
381
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
382
	if (MSEngine::enterConnection(session, &self, &result, false))
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
383
		return 0;
384
		
385
	inner_();
386
	try_(a) {
387
		MSTransactionManager::releaseSavepoint(savepoint.getName().c_str());
388
	}
389
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
390
		err = MSEngine::exceptionToResult(&self->myException, &result);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
391
	}
392
	cont_(a);
393
	return_(err);
394
}
395
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
396
#else
397
static int pbms_savepoint_set(handlerton *hton, THD *thd, void *sv)
398
{
399
	int			err = 0;
400
	CSThread	*self;
401
	PBMSResultRec result;
402
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
403
	if (MSEngine::enterConnection(thd, &self, &result, false))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
404
		return 0;
405
		
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
406
	*((uint32_t*)sv) = self->myStmtCount;
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
407
	return 0;	
408
}
409
410
static int pbms_savepoint_rollback(handlerton *hton, THD *thd, void *sv)
411
{
412
	int			err = 0;
413
	CSThread	*self;
414
	PBMSResultRec result;
415
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
416
	if (MSEngine::enterConnection(thd, &self, &result, false))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
417
		return 0;
418
	inner_();
419
	try_(a) {
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
420
		MSTransactionManager::rollbackToPosition(*((uint32_t*)sv));
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
421
	}
422
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
423
		err = MSEngine::exceptionToResult(&self->myException, &result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
424
	}
425
	cont_(a);
426
	return_(err);
427
}
428
429
static int pbms_savepoint_release(handlerton *hton, THD *thd, void *sv)
430
{
431
	return 0;
432
}
433
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
434
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
435
436
#ifdef DRIZZLED
1643.1.6 by Monty Taylor
Fix two signature change releated merge issues.
437
bool  PBMSStorageEngine::doDropSchema(const drizzled::SchemaIdentifier &schema)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
438
{
1548.2.6 by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle.
439
	CSThread *self;
440
	PBMSResultRec result;
441
	
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
442
	if (MSEngine::enterConnectionNoThd(&self, &result))
1548.2.6 by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle.
443
		return false;
444
	inner_();
445
	
446
	try_(a) {
447
		MSDatabase::dropDatabase(schema.getSchemaName().c_str());
448
	}
449
	catch_(a);
450
	self->logException();
451
	cont_(a);
452
	return_(false);
453
}
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
454
#else
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
455
static void pbms_drop_database(handlerton *, char *path)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
456
{
457
	CSThread *self;
458
	char db_name[PATH_MAX];
459
	PBMSResultRec result;
460
	
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
461
	if (MSEngine::enterConnectionNoThd(&self, &result))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
462
		return;
463
	inner_();
464
	
465
	cs_strcpy(PATH_MAX, db_name, cs_last_directory_of_path(path));
466
	cs_remove_dir_char(db_name);
467
	try_(a) {
468
		MSDatabase::dropDatabase(db_name);
469
	}
470
	catch_(a);
471
	self->logException();
472
	cont_(a);
473
	exit_();
474
}
1548.2.6 by Barry.Leslie at PrimeBase
trunk merge plus more pbms updates for drizzle.
475
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
476
477
static bool pbms_started = false;
478
479
480
#ifdef DRIZZLED
1548.2.23 by Barry.Leslie at PrimeBase
And more cleanup.
481
int pbms_init_func(module::Context &registry);
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
482
int pbms_init_func(module::Context &registry)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
483
#else
1548.2.23 by Barry.Leslie at PrimeBase
And more cleanup.
484
int pbms_init_func(void *p);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
485
int pbms_discover_system_tables(handlerton *hton, THD* thd, const char *db, const char *name, uchar **frmblob, size_t *frmlen);
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
486
int pbms_init_func(void *p)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
487
#endif
488
{
489
	PBMSResultRec		result;
490
	int					err;
491
	int					my_res = 0;
492
	CSThread			*thread;
493
494
	ASSERT(!pbms_started);
495
	pbms_started = false;
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
496
	PBMSDaemon::setDaemonState(PBMSDaemon::DaemonStartUp);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
497
	
498
	{
499
		char info[120];
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
500
		snprintf(info, 120, "PrimeBase Media Stream (PBMS) Daemon %s loaded...", PBMSVersion::getCString());
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
501
		CSL.logLine(NULL, CSLog::Protocol, info);
502
	}
503
	CSL.logLine(NULL, CSLog::Protocol, "Barry Leslie, PrimeBase Technologies GmbH, http://www.primebase.org");
504
	
505
	if ((err = MSEngine::startUp(&result))) {
506
		CSL.logLine(NULL, CSLog::Error, result.mr_message);
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
507
		PBMSDaemon::setDaemonState(PBMSDaemon::DaemonError);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
508
		return(1);
509
	}
510
511
#ifdef DRIZZLED
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
512
		pbms_hton= new PBMSStorageEngine();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
513
		registry.add(pbms_hton);
514
#else
515
	pbms_hton = (handlerton *) p;
516
	pbms_hton->state = SHOW_OPTION_YES;
517
	pbms_hton->close_connection = pbms_close_connection; /* close_connection, cleanup thread related data. */
518
	pbms_hton->create = pbms_create_handler;
519
	pbms_hton->flags = HTON_CAN_RECREATE | HTON_HIDDEN;
520
	pbms_hton->drop_database = pbms_drop_database; /* Drop a database */
521
	pbms_hton->discover = pbms_discover_system_tables;
522
523
	pbms_hton->commit = pbms_commit; /* commit */
524
	pbms_hton->rollback = pbms_rollback; /* rollback */
525
526
	pbms_hton->savepoint_offset = 4;
527
	pbms_hton->savepoint_set = pbms_savepoint_set;
528
	pbms_hton->savepoint_rollback = pbms_savepoint_rollback; 
529
	pbms_hton->savepoint_release = pbms_savepoint_release; 
530
#endif
531
	
532
	/* Startup the Media Stream network: */
533
	cs_init_memory();
534
	CSThread::startUp();
535
	if (!(thread = CSThread::newCSThread())) {
536
		CSException::logOSError(CS_CONTEXT, ENOMEM);
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
537
		PBMSDaemon::setDaemonState(PBMSDaemon::DaemonError);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
538
		return(1);
539
	}
540
	if (!CSThread::attach(thread)) {
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
541
		PBMSDaemon::setDaemonState(PBMSDaemon::DaemonError);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
542
		thread->myException.log(NULL);
543
		CSThread::shutDown();
544
		cs_exit_memory();
545
		MSEngine::shutDown();
546
		return(1);
547
	}
548
	enter_();
549
	try_(a) {
550
		thread->threadName = CSString::newString("startup");
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
551
		MSDatabase::startUp(PBMSParameters::getDefaultMetaDataHeaders());
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
552
		MSTableList::startUp();
553
		MSSystemTableShare::startUp();
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
554
		MSNetwork::startUp(PBMSParameters::getPortNumber());
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
555
		MSTransactionManager::startUp();
556
		MSNetwork::startNetwork();
557
	}
558
	catch_(a) {
559
		self->logException();
560
		my_res = 1;
561
	}
562
	cont_(a);
563
	if (my_res) {
564
		try_(b) {
565
			MSNetwork::shutDown();
566
			MSTransactionManager::shutDown();
567
			MSSystemTableShare::shutDown();
568
			MSDatabase::stopThreads();
569
			MSTableList::shutDown();
570
			MSDatabase::shutDown();
571
			CSThread::shutDown();
572
		}
573
		catch_(b) {
574
			self->logException();
575
		}
576
		cont_(b);
577
	}
578
	outer_();
579
	CSThread::detach(thread);
580
581
	if (my_res) {
582
		cs_exit_memory();
583
		MSEngine::shutDown();
584
	}
585
	else {
586
		srandom(time(NULL));
587
		pbms_started = true;
588
		
589
	}
590
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
591
	if (pbms_started)
592
		PBMSDaemon::setDaemonState(PBMSDaemon::DaemonRunning);
593
	else
594
		PBMSDaemon::setDaemonState(PBMSDaemon::DaemonError);
595
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
596
	return(my_res);
597
}
598
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
599
#ifdef DRIZZLED
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
600
static int pbms_done_func(void *)
1548.2.3 by Barry.Leslie at PrimeBase
Added drizzle event observer class to PBMS as well as a lot of mostly minor changes for drizzle compatability.
601
#else
602
int pbms_done_func(void *)
603
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
604
{
605
	CSThread	*thread;
606
607
	if (!pbms_started)
608
		return 0;
609
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
610
	PBMSDaemon::setDaemonState(PBMSDaemon::DaemonShuttingDown);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
611
	CSL.logLine(NULL, CSLog::Protocol, "PrimeBase Media Stream (PBMS) Daemon shutdown...");
612
	
613
	/* Shutdown the Media Stream network. */
614
	if (!(thread = CSThread::newCSThread()))
615
		CSException::logOSError(CS_CONTEXT, ENOMEM);
616
	else if (!CSThread::attach(thread))
617
		thread->myException.log(NULL);
618
	else {
619
		enter_();
620
		try_(a) {
621
			thread->threadName = CSString::newString("shutdown");
622
			MSNetwork::shutDown();
623
			MSSystemTableShare::shutDown();
624
			/* Ensure that the database threads are stopped before
625
			 * freeing the tables.
626
			 */
627
			MSDatabase::stopThreads();
628
			MSTableList::shutDown();
629
			/* Databases must be shutdown after table because tables
630
			 * have references to repositories.
631
			 */
632
			MSDatabase::shutDown();
633
			
634
			/* Shutdown the transaction manager after the databases
635
			 * incase they want to commit or rollback a transaction.
636
			 */
637
			MSTransactionManager::shutDown();
638
		}
639
		catch_(a) {
640
			self->logException();
641
		}
642
		cont_(a);
643
		outer_();
644
		CSThread::shutDown();
645
		CSThread::detach(thread);
646
	}
647
648
	MSEngine::shutDown();
649
	cs_exit_memory();
650
651
	CSL.logLine(NULL, CSLog::Protocol, "PrimeBase Media Stream (PBMS) Daemon shutdown completed");
652
	pbms_started = false;
653
	return(0);
654
}
655
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
656
#ifdef DRIZZLED
1869.1.4 by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy
657
ha_pbms::ha_pbms(handlerton *hton, Table& table_arg) : handler(*hton, table_arg),
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
658
#else
659
ha_pbms::ha_pbms(handlerton *hton, TABLE_SHARE *table_arg) : handler(hton, table_arg),
660
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
661
ha_open_tab(NULL),
662
ha_error(0)
663
{
664
	memset(&ha_result, 0, sizeof(PBMSResultRec));
665
}
666
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
667
#ifndef DRIZZLED
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
668
MX_TABLE_TYPES_T ha_pbms::table_flags() const
669
{
670
	return (
671
		/* We need this flag because records are not packed
672
		 * into a table which means #ROWID != offset
673
		 */
674
		HA_REC_NOT_IN_SEQ |
675
		HA_CAN_SQL_HANDLER |
676
#if MYSQL_VERSION_ID > 50119
677
		/* We can do row logging, but not statement, because
678
		 * MVCC is not serializable!
679
		 */
680
		HA_BINLOG_ROW_CAPABLE |
681
#endif
682
		/*
683
		 * Auto-increment is allowed on a partial key.
684
		 */
685
		0);
686
}
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
687
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
688
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
689
int ha_pbms::open(const char *table_path, int , uint )
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
690
{
691
	CSThread *self;
692
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
693
	if ((ha_error = MSEngine::enterConnection(current_thd, &self, &ha_result, true)))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
694
		return 1;
695
696
	inner_();
697
	try_(a) {
1869.1.5 by Brian Aker
getTable()
698
		ha_open_tab = MSSystemTableShare::openSystemTable(table_path, getTable());
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
699
#ifdef DRIZZLED
1689.2.13 by Brian Aker
More encapsulation of thr_lock
700
		ha_lock.init(&ha_open_tab->myShare->myThrLock);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
701
#else
702
		thr_lock_data_init(&ha_open_tab->myShare->myThrLock, &ha_lock, NULL);
703
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
704
		ref_length = ha_open_tab->getRefLen();
705
	}
706
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
707
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
708
	}
709
	cont_(a);
710
	return_(ha_error != MS_OK);
711
}
712
713
int ha_pbms::close(void)
714
{
715
	CSThread *self;
716
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
717
	if ((ha_error = MSEngine::enterConnection(current_thd, &self, &ha_result, true)))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
718
		return 1;
719
720
	inner_();
721
	if (ha_open_tab) {
722
		ha_open_tab->release();
723
		ha_open_tab = NULL;
724
	}
725
	outer_();
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
726
	MSEngine::exitConnection();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
727
	return 0;
728
}
729
730
#ifdef PBMS_HAS_KEYS
731
/* Index access functions: */
1548.2.28 by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro.
732
int ha_pbms::index_init(uint idx, bool sorted)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
733
{
734
	int err = 0;
1548.2.28 by Barry.Leslie at PrimeBase
Replaced the use of __attribute__((unused)) with my own macro.
735
	UNUSED(sorted);
736
	
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
737
	enter_();
738
	try_(a) {
739
		ha_open_tab->index_init(idx);
740
	}
741
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
742
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
743
		err = 1;
744
	}
745
	cont_(a);
746
	return_(err);
747
}
748
749
//-------
750
int ha_pbms::index_end()
751
{
752
	int err = 0;
753
	enter_();
754
	try_(a) {
755
		ha_open_tab->index_end();
756
	}
757
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
758
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
759
		err = 1;
760
	}
761
	cont_(a);
762
	return_(err);
763
}
764
765
//-------
766
int ha_pbms::index_read(byte * buf, const byte * key,
767
							 uint key_len, enum ha_rkey_function find_flag)
768
{
769
	int err = 0;
770
	enter_();
771
	try_(a) {
772
		if (!ha_open_tab->index_read(buf, key, key_len, find_flag))
773
			err = HA_ERR_KEY_NOT_FOUND;
774
775
	}
776
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
777
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
778
		err = 1;
779
	}
780
	cont_(a);
781
	return_(err);
782
}
783
784
//-------
785
int ha_pbms::index_read_idx(byte * buf, uint idx, const byte * key,
786
									 uint key_len, enum ha_rkey_function find_flag)
787
{
788
	int err = 0;
789
	enter_();
790
	try_(a) {
791
		if (!ha_open_tab->index_read_idx(buf, idx, key, key_len, find_flag))
792
			err = HA_ERR_KEY_NOT_FOUND;
793
	}
794
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
795
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
796
		err = 1;
797
	}
798
	cont_(a);
799
	return_(err);
800
}
801
802
//-------
803
int ha_pbms::index_next(byte * buf)
804
{
805
	int err = 0;
806
	enter_();
807
	try_(a) {
808
		if (!ha_open_tab->index_next(buf))
809
			err = HA_ERR_END_OF_FILE;
810
	}
811
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
812
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
813
		err = 1;
814
	}
815
	cont_(a);
816
	return_(err);
817
}
818
819
//-------
820
int ha_pbms::index_prev(byte * buf)
821
{
822
	int err = 0;
823
	enter_();
824
	try_(a) {
825
		if (!ha_open_tab->index_prev(buf))
826
			err = HA_ERR_END_OF_FILE;
827
	}
828
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
829
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
830
		err = 1;
831
	}
832
	cont_(a);
833
	return_(err);
834
}
835
836
//-------
837
int ha_pbms::index_first(byte * buf)
838
{
839
	int err = 0;
840
	enter_();
841
	try_(a) {
842
		if (!ha_open_tab->index_first(buf))
843
			err = HA_ERR_END_OF_FILE;
844
	}
845
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
846
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
847
		err = 1;
848
	}
849
	cont_(a);
850
	return_(err);
851
}
852
853
//-------
854
int ha_pbms::index_last(byte * buf)
855
{
856
	int err = 0;
857
	enter_();
858
	try_(a) {
859
		if (!ha_open_tab->index_last(buf))
860
			err = HA_ERR_END_OF_FILE;
861
	}
862
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
863
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
864
		err = 1;
865
	}
866
	cont_(a);
867
	return_(err);
868
}
869
870
//-------
871
int ha_pbms::index_read_last(byte * buf, const byte * key, uint key_len)
872
{
873
	int err = 0;
874
	enter_();
875
	try_(a) {
876
		if (!ha_open_tab->index_read_last(buf, key, key_len))
877
			err = HA_ERR_KEY_NOT_FOUND;
878
	}
879
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
880
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
881
		err = 1;
882
	}
883
	cont_(a);
884
	return_(err);
885
}
886
887
//-------
888
889
#endif // PBMS_HAS_KEYS
890
891
/* Sequential scan functions: */
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
892
#ifdef DRIZZLED
893
int ha_pbms::doStartTableScan(bool )
894
#else
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
895
int ha_pbms::rnd_init(bool )
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
896
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
897
{
898
	int err = 0;
899
	enter_();
900
	try_(a) {
901
		ha_open_tab->seqScanInit();
902
	}
903
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
904
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
905
		err = 1;
906
	}
907
	cont_(a);
908
	return_(err);
909
}
910
911
//-------
912
int ha_pbms::rnd_next(unsigned char *buf)
913
{
914
	int err = 0;
915
	enter_();
916
	try_(a) {
917
		if (!ha_open_tab->seqScanNext((char *) buf))
918
			err = HA_ERR_END_OF_FILE;
919
	}
920
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
921
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
922
		err = 1;
923
	}
924
	cont_(a);
925
	return_(err);
926
}
927
928
//-------
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
929
void ha_pbms::position(const unsigned char *)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
930
{
931
	ha_open_tab->seqScanPos((uint8_t *) ref);
932
}
933
934
//-------
935
int ha_pbms::rnd_pos(unsigned char * buf, unsigned char *pos)
936
{
937
	int err = 0;
938
	enter_();
939
	try_(a) {
940
		ha_open_tab->seqScanRead((uint8_t *) pos, (char *) buf);
941
	}
942
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
943
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
944
		err = 1;
945
	}
946
	cont_(a);
947
	return_(err);
948
}
949
950
//////////////////////////////
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
951
#ifdef DRIZZLED
952
int	ha_pbms::doInsertRecord(byte * buf)
953
#else
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
954
int ha_pbms::write_row(unsigned char * buf)
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
955
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
956
{
957
	int err = 0;
958
	enter_();
959
	try_(a) {
960
		ha_open_tab->insertRow((char *) buf);
961
	}
962
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
963
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
964
		err = 1;
965
	}
966
	cont_(a);
967
	return_(err);
968
}
969
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
970
#ifdef DRIZZLED
971
int	ha_pbms::doDeleteRecord(const byte * buf)
972
#else
973
int ha_pbms::delete_row(const  unsigned char * buf)
974
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
975
{
976
	int err = 0;
977
	enter_();
978
	try_(a) {
979
		ha_open_tab->deleteRow((char *) buf);
980
	}
981
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
982
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
983
		err = 1;
984
	}
985
	cont_(a);
986
	return_(err);
987
}
988
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
989
#ifdef DRIZZLED
990
int	ha_pbms::doUpdateRecord(const byte * old_data, byte * new_data)
991
#else
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
992
int ha_pbms::update_row(const unsigned char * old_data, unsigned char * new_data)
1548.2.5 by Barry.Leslie at PrimeBase
Code cleanup pluss merged drizzle changes.
993
#endif
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
994
{
995
	int err = 0;
996
	enter_();
997
	try_(a) {
998
		ha_open_tab->updateRow((char *) old_data, (char *) new_data);
999
	}
1000
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
1001
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1002
		err = 1;
1003
	}
1004
	cont_(a);
1005
	return_(err);
1006
}
1007
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1008
int ha_pbms::info(uint )
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1009
{
1010
	return 0;
1011
}
1012
1013
int ha_pbms::external_lock(THD *thd, int lock_type)
1014
{
1015
	CSThread	*self;
1016
	int			err = 0;
1017
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
1018
	if ((ha_error = MSEngine::enterConnection(thd, &self, &ha_result, true)))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1019
		return 1;
1020
1021
	inner_();
1022
	try_(a) {
1023
		if (lock_type == F_UNLCK)
1024
			ha_open_tab->unuse();
1025
		else
1026
			ha_open_tab->use();
1027
	}
1028
	catch_(a) {
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
1029
		ha_error = MSEngine::exceptionToResult(&self->myException, &ha_result);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1030
		err = 1;
1031
	}
1032
	cont_(a);
1033
	return_(err);
1034
}
1035
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1036
THR_LOCK_DATA **ha_pbms::store_lock(THD *, THR_LOCK_DATA **to, enum thr_lock_type lock_type)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1037
{
1038
	if (lock_type != TL_IGNORE && ha_lock.type == TL_UNLOCK)
1039
		ha_lock.type = lock_type;
1040
	*to++ = &ha_lock;
1041
	return to;
1042
}
1043
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1044
1045
#ifdef DRIZZLED
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
1046
int PBMSStorageEngine::doCreateTable(Session&, Table&, const TableIdentifier& , drizzled::message::Table& )
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1047
{
1048
	/* You cannot create PBMS tables. */
1049
	return( HA_ERR_WRONG_COMMAND );
1050
}
1051
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
1052
int PBMSStorageEngine::doDropTable(Session &, const TableIdentifier& )
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1053
{
1054
	/* You cannot delete PBMS tables. */
1548.2.7 by Barry.Leslie at PrimeBase
Fixed some problems with transactions and drizzle.
1055
	return( 0 );
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1056
}
1057
1548.2.13 by Barry.Leslie at PrimeBase
Bring engine interface up to date.
1058
int PBMSStorageEngine::doRenameTable(Session&, const TableIdentifier &, const TableIdentifier &)
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1059
{
1060
	/* You cannot rename PBMS tables. */
1061
	return( HA_ERR_WRONG_COMMAND );
1062
}
1063
1064
#else // DRIZZLED
1065
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
1066
int ha_pbms::create(const char *table_name, TABLE *table, HA_CREATE_INFO *)
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1067
{
1548.2.11 by Barry.Leslie at PrimeBase
Removed libxml reqirement by using a home grown xml parser.
1068
	bool isPBMS = (strcasecmp(table->s->db.str, "PBMS") == 0);
1069
	
1070
	if (PBMSSystemTables::isSystemTable(isPBMS, cs_last_name_of_path(table_name)))
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1071
		return(0);
1072
		
1073
	/* Create only works for system tables. */
1074
	return( HA_ERR_WRONG_COMMAND );
1075
}
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1076
#endif // DRIZZLED
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1077
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1078
bool ha_pbms::get_error_message(int , String *buf)
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
1079
{
1080
	if (!ha_result.mr_code)
1081
		return false;
1082
1083
	buf->copy(ha_result.mr_message, strlen(ha_result.mr_message), system_charset_info);
1084
	return true;
1085
}
1086
1087
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
1088
CSThread *pbms_getMySelf(THD *thd);
1089
void pbms_setMySelf(THD *thd, CSThread *self);
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1090
#ifdef DRIZZLED
1548.2.24 by Barry.Leslie at PrimeBase
Reorganized code while fixing some minor problems.
1091
CSThread *pbms_getMySelf(THD *thd) { return ((CSThread *) *thd->getEngineData(pbms_hton));}
1092
void pbms_setMySelf(THD *thd, CSThread *self) { *thd->getEngineData(pbms_hton) = (void *)self;}
1093
#else
1094
CSThread *pbms_getMySelf(THD *thd) { return ((CSThread *) *thd_ha_data(thd, pbms_hton));}
1095
void pbms_setMySelf(THD *thd, CSThread *self) { *thd_ha_data(thd, pbms_hton) = (void *)self;}
1096
#endif
1097
1548.2.2 by Barry.Leslie at PrimeBase
A lot of minor changes to clean up the code and to get it to build with Drizzle.
1098