~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
/* Copyright (C) 2009 PrimeBase Technologies GmbH, Germany
 *
 * PrimeBase Media Stream for MySQL
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * Barry Leslie
 *
 * System variables table.
 *
 */
#ifdef DRIZZLED
#include <config.h>
#include <drizzled/common.h>
#include <drizzled/session.h>
#include <drizzled/field/blob.h>
#endif

#include "cslib/CSConfig.h"
#include <inttypes.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <time.h>

//#include "mysql_priv.h"
#include "cslib/CSGlobal.h"
#include "cslib/CSStrUtil.h"
#include "cslib/CSLog.h"

#include "ha_pbms.h"
//#include <plugin.h>

#include "mysql_ms.h"
#include "repository_ms.h"
#include "database_ms.h"
#include "compactor_ms.h"
#include "open_table_ms.h"
#include "discover_ms.h"



#include "systab_variable_ms.h"

#define MS_REPOSITORY_STORAGE_TYPE	"REPOSITORY"
#define MS_CLOUD_STORAGE_TYPE		"CLOUD"

DT_FIELD_INFO pbms_variable_info[]=
{
	{"Id",			NOVAL,	NULL, MYSQL_TYPE_LONG,		NULL,							NOT_NULL_FLAG,	"The variable ID"},
	{"Name",		32,		NULL, MYSQL_TYPE_VARCHAR,	&UTF8_CHARSET,	NOT_NULL_FLAG,	"PBMS variable name"},
	{"Value",	1024,	NULL, MYSQL_TYPE_VARCHAR,	&UTF8_CHARSET,	0,	"PBMS variable value."},
	{"Description",	124,	NULL, MYSQL_TYPE_VARCHAR,	&UTF8_CHARSET,	NOT_NULL_FLAG,	"PBMS variable description."},
	{NULL,NOVAL, NULL, MYSQL_TYPE_STRING,NULL, 0, NULL}
};

DT_KEY_INFO pbms_variable_keys[]=
{
	{"pbms_variable_pk", PRI_KEY_FLAG, {"Id", NULL}},
	{NULL, 0, {NULL}}
};

typedef const char *(*PBMSVarGetFunc)(MSDatabase *db, const char *dflt_value);
typedef const char *(*PBMSVarCheckFunc)(char *value, bool *ok);
typedef void (*PBMSVarActionFunc)(MSDatabase *db, const char *value);

typedef struct {
	bool hidden;			// true if the value is not to be displayed
	const char *name;
	const char *value;
	const char *info;
	bool save;			// true if the value is to be saved to disk on update
	PBMSVarGetFunc get;
	PBMSVarCheckFunc check;
	PBMSVarActionFunc action;
} PBMSVariableRec, *PBMSVariablePtr;

CSLock MSVariableTable::gVarLock;

//---------------------------
static char *cleanupVariable(char *value, int *len)
{
	char *ptr;
	
	while (*value && isspace(*value)) value++;
	ptr = value + strlen(value) -1;
	while ((ptr > value) && isspace(*ptr)) ptr--;
	ptr++;
	*ptr = 0;
	
	ptr = value;
	while (*ptr) {
		*ptr = toupper(*ptr);
		ptr++;
	}
	
	*len = ptr - value;
	return value;
}

//---------------------------
static const char *get_DumpRestore(MSDatabase *db, const char *)
{
	const char *value;
	enter_();
	push_(db);
	if (db->isRecovering())
		value = "TRUE";
	else
		value = "FALSE";
	release_(db);
	return_(value);
}

//---------------------------
static const char *readOnlyCheck(char *, bool *ok)
{
	*ok = false;
	return "Value is Read Only.";
}
//---------------------------
static const char *boolCheck(char *value, bool *ok)
{
	const char *val = "Invalid boolean variable, try 'true' or 'false'";
	int len;
	
	value = cleanupVariable(value, &len);
	
	*ok = false;
	switch (*value) {
		case '0':
			if (len == 1) {
				*ok = true;
				val = "FALSE";
			}
			break;
			
		case '1':
			if (len == 1) {
				*ok = true;
				val = "TRUE";
			}
			break;
			
		case 'T':
			if (!strcmp(value, "TRUE")) {
				*ok = true;
				val = "TRUE";
			}
			break;
			
		case 'F':
			if (!strcmp(value, "FALSE")) {
				*ok = true;
				val = "FALSE";
			}
			break;
			
				
	}
	
	return val;
}

