1
/* -*- mode: c++; c-basic-offset: 2; i/dent-tabs-mode: nil; -*-
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
* Copyright (C) 2010 Brian Aker
44
44
#include "drizzled/internal/my_pthread.h"
45
45
#include "drizzled/plugin/event_observer.h"
47
#include "drizzled/table.h"
48
#include "drizzled/table/shell.h"
50
47
#include "drizzled/session.h"
52
49
#include "drizzled/charset.h"
70
67
#include "drizzled/field/decimal.h"
71
68
#include "drizzled/field/real.h"
72
69
#include "drizzled/field/double.h"
73
#include "drizzled/field/int32.h"
74
#include "drizzled/field/int64.h"
70
#include "drizzled/field/long.h"
71
#include "drizzled/field/int64_t.h"
75
72
#include "drizzled/field/num.h"
76
73
#include "drizzled/field/timestamp.h"
77
74
#include "drizzled/field/datetime.h"
78
75
#include "drizzled/field/varstring.h"
79
#include "drizzled/field/uuid.h"
81
#include "drizzled/definition/cache.h"
83
77
using namespace std;
88
82
extern size_t table_def_size;
83
static TableDefinitionCache table_def_cache;
84
static pthread_mutex_t LOCK_table_share;
85
bool table_def_inited= false;
90
87
/*****************************************************************************
91
88
Functions to handle table definition cach (TableShare)
92
89
*****************************************************************************/
92
void TableShare::cacheStart(void)
94
pthread_mutex_init(&LOCK_table_share, MY_MUTEX_INIT_FAST);
95
table_def_inited= true;
97
* This is going to overalloc a bit - as rehash sets the number of
98
* buckets, not the number of elements. BUT, it'll allow us to not need
99
* to rehash later on as the unordered_map grows.
101
table_def_cache.rehash(table_def_size);
105
void TableShare::cacheStop(void)
107
if (table_def_inited)
109
table_def_inited= false;
110
pthread_mutex_destroy(&LOCK_table_share);
116
* @TODO: This should return size_t
118
uint32_t cached_table_definitions(void)
120
return static_cast<uint32_t>(table_def_cache.size());
95
125
Mark that we are not using table share anymore.
106
136
void TableShare::release(TableShare *share)
108
138
bool to_be_deleted= false;
109
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
112
if (!--share->ref_count)
120
definition::Cache::singleton().erase(share->getCacheKey());
124
void TableShare::release(TableShare::shared_ptr &share)
126
bool to_be_deleted= false;
127
safe_mutex_assert_owner(table::Cache::singleton().mutex().native_handle);
130
if (!--share->ref_count)
138
definition::Cache::singleton().erase(share->getCacheKey());
142
void TableShare::release(const TableIdentifier &identifier)
144
TableShare::shared_ptr share= definition::Cache::singleton().find(identifier.getKey());
139
safe_mutex_assert_owner(&LOCK_open);
141
pthread_mutex_lock(&share->mutex);
142
if (!--share->ref_count)
149
TableIdentifier identifier(share->getSchemaName(), share->getTableName());
150
plugin::EventObserver::deregisterTableEvents(*share);
152
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
153
if (iter != table_def_cache.end())
155
table_def_cache.erase(iter);
160
pthread_mutex_unlock(&share->mutex);
163
void TableShare::release(TableIdentifier &identifier)
165
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
166
if (iter != table_def_cache.end())
168
TableShare *share= (*iter).second;
147
169
share->version= 0; // Mark for delete
148
170
if (share->ref_count == 0)
150
definition::Cache::singleton().erase(identifier.getKey());
172
pthread_mutex_lock(&share->mutex);
173
plugin::EventObserver::deregisterTableEvents(*share);
174
table_def_cache.erase(identifier.getKey());
156
static TableShare::shared_ptr foundTableShare(TableShare::shared_ptr share)
181
static TableShare *foundTableShare(TableShare *share)
159
184
We found an existing table definition. Return it if we didn't get
163
188
/* We must do a lock to ensure that the structure is initialized */
189
(void) pthread_mutex_lock(&share->mutex);
164
190
if (share->error)
166
192
/* Table definition contained an error */
167
193
share->open_table_error(share->error, share->open_errno, share->errarg);
194
(void) pthread_mutex_unlock(&share->mutex);
169
return TableShare::shared_ptr();
172
199
share->incrementTableCount();
200
(void) pthread_mutex_unlock(&share->mutex);
197
225
# Share for table
200
TableShare::shared_ptr TableShare::getShareCreate(Session *session,
201
const TableIdentifier &identifier,
228
TableShare *TableShare::getShareCreate(Session *session,
229
TableIdentifier &identifier,
204
TableShare::shared_ptr share;
232
TableShare *share= NULL;
208
236
/* Read table definition from cache */
209
if ((share= definition::Cache::singleton().find(identifier.getKey())))
237
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
238
if (iter != table_def_cache.end())
240
share= (*iter).second;
210
241
return foundTableShare(share);
212
share.reset(new TableShare(message::Table::STANDARD, identifier));
244
if (not (share= new TableShare(message::Table::STANDARD, identifier)))
250
Lock mutex to be able to read table definition from file without
253
(void) pthread_mutex_lock(&share->mutex);
256
* @TODO: we need to eject something if we exceed table_def_size
258
pair<TableDefinitionCache::iterator, bool> ret=
259
table_def_cache.insert(make_pair(identifier.getKey(), share));
260
if (ret.second == false)
214
267
if (share->open_table_def(*session, identifier))
216
in_error= share->error;
269
*error= share->error;
270
table_def_cache.erase(identifier.getKey());
218
return TableShare::shared_ptr();
220
275
share->ref_count++; // Mark in use
222
277
plugin::EventObserver::registerTableEvents(*share);
224
bool ret= definition::Cache::singleton().insert(identifier.getKey(), share);
227
return TableShare::shared_ptr();
279
(void) pthread_mutex_unlock(&share->mutex);
286
Check if table definition exits in cache
289
get_cached_table_share()
291
table_name Table name
295
# TableShare for table
297
TableShare *TableShare::getShare(TableIdentifier &identifier)
299
safe_mutex_assert_owner(&LOCK_open);
301
TableDefinitionCache::iterator iter= table_def_cache.find(identifier.getKey());
302
if (iter != table_def_cache.end())
304
return (*iter).second;
232
312
static enum_field_types proto_field_type_to_drizzle_type(uint32_t proto_field_type)
234
314
enum_field_types field_type;
265
345
case message::Table::Field::BLOB:
266
346
field_type= DRIZZLE_TYPE_BLOB;
268
case message::Table::Field::UUID:
269
field_type= DRIZZLE_TYPE_UUID;
273
abort(); // Programming error
349
field_type= DRIZZLE_TYPE_LONG; /* Set value to kill GCC warning */
276
353
return field_type;
304
381
default_value->length());
306
383
case DRIZZLE_TYPE_NULL:
309
385
case DRIZZLE_TYPE_TIMESTAMP:
310
386
case DRIZZLE_TYPE_DATETIME:
311
387
case DRIZZLE_TYPE_DATE:
312
388
case DRIZZLE_TYPE_ENUM:
313
case DRIZZLE_TYPE_UUID:
314
389
default_item= new Item_string(default_value->c_str(),
315
390
default_value->length(),
316
391
system_charset_info);
372
TableShare::TableShare(const TableIdentifier::Type type_arg) :
447
const TableDefinitionCache &TableShare::getCache()
449
return table_def_cache;
452
TableShare::TableShare(TableIdentifier::Type type_arg) :
373
453
table_category(TABLE_UNKNOWN_CATEGORY),
374
455
found_next_number_field(NULL),
375
456
timestamp_field(NULL),
377
mem_root(TABLE_ALLOC_BLOCK_SIZE),
381
461
timestamp_offset(0),
426
511
if (type_arg == message::Table::INTERNAL)
428
TableIdentifier::build_tmptable_filename(private_key_for_cache.vectorPtr());
429
init(private_key_for_cache.vector(), private_key_for_cache.vector());
513
TableIdentifier::build_tmptable_filename(private_key_for_cache);
514
init(&private_key_for_cache[0], &private_key_for_cache[0]);
437
TableShare::TableShare(const TableIdentifier &identifier, const TableIdentifier::Key &key) :// Used by placeholder
522
TableShare::TableShare(TableIdentifier &identifier, const TableIdentifier::Key &key) :// Used by placeholder
438
523
table_category(TABLE_UNKNOWN_CATEGORY),
439
525
found_next_number_field(NULL),
440
526
timestamp_field(NULL),
442
mem_root(TABLE_ALLOC_BLOCK_SIZE),
446
531
timestamp_offset(0),
490
580
private_key_for_cache= key;
582
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
492
583
table_category= TABLE_CATEGORY_TEMPORARY;
493
584
tmp_table= message::Table::INTERNAL;
495
db.str= const_cast<char *>(private_key_for_cache.vector());
496
db.length= strlen(private_key_for_cache.vector());
586
db.str= &private_key_for_cache[0];
587
db.length= strlen(&private_key_for_cache[0]);
498
table_name.str= const_cast<char *>(private_key_for_cache.vector()) + strlen(private_key_for_cache.vector()) + 1;
589
table_name.str= &private_key_for_cache[0] + strlen(&private_key_for_cache[0]) + 1;
499
590
table_name.length= strlen(table_name.str);
500
591
path.str= (char *)"";
501
592
normalized_path.str= path.str;
502
593
path.length= normalized_path.length= 0;
504
std::string tb_name(identifier.getTableName());
505
std::transform(tb_name.begin(), tb_name.end(), tb_name.begin(), ::tolower);
506
assert(strcmp(tb_name.c_str(), table_name.str) == 0);
594
assert(strcmp(identifier.getTableName().c_str(), table_name.str) == 0);
508
595
assert(strcmp(identifier.getSchemaName().c_str(), db.str) == 0);
512
599
TableShare::TableShare(const TableIdentifier &identifier) : // Just used during createTable()
513
600
table_category(TABLE_UNKNOWN_CATEGORY),
514
602
found_next_number_field(NULL),
515
603
timestamp_field(NULL),
517
mem_root(TABLE_ALLOC_BLOCK_SIZE),
521
608
timestamp_offset(0),
568
660
memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
663
memory::init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
571
664
table_category= TABLE_CATEGORY_TEMPORARY;
572
665
tmp_table= message::Table::INTERNAL;
573
db.str= const_cast<char *>(private_key_for_cache.vector());
574
db.length= strlen(private_key_for_cache.vector());
666
db.str= &private_key_for_cache[0];
667
db.length= strlen(&private_key_for_cache[0]);
575
668
table_name.str= db.str + 1;
576
669
table_name.length= strlen(table_name.str);
577
670
path.str= &private_normalized_path[0];
585
678
Used for shares that will go into the cache.
587
TableShare::TableShare(const TableIdentifier::Type type_arg,
588
const TableIdentifier &identifier,
680
TableShare::TableShare(TableIdentifier::Type type_arg,
681
TableIdentifier &identifier,
590
683
uint32_t path_length_arg) :
591
684
table_category(TABLE_UNKNOWN_CATEGORY),
592
686
found_next_number_field(NULL),
593
687
timestamp_field(NULL),
595
mem_root(TABLE_ALLOC_BLOCK_SIZE),
599
692
timestamp_offset(0),
640
738
memset(&path, 0, sizeof(LEX_STRING));
641
739
memset(&normalized_path, 0, sizeof(LEX_STRING));
741
mem_root.init_alloc_root(TABLE_ALLOC_BLOCK_SIZE);
644
743
std::string _path;
648
747
Let us use the fact that the key is "db/0/table_name/0" + optional
649
748
part for temporary tables.
651
db.str= const_cast<char *>(private_key_for_cache.vector());
750
db.str= &private_key_for_cache[0];
652
751
db.length= strlen(db.str);
653
752
table_name.str= db.str + db.length + 1;
654
753
table_name.length= strlen(table_name.str);
662
761
TableIdentifier::build_table_filename(_path, db.str, table_name.str, false);
665
if ((path_buff= (char *)mem_root.alloc_root(_path.length() + 1)))
764
if (mem_root.multi_alloc_root(0,
765
&path_buff, _path.length() + 1,
667
768
setPath(path_buff, _path.length());
668
769
strcpy(path_buff, _path.c_str());
669
770
setNormalizedPath(path_buff, _path.length());
671
772
version= refresh_version;
774
pthread_mutex_init(&mutex, MY_MUTEX_INIT_FAST);
775
pthread_cond_init(&cond, NULL);
675
779
assert(0); // We should throw here.
697
801
assert(ref_count == 0);
804
If someone is waiting for this to be deleted, inform it about this.
805
Don't do a delete until we know that no one is refering to this anymore.
807
if (tmp_table == message::Table::STANDARD)
809
/* share->mutex is locked in release_table_share() */
810
while (waiting_on_cond)
812
pthread_cond_broadcast(&cond);
813
pthread_cond_wait(&cond, &mutex);
815
/* No thread refers to this anymore */
816
pthread_mutex_unlock(&mutex);
817
pthread_mutex_destroy(&mutex);
818
pthread_cond_destroy(&cond);
699
821
storage_engine= NULL;
701
823
delete table_proto;
702
824
table_proto= NULL;
704
plugin::EventObserver::deregisterTableEvents(*this);
706
826
mem_root.free_root(MYF(0)); // Free's share
709
void TableShare::setIdentifier(const TableIdentifier &identifier_arg)
829
void TableShare::setIdentifier(TableIdentifier &identifier_arg)
831
private_key_for_cache.clear();
711
832
private_key_for_cache= identifier_arg.getKey();
714
835
Let us use the fact that the key is "db/0/table_name/0" + optional
715
836
part for temporary tables.
717
db.str= const_cast<char *>(private_key_for_cache.vector());
838
db.str= &private_key_for_cache[0];
718
839
db.length= strlen(db.str);
719
840
table_name.str= db.str + db.length + 1;
720
841
table_name.length= strlen(table_name.str);
883
1004
key_part->length= part.compare_length();
887
if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
888
|| table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
890
uint32_t collation_id;
892
if (table.field(part.fieldnr()).string_options().has_collation_id())
893
collation_id= table.field(part.fieldnr()).string_options().collation_id();
895
collation_id= table.options().collation_id();
897
const CHARSET_INFO *cs= get_charset(collation_id);
899
mbmaxlen= cs->mbmaxlen;
901
key_part->length*= mbmaxlen;
903
1006
key_part->store_length= key_part->length;
905
1008
/* key_part->offset is set later */
934
1037
uint32_t local_null_fields= 0;
937
std::vector<uint32_t> field_offsets;
938
std::vector<uint32_t> field_pack_length;
1040
vector<uint32_t> field_offsets;
1041
vector<uint32_t> field_pack_length;
940
1043
field_offsets.resize(fields);
941
1044
field_pack_length.resize(fields);
982
1085
message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
984
field_pack_length[fieldnr]= 4;
1087
field_pack_length[fieldnr]=
1088
get_enum_pack_length(field_options.field_value_size());
986
1090
interval_count++;
987
1091
interval_parts+= field_options.field_value_size();
1124
1228
if (pfield.has_options() &&
1125
1229
pfield.options().has_default_expression() &&
1126
pfield.options().default_expression().compare("CURRENT_TIMESTAMP") == 0)
1230
pfield.options().default_expression().compare("NOW()") == 0)
1128
1232
if (pfield.options().has_update_expression() &&
1129
pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
1233
pfield.options().update_expression().compare("NOW()") == 0)
1131
1235
unireg_type= Field::TIMESTAMP_DNUN_FIELD;
1135
1239
unireg_type= Field::TIMESTAMP_DN_FIELD;
1139
assert(0); // Invalid update value.
1242
assert(1); // Invalid update value.
1143
1244
else if (pfield.has_options() &&
1144
1245
pfield.options().has_update_expression() &&
1145
pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
1246
pfield.options().update_expression().compare("NOW()") == 0)
1147
1248
unireg_type= Field::TIMESTAMP_UN_FIELD;
1220
1321
Item *default_value= NULL;
1222
1323
if (pfield.options().has_default_value() ||
1223
pfield.options().default_null() ||
1324
pfield.options().has_default_null() ||
1224
1325
pfield.options().has_default_bin_value())
1226
1327
default_value= default_value_item(field_type,
1234
blob_ptr_size= portable_sizeof_char_ptr;
1335
Table temp_table; /* Use this so that BLOB DEFAULT '' works */
1336
memset(&temp_table, 0, sizeof(temp_table));
1337
temp_table.setShare(this);
1338
temp_table.in_use= &session;
1339
temp_table.getMutableShare()->db_low_byte_first= true; //Cursor->low_byte_first();
1340
temp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1236
1342
uint32_t field_length= 0; //Assignment is for compiler complaint.
1315
1421
case DRIZZLE_TYPE_LONGLONG:
1316
1422
field_length= MAX_BIGINT_WIDTH;
1318
case DRIZZLE_TYPE_UUID:
1319
field_length= field::Uuid::max_string_length();
1321
1424
case DRIZZLE_TYPE_NULL:
1322
1425
abort(); // Programming error
1325
assert(enum_field_types_size == 12);
1327
1428
Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1329
pfield.constraints().is_nullable(),
1335
MTYP_TYPENR(unireg_type),
1336
((field_type == DRIZZLE_TYPE_ENUM) ? &intervals[interval_nr++] : (TYPELIB*) 0),
1337
getTableProto()->field(fieldnr).name().c_str());
1430
pfield.constraints().is_nullable(),
1436
(Field::utype) MTYP_TYPENR(unireg_type),
1437
((field_type == DRIZZLE_TYPE_ENUM) ?
1438
&intervals[interval_nr++]
1440
getTableProto()->field(fieldnr).name().c_str());
1339
1442
field[fieldnr]= f;
1341
// Insert post make_field code here.
1344
case DRIZZLE_TYPE_BLOB:
1345
case DRIZZLE_TYPE_VARCHAR:
1346
case DRIZZLE_TYPE_DOUBLE:
1347
case DRIZZLE_TYPE_DECIMAL:
1348
case DRIZZLE_TYPE_TIMESTAMP:
1349
case DRIZZLE_TYPE_DATETIME:
1350
case DRIZZLE_TYPE_DATE:
1351
case DRIZZLE_TYPE_ENUM:
1352
case DRIZZLE_TYPE_LONG:
1353
case DRIZZLE_TYPE_LONGLONG:
1354
case DRIZZLE_TYPE_NULL:
1355
case DRIZZLE_TYPE_UUID:
1359
// This needs to go, we should be setting the "use" on the field so that
1360
// it does not reference the share/table.
1361
table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1362
temp_table.in_use= &session;
1364
1444
f->init(&temp_table); /* blob default values need table obj */
1366
1446
if (! (f->flags & NOT_NULL_FLAG))
1385
1465
return local_error;
1388
else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1468
else if (f->real_type() == DRIZZLE_TYPE_ENUM &&
1469
(f->flags & NOT_NULL_FLAG))
1390
1471
f->set_notnull();
1391
1472
f->store((int64_t) 1, true);
1412
1493
if (f->unireg_check == Field::NEXT_NUMBER)
1413
1494
found_next_number_field= &(field[fieldnr]);
1496
if (timestamp_field == f)
1497
timestamp_field_offset= fieldnr;
1415
1499
if (use_hash) /* supposedly this never fails... but comments lie */
1417
1501
const char *local_field_name= field[fieldnr]->field_name;
1418
1502
name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1422
1507
keyinfo= key_info;
1607
1693
if (blob_fields)
1609
1697
/* Store offsets to blob fields to find them fast */
1610
1698
blob_field.resize(blob_fields);
1611
uint32_t *save= &blob_field[0];
1699
save= &blob_field[0];
1613
1701
for (Fields::iterator iter= field.begin(); iter != field.end()-1; iter++, k++)
1615
1703
if ((*iter)->flags & BLOB_FLAG)
1621
all_set.resize(fields);
1708
db_low_byte_first= true; // @todo Question this.
1709
column_bitmap_size= bitmap_buffer_size(fields);
1711
all_bitmap.resize(column_bitmap_size);
1712
all_set.init(&all_bitmap[0], fields);
1624
1715
return local_error;
1652
1743
This function is called when the table definition is not cached in
1653
definition::Cache::singleton().getCache()
1654
1745
The data is returned in 'share', which is alloced by
1655
1746
alloc_table_share().. The code assumes that share is initialized.
1731
1822
5 Error (see open_table_error: charset unavailable)
1732
1823
7 Table definition has changed in engine
1734
1826
int TableShare::open_table_from_share(Session *session,
1735
1827
const TableIdentifier &identifier,
1736
1828
const char *alias,
1737
1829
uint32_t db_stat, uint32_t ha_open_flags,
1738
1830
Table &outparam)
1833
uint32_t records, bitmap_size;
1740
1834
bool error_reported= false;
1741
int ret= open_table_from_share_inner(session, alias, db_stat, outparam);
1744
ret= open_table_cursor_inner(identifier, db_stat, ha_open_flags, outparam, error_reported);
1749
if (not error_reported)
1750
open_table_error(ret, errno, 0);
1752
delete outparam.cursor;
1753
outparam.cursor= 0; // For easier error checking
1754
outparam.db_stat= 0;
1755
outparam.getMemRoot()->free_root(MYF(0)); // Safe to call on zeroed root
1756
outparam.clearAlias();
1761
int TableShare::open_table_from_share_inner(Session *session,
1768
unsigned char *record= NULL;
1835
unsigned char *record, *bitmaps;
1769
1836
Field **field_ptr;
1771
1838
/* Parsing of partitioning information from .frm needs session->lex set up. */
1774
1841
local_error= 1;
1775
1842
outparam.resetTable(session, this, db_stat);
1777
outparam.setAlias(alias);
1844
if (not (outparam.alias= strdup(alias)))
1779
1847
/* Allocate Cursor */
1780
if (not (outparam.cursor= db_type()->getCursor(outparam)))
1848
if (not (outparam.cursor= db_type()->getCursor(*this, outparam.getMemRoot())))
1783
1851
local_error= 4;
1801
1869
if (records > 1)
1802
1870
outparam.record[1]= record+ rec_buff_length;
1804
outparam.record[1]= outparam.getInsertRecord(); // Safety
1872
outparam.record[1]= outparam.record[0]; // Safety
1807
#ifdef HAVE_VALGRIND
1809
1877
We need this because when we read var-length rows, we are not updating
1810
1878
bytes after end of varchar
1812
1880
if (records > 1)
1814
memcpy(outparam.getInsertRecord(), getDefaultValues(), rec_buff_length);
1815
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1882
memcpy(outparam.record[0], getDefaultValues(), rec_buff_length);
1883
memcpy(outparam.record[1], getDefaultValues(), null_bytes);
1816
1884
if (records > 2)
1817
memcpy(outparam.getUpdateRecord(), getDefaultValues(), rec_buff_length);
1885
memcpy(outparam.record[1], getDefaultValues(), rec_buff_length);
1820
1888
if (records > 1)
1822
memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1890
memcpy(outparam.record[1], getDefaultValues(), null_bytes);
1825
1893
if (!(field_ptr = (Field **) outparam.alloc_root( (uint32_t) ((fields+1)* sizeof(Field*)))))
1830
1898
outparam.setFields(field_ptr);
1832
record= (unsigned char*) outparam.getInsertRecord()-1; /* Fieldstart = 1 */
1900
record= (unsigned char*) outparam.record[0]-1; /* Fieldstart = 1 */
1834
1902
outparam.null_flags= (unsigned char*) record+1;
1845
1913
outparam.found_next_number_field=
1846
1914
outparam.getField(positionFields(found_next_number_field));
1847
1915
if (timestamp_field)
1848
outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field->position());
1916
outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field_offset);
1850
1919
/* Fix key->name and key_part->field */
1855
1924
uint32_t n_length;
1856
1925
n_length= keys*sizeof(KeyInfo) + key_parts*sizeof(KeyPartInfo);
1857
1926
if (!(local_key_info= (KeyInfo*) outparam.alloc_root(n_length)))
1859
1928
outparam.key_info= local_key_info;
1860
1929
key_part= (reinterpret_cast<KeyPartInfo*> (local_key_info+keys));
1895
1964
/* Allocate bitmaps */
1897
outparam.def_read_set.resize(fields);
1898
outparam.def_write_set.resize(fields);
1899
outparam.tmp_set.resize(fields);
1966
bitmap_size= column_bitmap_size;
1967
if (!(bitmaps= (unsigned char*) outparam.alloc_root(bitmap_size*3)))
1971
outparam.def_read_set.init((my_bitmap_map*) bitmaps, fields);
1972
outparam.def_write_set.init((my_bitmap_map*) (bitmaps+bitmap_size), fields);
1973
outparam.tmp_set.init((my_bitmap_map*) (bitmaps+bitmap_size*2), fields);
1900
1974
outparam.default_column_bitmaps();
1905
int TableShare::open_table_cursor_inner(const TableIdentifier &identifier,
1906
uint32_t db_stat, uint32_t ha_open_flags,
1908
bool &error_reported)
1910
1976
/* The table struct is now initialized; Open the table */
1914
1980
assert(!(db_stat & HA_WAIT_IF_LOCKED));
1917
if ((ha_err= (outparam.cursor->ha_open(identifier,
1918
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1919
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1983
if ((ha_err= (outparam.cursor->ha_open(identifier, &outparam, getNormalizedPath(),
1984
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1985
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1921
1987
switch (ha_err)
1943
2009
local_error= 7;
2016
#if defined(HAVE_purify)
2017
memset(bitmaps, 0, bitmap_size*3);
2023
if (!error_reported)
2024
open_table_error(local_error, errno, 0);
2026
delete outparam.cursor;
2027
outparam.cursor= 0; // For easier error checking
2028
outparam.db_stat= 0;
2029
outparam.getMemRoot()->free_root(MYF(0)); // Safe to call on zeroed root
2030
free((char*) outparam.alias);
2032
return (local_error);
1953
2035
/* error message when opening a form cursor */
2134
get_enum_pack_length(interval->count),
2054
2136
field_charset);
2055
2137
case DRIZZLE_TYPE_VARCHAR:
2057
2138
return new (&mem_root) Field_varstring(ptr,field_length,
2058
ha_varchar_packlength(field_length),
2139
HA_VARCHAR_PACKLENGTH(field_length),
2059
2140
null_pos,null_bit,
2061
2143
field_charset);
2062
2144
case DRIZZLE_TYPE_BLOB:
2063
2145
return new (&mem_root) Field_blob(ptr,
2150
calc_pack_length(DRIZZLE_TYPE_LONG, 0),
2068
2151
field_charset);
2069
2152
case DRIZZLE_TYPE_DECIMAL:
2070
2153
return new (&mem_root) Field_decimal(ptr,
2088
2171
false /* is_unsigned */);
2089
case DRIZZLE_TYPE_UUID:
2090
return new (&mem_root) field::Uuid(ptr,
2095
2172
case DRIZZLE_TYPE_LONG:
2096
return new (&mem_root) field::Int32(ptr,
2173
return new (&mem_root) Field_long(ptr,
2180
false /* is_unsigned */);
2102
2181
case DRIZZLE_TYPE_LONGLONG:
2103
return new (&mem_root) field::Int64(ptr,
2182
return new (&mem_root) Field_int64_t(ptr,
2189
false /* is_unsigned */);
2109
2190
case DRIZZLE_TYPE_TIMESTAMP:
2110
2191
return new (&mem_root) Field_timestamp(ptr,