//---------------------------
static const char *storageTypeCheck(char *value, bool *ok)
{
	const char *val = "Invalid storage type, try '"MS_REPOSITORY_STORAGE_TYPE"' or '"MS_CLOUD_STORAGE_TYPE"'";
	int len;
	
	value = cleanupVariable(value, &len);
	*ok = false;
	
	if (!strcmp(value, MS_REPOSITORY_STORAGE_TYPE)) {
		*ok = true;
		val = MS_REPOSITORY_STORAGE_TYPE;
	} else if (!strcmp(value, MS_CLOUD_STORAGE_TYPE)) {
		*ok = true;
		val = MS_CLOUD_STORAGE_TYPE;
	}
	
	return val;
}

//---------------------------
static void set_DumpRestore(MSDatabase *db, const char *value)
{
	enter_();
	push_(db);
	db->setRecovering((strcmp(value, "TRUE") == 0));
	release_(db);
	exit_();
}

//---------------------------
static void set_StorageType(MSDatabase *db, const char *value)
{
	enter_();
	push_(db);

	if (!strcmp(value, MS_REPOSITORY_STORAGE_TYPE))
		db->myBlobType = MS_STANDARD_STORAGE;
	else if (!strcmp(value, MS_CLOUD_STORAGE_TYPE))
		db->myBlobType = MS_CLOUD_STORAGE;

	release_(db);
	exit_();
}

//---------------------------
static const char *get_StorageType(MSDatabase *db, const char *)
{
	const char *value = "Unknown";
	enter_();
	push_(db);

	if (db->myBlobType == MS_STANDARD_STORAGE)
		value = MS_REPOSITORY_STORAGE_TYPE;
	else if (db->myBlobType == MS_CLOUD_STORAGE)
		value = MS_CLOUD_STORAGE_TYPE;

	release_(db);
	return_(value);
}

//---------------------------
static const char *get_S3CloudRefNo(MSDatabase *db, const char *)
{
	static char value[20];
	uint32_t	num;
	enter_();
	push_(db);
	
	num = db->myBlobCloud->cl_getDefaultCloudRef();
	snprintf(value, 20, "%"PRIu32"", num);
	
	release_(db);
	return_(value);
}

//---------------------------
static void set_S3CloudRefNo(MSDatabase *db, const char *value)
{
	enter_();
	push_(db);
	
	db->myBlobCloud->cl_setDefaultCloudRef(atol(value));
	
	release_(db);
	exit_();
}

//---------------------------
static void set_BackupNo(MSDatabase *db, const char *value)
{
	enter_();
	push_(db);
	
	db->myBlobCloud->cl_setRecoveryNumber(value);
	
	release_(db);
	exit_();
}

//---------------------------
static const char *get_BackupNo(MSDatabase *db, const char *)
{
	const char *value;
	enter_();
	push_(db);
	
	value = db->myBlobCloud->cl_getRecoveryNumber();
	
	release_(db);
	return_(value);
}

static PBMSVariableRec variables[] = {
	{false, "Storage-Type", MS_REPOSITORY_STORAGE_TYPE, "How the BLOB data is to be stored.", true, get_StorageType, storageTypeCheck, set_StorageType},
	{false, "S3-Cloud-Ref", NULL, "The S3 cloud reference id from the pbms.pbms_cloud table used for new BLOB storage.", true, get_S3CloudRefNo, NULL, set_S3CloudRefNo},
	{false, RESTORE_DUMP_VAR, "FALSE", "Indicate if the database is being restored from a dump file.", false, get_DumpRestore, boolCheck, set_DumpRestore},
	// Hidden variables should be placed at the end.
	{true, BACKUP_NUMBER_VAR, NULL, "The backup number for cloud blob data after a drag and drop restore.", true, get_BackupNo, readOnlyCheck, set_BackupNo}
};

static const uint32_t num_variables = 4;

//---------------------------
//----------------------------
#define PBMS_VARIABLES_FILE	"pbms_variables"
static  CSPath *getSysVarFile(CSString *db_path)
{
	CSPath			*path;

	enter_();
	
	push_(db_path);

	path = CSPath::newPath(RETAIN(db_path), PBMS_VARIABLES_FILE".dat");
	push_(path);
	if (!path->exists()) {
		CSPath *tmp_path;

		tmp_path = CSPath::newPath(RETAIN(db_path), PBMS_VARIABLES_FILE".tmp");
		push_(tmp_path);
		if (tmp_path->exists())
			tmp_path->rename(PBMS_VARIABLES_FILE".dat");
		release_(tmp_path);
	}
	
	
	pop_(path);
	release_(db_path);
	return_(path);
}

class LoadTableCleanUp : public CSRefObject {
	bool do_cleanup;
	CSThread *myself;
	
	uint32_t ref_id;

	public:
	
	LoadTableCleanUp(): CSRefObject(),
		do_cleanup(false), myself(NULL){}
		
	~LoadTableCleanUp() 
	{
		if (do_cleanup) {
			CSL.log(myself, CSLog::Protocol, "\nRestore failed!\n");
			CSL.flush();
			myself->logException();
		}
	}
	
	void setCleanUp(CSThread *self)
	{
		myself = self;
		do_cleanup = true;
	}
	
	void cancelCleanUp()
	{
		do_cleanup = false;
	}
	
};

void MSVariableTable::loadTable(MSDatabase *db)
{
	CSPath	*path;

	enter_();
	
	push_(db);
	path = getSysVarFile(RETAIN(db->myDatabasePath));
	push_(path);

	if (path->exists()) {
		CSFile			*file;
		CSStringBuffer	*string;
		size_t			size = 0, pos =0;
		char			*name, *value;
		
		new_(string, CSStringBuffer(20));
		push_(string);

		file = path->openFile(CSFile::READONLY);
		push_(file);
		size = file->getEOF();
		string->setLength(size);
		file->read(string->getBuffer(0), 0, size, size);
		release_(file);
				
		while (pos < size) {
			name = string->getBuffer(pos);
			pos += strlen(name) +1;
			if (pos >= size)
				break;
				
			value = string->getBuffer(pos);
			pos += strlen(value) +1;
			if (pos > size)
				break;
			
			for (uint32_t i =0; i < num_variables; i++) {
				if (variables[i].save && variables[i].action && !strcmp(name, variables[i].name)) {
					variables[i].action(RETAIN(db), value);
				}
			}
			
		}
		
		release_(string);

	} else { // Set the default values
		for (uint32_t i =0; i < num_variables; i++) {
			if (variables[i].value && variables[i].action) {
				variables[i].action(RETAIN(db), variables[i].value);
			}
		}
	}
	

	release_(path);
	
	// Check to see if there is cloud storage and if the database is not
	// currently recovering, then try to restore the BLOBs.	
	if ((db->myBlobType == MS_CLOUD_STORAGE) && db->myBlobCloud->cl_mustRecoverBlobs() && !db->isRecovering()) {
		CSL.log(self, CSLog::Protocol, "Restoring Cloud BLOBs for database: ");
		CSL.log(self, CSLog::Protocol, db->myDatabaseName->getCString());
		CSL.log(self, CSLog::Protocol, " ...");
		CSL.flush();
		LoadTableCleanUp *cleanup;
		
		new_(cleanup, LoadTableCleanUp());
		push_(cleanup);
		cleanup->setCleanUp(self);
		
		db->myBlobCloud->cl_restoreDB();
		
		cleanup->cancelCleanUp();
		release_(cleanup);

		CSL.log(self, CSLog::Protocol, "\nRestore done.\n");
		CSL.flush();
		set_BackupNo(RETAIN(db), "0");
		saveTable(RETAIN(db));
	}
	
	release_(db);

	exit_();
}

void MSVariableTable::saveTable(MSDatabase *db)
{
	CSPath			*path;
	CSPath			*old_path;
	CSFile			*file;
	const char		*value;
	size_t			offset = 0, len;
	char			null_char = 0;
	enter_();
	
	push_(db);
	path = CSPath::newPath(RETAIN(db->myDatabasePath), PBMS_VARIABLES_FILE".tmp");
	push_(path);
	file = path->openFile(CSFile::CREATE | CSFile::TRUNCATE);
	push_(file);
	
	for (uint32_t i = 0; i < num_variables; i++) {
		if (! variables[i].save) continue;
		
		len = strlen(variables[i].name)+1;
		file->write(variables[i].name, offset, len);
		offset += len;

		value = variables[i].get(RETAIN(db), variables[i].value);
		if (value) {
			len = strlen(value)+1;
			file->write(value, offset, len);
			offset += len;
		} else {
			file->write(&null_char, offset, 1);
			offset++;
		}		
	}
	file->close();
	release_(file);

	old_path = CSPath::newPath(RETAIN(db->myDatabasePath), PBMS_VARIABLES_FILE".dat");
	push_(old_path);
	if (old_path->exists())
		old_path->remove();
	path->rename(PBMS_VARIABLES_FILE".dat");
	release_(old_path);

	release_(path);
	release_(db);
	exit_();
}


MSVariableTable::MSVariableTable(MSSystemTableShare *share, TABLE *table):
MSOpenSystemTable(share, table),
iVariableIndex(0)
{
}

MSVariableTable::~MSVariableTable()
{
	//unuse();
}

void MSVariableTable::use()
{
	gVarLock.lock();
}

void MSVariableTable::unuse()
{
	gVarLock.unlock();	
}


void MSVariableTable::seqScanInit()
{
	iVariableIndex = 0;
}

bool MSVariableTable::seqScanNext(char *buf)
{
	TABLE		*table = mySQLTable;
	Field		*curr_field;
	byte		*save;
	MY_BITMAP	*save_write_set;
	PBMSVariablePtr var;
	
	enter_();
	
	do {
		if (iVariableIndex >= num_variables)
			return_(false);
		var = &(variables[iVariableIndex++]);
	
	} while (var->hidden); 
	
	save_write_set = table->write_set;
	table->write_set = NULL;

#ifdef DRIZZLED
	memset(buf, 0xFF, table->getNullBytes());
#else
	memset(buf, 0xFF, table->s->null_bytes);
#endif
 	for (Field **field=GET_TABLE_FIELDS(table) ; *field ; field++) {
 		curr_field = *field;
		save = curr_field->ptr;
#if MYSQL_VERSION_ID < 50114
		curr_field->ptr = (byte *) buf + curr_field->offset();
#else
#ifdef DRIZZLED
		curr_field->ptr = (byte *) buf + curr_field->offset(curr_field->getTable()->getInsertRecord());
#else
		curr_field->ptr = (byte *) buf + curr_field->offset(curr_field->table->record[0]);
#endif
#endif
		switch (curr_field->field_name[0]) {
			case 'I':
				ASSERT(strcmp(curr_field->field_name, "Id") == 0);
				curr_field->store(iVariableIndex, true);
				setNotNullInRecord(curr_field, buf);
				break;

			case 'N':
				ASSERT(strcmp(curr_field->field_name, "Name") == 0);
					curr_field->store(var->name, strlen(var->name), &UTF8_CHARSET);
					setNotNullInRecord(curr_field, buf);
				break;

			case 'V': {
				ASSERT(strcmp(curr_field->field_name, "Value") == 0);
					const char *value;
					value = var->get(RETAIN(myShare->mySysDatabase), var->value);
					if (value) {
						curr_field->store(value, strlen(value), &UTF8_CHARSET);
						setNotNullInRecord(curr_field, buf);
					}
				}
				break;

			case 'D':
				ASSERT(strcmp(curr_field->field_name, "Description") == 0);
					curr_field->store(var->info, strlen(var->info), &UTF8_CHARSET);
					setNotNullInRecord(curr_field, buf);
				break;

		}
		curr_field->ptr = save;
	}

	table->write_set = save_write_set;
	return_(true);
}

void MSVariableTable::seqScanPos(uint8_t *pos)
{
	int32_t index = iVariableIndex -1;
	if (index < 0)
		index = 0; // This is probably an error condition.
		
	mi_int4store(pos, index);
}

void MSVariableTable::seqScanRead(uint8_t *pos, char *buf)
{
	iVariableIndex = mi_uint4korr(pos);
	seqScanNext(buf);
}

void MSVariableTable::updateRow(char *old_data, char *new_data) 
{
	uint32_t n_id, o_id;
	String n_var_name, n_var_value;	
	String o_var_name;	
	const char *clean_value;

	enter_();
	
	getFieldValue(old_data, 0, &o_id);
	getFieldValue(old_data, 1, &o_var_name);
	
	getFieldValue(new_data, 0, &n_id);
	getFieldValue(new_data, 1, &n_var_name);
	getFieldValue(new_data, 2, &n_var_value);
	
	// The command names must match.
	if ((n_id != o_id) || my_strcasecmp(&UTF8_CHARSET, o_var_name.c_ptr_safe(), n_var_name.c_ptr_safe()))
		CSException::throwException(CS_CONTEXT, HA_ERR_TABLE_READONLY, "Attempt to update read only fields in the "VARIABLES_TABLE_NAME" table.");
		
	n_id--;
	if (n_id >  num_variables) // Should never happen
		CSException::throwException(CS_CONTEXT, HA_ERR_KEY_NOT_FOUND, "Invalid id");
	
	CSStringBuffer *value;	
	new_(value, CSStringBuffer(0));
	push_(value);
	value->append(n_var_value.c_ptr(), n_var_value.length());
	
	// check the input value converting it to a standard format where aplicable:
	if (variables[n_id].check) {
		bool ok = false;
		clean_value = variables[n_id].check(value->getCString(), &ok);
		if (!ok)
			CSException::throwException(CS_CONTEXT, HA_ERR_GENERIC, clean_value);
	} else
		clean_value = value->getCString();
		
	// Execute the action associated with the variable.
	if (variables[n_id].action) {
		variables[n_id].action(RETAIN(myShare->mySysDatabase), clean_value);
	}
	
	release_(value);
	
	if (variables[n_id].save) {
		saveTable(RETAIN(myShare->mySysDatabase));
	}
	
	exit_();
}

void MSVariableTable::transferTable(MSDatabase *to_db, MSDatabase *from_db)
{
	CSPath	*path;
	enter_();
	
	push_(from_db);
	push_(to_db);
	
	path = CSPath::newPath(RETAIN(from_db->myDatabasePath), PBMS_VARIABLES_FILE".dat");
	push_(path);
	if (path->exists()) {
		CSPath	*bu_path;
		bu_path = CSPath::newPath(RETAIN(to_db->myDatabasePath), PBMS_VARIABLES_FILE".dat");
		path->copyTo(bu_path, true);
	}
	
	release_(path);
	release_(to_db);
	release_(from_db);
	
	exit_();
}

void MSVariableTable::setVariable(MSDatabase *db, const char *name, const char *value)
{
	enter_();
	
	push_(db);
	
	for (uint32_t i =0; db && i < num_variables; i++) {
		if (variables[i].action && !strcmp(name, variables[i].name)) {
			variables[i].action(RETAIN(db), value);
			if (variables[i].save) {
				pop_(db);
				saveTable(db);
			} else
				release_(db);
			db = NULL;
		}
	}

	if (db) {
		release_(db);
		CSException::throwException(CS_CONTEXT, HA_ERR_KEY_NOT_FOUND, name);
	}
	exit_();
}

CSStringBuffer *MSVariableTable::dumpTable(MSDatabase *db)
{

	CSPath			*path;
	CSStringBuffer	*dump;

	enter_();
	
	push_(db);
	path = getSysVarFile(RETAIN(db->myDatabasePath));
	release_(db);
	
	push_(path);
	new_(dump, CSStringBuffer(20));
	push_(dump);

	if (path->exists()) {
		CSFile	*file;
		size_t	size;
		
		file = path->openFile(CSFile::READONLY);
		push_(file);
		
		size = file->getEOF();
		dump->setLength(size);
		file->read(dump->getBuffer(0), 0, size, size);
		release_(file);
	}
	
	pop_(dump);
	release_(path);
	return_(dump);
}

void MSVariableTable::restoreTable(MSDatabase *db, const char *data, size_t size, bool reload)
{
	CSPath	*path;
	CSFile	*file;

	enter_();
	
	push_(db);
	path = getSysVarFile(RETAIN(db->myDatabasePath));
	push_(path);
	
	file = path->openFile(CSFile::CREATE | CSFile::TRUNCATE);
	push_(file);
	
	file->write(data, 0, size);
	file->close();
	release_(file);
	
	release_(path);
	
	pop_(db);
	if (reload)
		loadTable(db);
	else
		db->release();
	exit_();
}

void MSVariableTable::removeTable(CSString *db_path)
{
	CSPath	*path;
	enter_();
	
	path = getSysVarFile(db_path);
	push_(path);
	
	path->removeFile();
	release_(path);
	exit_();
}