~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_engine.cc

  • Committer: Brian Aker
  • Date: 2010-12-08 18:53:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1983.
  • Revision ID: brian@tangent.org-20101208185346-89uak2ofyivk1yss
Update schema, make sure that it always ruturns a valid string (it just
makes the entire interface simpler to use).

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
/*****************************************************************************
23
23
 
24
 
Copyright (C) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
25
 
Copyright (C) 2008, 2009 Google Inc.
 
24
Copyright (c) 2000, 2009, MySQL AB & Innobase Oy. All Rights Reserved.
 
25
Copyright (c) 2008, 2009 Google Inc.
26
26
 
27
27
Portions of this file contain modifications contributed and copyrighted by
28
28
Google, Inc. Those modifications are gratefully acknowledged and are described
45
45
*****************************************************************************/
46
46
/***********************************************************************
47
47
 
48
 
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
49
 
Copyright (C) 2009, Percona Inc.
 
48
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
 
49
Copyright (c) 2009, Percona Inc.
50
50
 
51
51
Portions of this file contain modifications contributed and copyrighted
52
52
by Percona Inc.. Those modifications are
71
71
***********************************************************************/
72
72
 
73
73
 
74
 
#include <config.h>
 
74
#include "config.h"
75
75
#include <drizzled/table.h>
76
76
#include <drizzled/error.h>
77
 
#include <drizzled/internal/my_pthread.h>
 
77
#include "drizzled/internal/my_pthread.h"
78
78
#include <drizzled/plugin/transactional_storage_engine.h>
79
 
#include <drizzled/plugin/error_message.h>
80
79
 
81
80
#include <fcntl.h>
82
 
#include <stdarg.h>
83
81
 
84
82
#include <string>
85
83
#include <boost/algorithm/string.hpp>
88
86
#include <map>
89
87
#include <fstream>
90
88
#include <drizzled/message/table.pb.h>
91
 
#include <drizzled/internal/m_string.h>
 
89
#include "drizzled/internal/m_string.h"
92
90
 
93
 
#include <drizzled/global_charset_info.h>
 
91
#include "drizzled/global_charset_info.h"
94
92
 
95
93
#include "haildb_datadict_dump_func.h"
96
94
#include "config_table_function.h"
101
99
#include "haildb_engine.h"
102
100
 
103
101
#include <drizzled/field.h>
104
 
#include <drizzled/field/blob.h>
105
 
#include <drizzled/field/enum.h>
 
102
#include "drizzled/field/timestamp.h" // needed for UPDATE NOW()
 
103
#include "drizzled/field/blob.h"
 
104
#include "drizzled/field/enum.h"
106
105
#include <drizzled/session.h>
 
106
#include <boost/program_options.hpp>
107
107
#include <drizzled/module/option_map.h>
 
108
#include <iostream>
108
109
#include <drizzled/charset.h>
109
 
#include <drizzled/current_session.h>
110
 
 
111
 
#include <iostream>
112
110
 
113
111
namespace po= boost::program_options;
114
 
#include <boost/program_options.hpp>
115
112
#include <boost/algorithm/string.hpp>
116
113
 
117
114
using namespace std;
118
115
using namespace google;
119
116
using namespace drizzled;
120
117
 
121
 
int read_row_from_haildb(Session *session, unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot= NULL);
 
118
int read_row_from_haildb(unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot= NULL);
122
119
static void fill_ib_search_tpl_from_drizzle_key(ib_tpl_t search_tuple,
123
120
                                                const drizzled::KeyInfo *key_info,
124
121
                                                const unsigned char *key_ptr,
167
164
 
168
165
  int doCreateTable(Session&,
169
166
                    Table& table_arg,
170
 
                    const drizzled::identifier::Table &identifier,
 
167
                    const drizzled::TableIdentifier &identifier,
171
168
                    drizzled::message::Table& proto);
172
169
 
173
 
  int doDropTable(Session&, const identifier::Table &identifier);
 
170
  int doDropTable(Session&, const TableIdentifier &identifier);
174
171
 
175
172
  int doRenameTable(drizzled::Session&,
176
 
                    const drizzled::identifier::Table&,
177
 
                    const drizzled::identifier::Table&);
 
173
                    const drizzled::TableIdentifier&,
 
174
                    const drizzled::TableIdentifier&);
178
175
 
179
176
  int doGetTableDefinition(Session& session,
180
 
                           const identifier::Table &identifier,
 
177
                           const TableIdentifier &identifier,
181
178
                           drizzled::message::Table &table_proto);
182
179
 
183
 
  bool doDoesTableExist(Session&, const identifier::Table &identifier);
 
180
  bool doDoesTableExist(Session&, const TableIdentifier &identifier);
184
181
 
185
182
private:
186
 
  void getTableNamesInSchemaFromHailDB(const drizzled::identifier::Schema &schema,
 
183
  void getTableNamesInSchemaFromHailDB(const drizzled::SchemaIdentifier &schema,
187
184
                                       drizzled::plugin::TableNameList *set_of_names,
188
 
                                       drizzled::identifier::Table::vector *identifiers);
 
185
                                       drizzled::TableIdentifier::vector *identifiers);
189
186
 
190
187
public:
191
188
  void doGetTableIdentifiers(drizzled::CachedDirectory &,
192
 
                             const drizzled::identifier::Schema &schema,
193
 
                             drizzled::identifier::Table::vector &identifiers);
 
189
                             const drizzled::SchemaIdentifier &schema,
 
190
                             drizzled::TableIdentifier::vector &identifiers);
194
191
 
195
192
  /* The following defines can be increased if necessary */
196
193
  uint32_t max_supported_keys()          const { return 1000; }
241
238
/* This is a superset of the map from innobase plugin.
242
239
   Unlike innobase plugin we don't act on errors here, we just
243
240
   map error codes. */
244
 
static int ib_err_t_to_drizzle_error(Session* session, ib_err_t err)
 
241
static int ib_err_t_to_drizzle_error(ib_err_t err)
245
242
{
246
243
  switch (err)
247
244
  {
271
268
    return HA_ERR_NO_ACTIVE_RECORD;
272
269
 
273
270
  case DB_DEADLOCK:
274
 
    /* HailDB will roll back a transaction itself due to DB_DEADLOCK.
275
 
       This means we have to tell Drizzle about it */
276
 
    session->markTransactionForRollback(true);
277
271
    return HA_ERR_LOCK_DEADLOCK;
278
272
 
279
273
  case DB_LOCK_WAIT_TIMEOUT:
280
 
    session->markTransactionForRollback(false);
281
274
    return HA_ERR_LOCK_WAIT_TIMEOUT;
282
275
 
283
276
  case DB_NO_REFERENCED_ROW:
356
349
  (void)options;
357
350
 
358
351
  transaction= get_trx(session);
359
 
  isolation_level= tx_isolation_to_ib_trx_level(session->getTxIsolation());
 
352
  isolation_level= tx_isolation_to_ib_trx_level((enum_tx_isolation)session_tx_isolation(session));
360
353
  *transaction= ib_trx_begin(isolation_level);
361
354
 
362
 
  return *transaction == NULL;
 
355
  return 0;
363
356
}
364
357
 
365
358
void HailDBEngine::doStartStatement(Session *session)
393
386
  err= ib_savepoint_rollback(*transaction, savepoint.getName().c_str(),
394
387
                             savepoint.getName().length());
395
388
 
396
 
  return ib_err_t_to_drizzle_error(session, err);
 
389
  return ib_err_t_to_drizzle_error(err);
397
390
}
398
391
 
399
392
int HailDBEngine::doReleaseSavepoint(Session* session,
405
398
  err= ib_savepoint_release(*transaction, savepoint.getName().c_str(),
406
399
                            savepoint.getName().length());
407
400
  if (err != DB_SUCCESS)
408
 
    return ib_err_t_to_drizzle_error(session, err);
 
401
    return ib_err_t_to_drizzle_error(err);
409
402
 
410
403
  return 0;
411
404
}
415
408
  ib_err_t err;
416
409
  ib_trx_t *transaction= get_trx(session);
417
410
 
418
 
  if (all)
 
411
  if (all || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
419
412
  {
420
413
    err= ib_trx_commit(*transaction);
421
414
 
422
415
    if (err != DB_SUCCESS)
423
 
      return ib_err_t_to_drizzle_error(session, err);
 
416
      return ib_err_t_to_drizzle_error(err);
424
417
 
425
418
    *transaction= NULL;
426
419
  }
433
426
  ib_err_t err;
434
427
  ib_trx_t *transaction= get_trx(session);
435
428
 
436
 
  if (all)
 
429
  if (all || !session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
437
430
  {
438
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
439
 
      err= ib_trx_release(*transaction);
440
 
    else
441
 
      err= ib_trx_rollback(*transaction);
 
431
    err= ib_trx_rollback(*transaction);
442
432
 
443
433
    if (err != DB_SUCCESS)
444
 
      return ib_err_t_to_drizzle_error(session, err);
 
434
      return ib_err_t_to_drizzle_error(err);
445
435
 
446
436
    *transaction= NULL;
447
437
  }
448
438
  else
449
439
  {
450
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
451
 
      return 0;
452
 
 
453
440
    err= ib_savepoint_rollback(*transaction, statement_savepoint_name.c_str(),
454
441
                               statement_savepoint_name.length());
455
442
    if (err != DB_SUCCESS)
456
 
      return ib_err_t_to_drizzle_error(session, err);
 
443
      return ib_err_t_to_drizzle_error(err);
457
444
  }
458
445
 
459
446
  return 0;
497
484
  else
498
485
  {
499
486
    assert (err == DB_SUCCESS);
500
 
    err= ib_tuple_read_u64(tuple, getTable()->getShare()->sizeFields(), &nr);
 
487
    err= ib_tuple_read_u64(tuple, getTable()->getShare()->fields, &nr);
501
488
    nr++;
502
489
  }
503
490
  ib_tuple_delete(tuple);
504
 
  tuple= NULL;
505
491
  err= ib_cursor_reset(cursor);
506
492
  assert(err == DB_SUCCESS);
507
493
  return nr;
538
524
  doEndIndexScan();
539
525
  (void) extra(HA_EXTRA_NO_KEYREAD);
540
526
 
541
 
  if (getTable()->getShare()->getTableMessage()->options().auto_increment_value() > nr)
542
 
    nr= getTable()->getShare()->getTableMessage()->options().auto_increment_value();
 
527
  if (getTable()->getShare()->getTableProto()->options().auto_increment_value() > nr)
 
528
    nr= getTable()->getShare()->getTableProto()->options().auto_increment_value();
543
529
 
544
530
  return nr;
545
531
}
652
638
 
653
639
  /* the below is adapted from ha_innodb.cc */
654
640
 
655
 
  const uint32_t sql_command = session->getSqlCommand();
 
641
  const uint32_t sql_command = session_sql_command(session);
656
642
 
657
643
  if (sql_command == SQLCOM_DROP_TABLE) {
658
644
 
683
669
    unexpected if an obsolete consistent read view would be
684
670
    used. */
685
671
 
686
 
    enum_tx_isolation isolation_level= session->getTxIsolation();
 
672
    enum_tx_isolation isolation_level= session_tx_isolation(session);
687
673
 
688
674
    if (isolation_level != ISO_SERIALIZABLE
689
675
        && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
726
712
 
727
713
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
728
714
         && lock_type <= TL_WRITE)
729
 
        && ! session->doing_tablespace_operation()
 
715
        && !session_tablespace_op(session)
730
716
        && sql_command != SQLCOM_TRUNCATE
731
717
        && sql_command != SQLCOM_CREATE_TABLE) {
732
718
 
803
789
  return &name[l];
804
790
}
805
791
 
806
 
static void TableIdentifier_to_haildb_name(const identifier::Table &identifier, std::string *str)
 
792
static void TableIdentifier_to_haildb_name(const TableIdentifier &identifier, std::string *str)
807
793
{
808
794
  str->assign(table_path_to_haildb_name(identifier.getPath().c_str()));
809
795
}
832
818
int HailDBCursor::open(const char *name, int, uint32_t)
833
819
{
834
820
  const char* haildb_table_name= table_path_to_haildb_name(name);
835
 
  ib_err_t err= ib_table_get_id(haildb_table_name, &table_id);
 
821
  ib_err_t err= ib_cursor_open_table(haildb_table_name, NULL, &cursor);
836
822
  bool has_hidden_primary_key= false;
837
823
  ib_id_t idx_id;
838
824
 
839
825
  if (err != DB_SUCCESS)
840
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
841
 
 
842
 
  err= ib_cursor_open_table_using_id(table_id, NULL, &cursor);
843
 
  cursor_is_sec_index= false;
844
 
 
845
 
  if (err != DB_SUCCESS)
846
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
826
    return ib_err_t_to_drizzle_error(err);
847
827
 
848
828
  err= ib_index_get_id(haildb_table_name, "HIDDEN_PRIMARY", &idx_id);
849
829
 
874
854
{
875
855
  ib_err_t err= ib_cursor_close(cursor);
876
856
  if (err != DB_SUCCESS)
877
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
857
    return ib_err_t_to_drizzle_error(err);
878
858
 
879
859
  free_share();
880
860
 
907
887
{
908
888
  ib_col_attr_t column_attr= IB_COL_NONE;
909
889
 
910
 
  if (field.has_constraints() && field.constraints().is_notnull())
 
890
  if (field.has_constraints() && ! field.constraints().is_nullable())
911
891
    column_attr= IB_COL_NOT_NULL;
912
892
 
913
893
  switch (field.type())
938
918
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
939
919
                                  column_attr, 0, 4);
940
920
    break;
941
 
  case message::Table::Field::EPOCH:
 
921
  case message::Table::Field::TIMESTAMP:
942
922
    *err= ib_table_schema_add_col(schema, field.name().c_str(), IB_INT,
943
923
                                  column_attr, 0, 8);
944
924
    break;
1038
1018
 
1039
1019
int HailDBEngine::doCreateTable(Session &session,
1040
1020
                                        Table& table_obj,
1041
 
                                        const drizzled::identifier::Table &identifier,
 
1021
                                        const drizzled::TableIdentifier &identifier,
1042
1022
                                        drizzled::message::Table& table_message)
1043
1023
{
1044
1024
  ib_tbl_sch_t haildb_table_schema= NULL;
1082
1062
                        ER_CANT_CREATE_TABLE,
1083
1063
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1084
1064
                        haildb_table_name.c_str(), haildb_err, ib_strerror(haildb_err));
1085
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1065
    return ib_err_t_to_drizzle_error(haildb_err);
1086
1066
  }
1087
1067
 
1088
1068
  for (int colnr= 0; colnr < table_message.field_size() ; colnr++)
1103
1083
                            " HailDB Error %d (%s)\n"),
1104
1084
                          field.name().c_str(), haildb_table_name.c_str(),
1105
1085
                          haildb_err, ib_strerror(haildb_err));
1106
 
      return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1086
      return ib_err_t_to_drizzle_error(haildb_err);
1107
1087
    }
1108
1088
    if (field_err != 0)
1109
1089
      return field_err;
1251
1231
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1252
1232
                        haildb_table_name.c_str(),
1253
1233
                        haildb_err, ib_strerror(haildb_err));
1254
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1234
    return ib_err_t_to_drizzle_error(haildb_err);
1255
1235
  }
1256
1236
 
1257
1237
  return 0;
1294
1274
}
1295
1275
 
1296
1276
int HailDBEngine::doDropTable(Session &session,
1297
 
                                      const identifier::Table &identifier)
 
1277
                                      const TableIdentifier &identifier)
1298
1278
{
1299
1279
  ib_trx_t haildb_schema_transaction;
1300
1280
  ib_err_t haildb_err;
1376
1356
  return 0;
1377
1357
}
1378
1358
 
1379
 
static ib_err_t rename_table_message(ib_trx_t transaction, const identifier::Table &from_identifier, const identifier::Table &to_identifier)
 
1359
static ib_err_t rename_table_message(ib_trx_t transaction, const TableIdentifier &from_identifier, const TableIdentifier &to_identifier)
1380
1360
{
1381
1361
  ib_crsr_t cursor;
1382
1362
  ib_tpl_t search_tuple;
1467
1447
}
1468
1448
 
1469
1449
int HailDBEngine::doRenameTable(drizzled::Session &session,
1470
 
                                        const drizzled::identifier::Table &from,
1471
 
                                        const drizzled::identifier::Table &to)
 
1450
                                        const drizzled::TableIdentifier &from,
 
1451
                                        const drizzled::TableIdentifier &to)
1472
1452
{
1473
1453
  ib_trx_t haildb_schema_transaction;
1474
1454
  ib_err_t err;
1518
1498
  assert(rollback_err == DB_SUCCESS);
1519
1499
  rollback_err= ib_trx_rollback(haildb_schema_transaction);
1520
1500
  assert(rollback_err == DB_SUCCESS);
1521
 
  return ib_err_t_to_drizzle_error(&session, err);
 
1501
  return ib_err_t_to_drizzle_error(err);
1522
1502
}
1523
1503
 
1524
1504
void HailDBEngine::getTableNamesInSchemaFromHailDB(
1525
 
                                 const drizzled::identifier::Schema &schema,
 
1505
                                 const drizzled::SchemaIdentifier &schema,
1526
1506
                                 drizzled::plugin::TableNameList *set_of_names,
1527
 
                                 drizzled::identifier::Table::vector *identifiers)
 
1507
                                 drizzled::TableIdentifier::vector *identifiers)
1528
1508
{
1529
1509
  ib_trx_t   transaction;
1530
1510
  ib_crsr_t  cursor;
1554
1534
    {
1555
1535
      BOOST_FOREACH(std::string table_name, haildb_system_table_names)
1556
1536
      {
1557
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(),
 
1537
        identifiers->push_back(TableIdentifier(schema.getSchemaName(),
1558
1538
                                               table_name));
1559
1539
      }
1560
1540
    }
1597
1577
      if (set_of_names)
1598
1578
        set_of_names->insert(just_table_name);
1599
1579
      if (identifiers)
1600
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(), just_table_name));
 
1580
        identifiers->push_back(TableIdentifier(schema.getSchemaName(), just_table_name));
1601
1581
    }
1602
1582
 
1603
1583
 
1616
1596
}
1617
1597
 
1618
1598
void HailDBEngine::doGetTableIdentifiers(drizzled::CachedDirectory &,
1619
 
                                                 const drizzled::identifier::Schema &schema,
1620
 
                                                 drizzled::identifier::Table::vector &identifiers)
 
1599
                                                 const drizzled::SchemaIdentifier &schema,
 
1600
                                                 drizzled::TableIdentifier::vector &identifiers)
1621
1601
{
1622
1602
  getTableNamesInSchemaFromHailDB(schema, NULL, &identifiers);
1623
1603
}
1742
1722
}
1743
1723
 
1744
1724
int HailDBEngine::doGetTableDefinition(Session &session,
1745
 
                                               const identifier::Table &identifier,
 
1725
                                               const TableIdentifier &identifier,
1746
1726
                                               drizzled::message::Table &table)
1747
1727
{
1748
1728
  ib_crsr_t haildb_cursor= NULL;
1771
1751
}
1772
1752
 
1773
1753
bool HailDBEngine::doDoesTableExist(Session &,
1774
 
                                    const identifier::Table& identifier)
 
1754
                                    const TableIdentifier& identifier)
1775
1755
{
1776
1756
  ib_crsr_t haildb_cursor;
1777
1757
  string haildb_table_name;
1796
1776
  return("BTREE");
1797
1777
}
1798
1778
 
1799
 
static ib_err_t write_row_to_haildb_tuple(const unsigned char* buf,
1800
 
                                          Field **fields, ib_tpl_t tuple)
 
1779
static ib_err_t write_row_to_haildb_tuple(Field **fields, ib_tpl_t tuple)
1801
1780
{
1802
1781
  int colnr= 0;
1803
1782
  ib_err_t err= DB_ERROR;
1804
 
  ptrdiff_t row_offset= buf - (*fields)->getTable()->getInsertRecord();
1805
1783
 
1806
1784
  for (Field **field= fields; *field; field++, colnr++)
1807
1785
  {
1808
 
    (**field).move_field_offset(row_offset);
1809
 
 
1810
1786
    if (! (**field).isWriteSet() && (**field).is_null())
1811
 
    {
1812
 
      (**field).move_field_offset(-row_offset);
1813
1787
      continue;
1814
 
    }
1815
1788
 
1816
1789
    if ((**field).is_null())
1817
1790
    {
1818
1791
      err= ib_col_set_value(tuple, colnr, NULL, IB_SQL_NULL);
1819
1792
      assert(err == DB_SUCCESS);
1820
 
      (**field).move_field_offset(-row_offset);
1821
1793
      continue;
1822
1794
    }
1823
1795
 
1829
1801
      */
1830
1802
      String str;
1831
1803
      (**field).setReadSet();
1832
 
      (**field).val_str_internal(&str);
 
1804
      (**field).val_str(&str);
1833
1805
      err= ib_col_set_value(tuple, colnr, str.ptr(), str.length());
1834
1806
    }
1835
1807
    else if ((**field).type() == DRIZZLE_TYPE_ENUM)
1855
1827
    }
1856
1828
 
1857
1829
    assert (err == DB_SUCCESS);
1858
 
 
1859
 
    (**field).move_field_offset(-row_offset);
1860
1830
  }
1861
1831
 
1862
1832
  return err;
1905
1875
 
1906
1876
  tuple= ib_clust_read_tuple_create(cursor);
1907
1877
 
1908
 
  if (cursor_is_sec_index)
1909
 
  {
1910
 
    err= ib_cursor_close(cursor);
1911
 
    assert(err == DB_SUCCESS);
1912
 
 
1913
 
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
1914
 
 
1915
 
    if (err != DB_SUCCESS)
1916
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
1917
 
 
1918
 
    cursor_is_sec_index= false;
1919
 
  }
1920
 
  else
1921
 
  {
1922
 
    ib_cursor_attach_trx(cursor, transaction);
1923
 
  }
 
1878
  ib_cursor_attach_trx(cursor, transaction);
1924
1879
 
1925
1880
  err= ib_cursor_first(cursor);
1926
 
  if (current_session->getLex()->sql_command == SQLCOM_CREATE_TABLE
 
1881
  if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
1927
1882
      && err == DB_MISSING_HISTORY)
1928
1883
  {
1929
1884
    /* See https://bugs.launchpad.net/drizzle/+bug/556978
1979
1934
 
1980
1935
  }
1981
1936
 
1982
 
  write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
 
1937
  write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1983
1938
 
1984
1939
  if (share->has_hidden_primary_key)
1985
1940
  {
1986
 
    err= ib_tuple_write_u64(tuple, getTable()->getShare()->sizeFields(),
1987
 
                            share->hidden_pkey_auto_increment_value.fetch_and_increment());
 
1941
    err= ib_tuple_write_u64(tuple, getTable()->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1988
1942
  }
1989
1943
 
1990
1944
  err= ib_cursor_insert_row(cursor, tuple);
2013
1967
      err= ib_cursor_first(cursor);
2014
1968
      assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
2015
1969
 
2016
 
      write_row_to_haildb_tuple(record, getTable()->getFields(), tuple);
 
1970
      write_row_to_haildb_tuple(getTable()->getFields(), tuple);
2017
1971
 
2018
1972
      err= ib_cursor_insert_row(cursor, tuple);
2019
1973
      assert(err==DB_SUCCESS); // probably be nice and process errors
2022
1976
      ret= HA_ERR_FOUND_DUPP_KEY;
2023
1977
  }
2024
1978
  else if (err != DB_SUCCESS)
2025
 
    ret= ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
1979
    ret= ib_err_t_to_drizzle_error(err);
2026
1980
 
2027
1981
  tuple= ib_tuple_clear(tuple);
2028
1982
  ib_tuple_delete(tuple);
2029
 
  tuple= NULL;
2030
1983
  err= ib_cursor_reset(cursor);
2031
1984
 
2032
1985
  return ret;
2033
1986
}
2034
1987
 
2035
 
int HailDBCursor::doUpdateRecord(const unsigned char *old_data,
2036
 
                                 unsigned char *new_data)
 
1988
int HailDBCursor::doUpdateRecord(const unsigned char *,
 
1989
                                         unsigned char *)
2037
1990
{
2038
1991
  ib_tpl_t update_tuple;
2039
1992
  ib_err_t err;
2040
 
  bool created_tuple= false;
2041
1993
 
2042
1994
  update_tuple= ib_clust_read_tuple_create(cursor);
2043
1995
 
2044
 
  if (tuple == NULL)
2045
 
  {
2046
 
    ib_trx_t transaction= *get_trx(getTable()->in_use);
2047
 
 
2048
 
    if (cursor_is_sec_index)
2049
 
    {
2050
 
      err= ib_cursor_close(cursor);
2051
 
      assert(err == DB_SUCCESS);
2052
 
 
2053
 
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2054
 
 
2055
 
      if (err != DB_SUCCESS)
2056
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2057
 
      cursor_is_sec_index= false;
2058
 
    }
2059
 
    else
2060
 
    {
2061
 
      ib_cursor_attach_trx(cursor, transaction);
2062
 
    }
2063
 
 
2064
 
    store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
2065
 
                                  ref, ref_length, old_data);
2066
 
 
2067
 
    ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
2068
 
 
2069
 
    fill_ib_search_tpl_from_drizzle_key(search_tuple,
2070
 
                                        getTable()->key_info + 0,
2071
 
                                        ref, ref_length);
2072
 
 
2073
 
    err= ib_cursor_set_lock_mode(cursor, IB_LOCK_X);
2074
 
    assert(err == DB_SUCCESS);
2075
 
 
2076
 
    int res;
2077
 
    err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2078
 
    assert(err == DB_SUCCESS);
2079
 
 
2080
 
    tuple= ib_clust_read_tuple_create(cursor);
2081
 
 
2082
 
    err= ib_cursor_read_row(cursor, tuple);
2083
 
    assert(err == DB_SUCCESS);// FIXME
2084
 
 
2085
 
    created_tuple= true;
2086
 
  }
2087
 
 
2088
1996
  err= ib_tuple_copy(update_tuple, tuple);
2089
1997
  assert(err == DB_SUCCESS);
2090
1998
 
2091
 
  write_row_to_haildb_tuple(new_data, getTable()->getFields(), update_tuple);
 
1999
  write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
2092
2000
 
2093
2001
  err= ib_cursor_update_row(cursor, tuple, update_tuple);
2094
2002
 
2095
2003
  ib_tuple_delete(update_tuple);
2096
2004
 
2097
 
  if (created_tuple)
2098
 
  {
2099
 
    ib_err_t ib_err= ib_cursor_reset(cursor); //fixme check error
2100
 
    assert(ib_err == DB_SUCCESS);
2101
 
    tuple= ib_tuple_clear(tuple);
2102
 
    ib_tuple_delete(tuple);
2103
 
    tuple= NULL;
2104
 
  }
2105
 
 
2106
2005
  advance_cursor= true;
2107
2006
 
2108
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2007
  if (err == DB_SUCCESS)
 
2008
    return 0;
 
2009
  else if (err == DB_DUPLICATE_KEY)
 
2010
    return HA_ERR_FOUND_DUPP_KEY;
 
2011
  else
 
2012
    return -1;
2109
2013
}
2110
2014
 
2111
2015
int HailDBCursor::doDeleteRecord(const unsigned char *)
2112
2016
{
2113
2017
  ib_err_t err;
2114
2018
 
2115
 
  assert(ib_cursor_is_positioned(cursor) == IB_TRUE);
2116
2019
  err= ib_cursor_delete_row(cursor);
 
2020
  if (err != DB_SUCCESS)
 
2021
    return -1; // FIXME
2117
2022
 
2118
2023
  advance_cursor= true;
2119
 
 
2120
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2024
  return 0;
2121
2025
}
2122
2026
 
2123
2027
int HailDBCursor::delete_all_rows(void)
2124
2028
{
2125
2029
  /* I *think* ib_truncate is non-transactional....
2126
2030
     so only support TRUNCATE and not DELETE FROM t;
2127
 
     (this is what ha_innodb does)
 
2031
     (this is what ha_haildb does)
2128
2032
  */
2129
 
  if (getTable()->in_use->getSqlCommand() != SQLCOM_TRUNCATE)
 
2033
  if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2130
2034
    return HA_ERR_WRONG_COMMAND;
2131
2035
 
2132
2036
  ib_id_t id;
2134
2038
 
2135
2039
  ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
2136
2040
 
2137
 
  if (cursor_is_sec_index)
2138
 
  {
2139
 
    err= ib_cursor_close(cursor);
2140
 
    assert(err == DB_SUCCESS);
2141
 
 
2142
 
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2143
 
 
2144
 
    if (err != DB_SUCCESS)
2145
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2146
 
    cursor_is_sec_index= false;
2147
 
  }
2148
 
  else
2149
 
  {
2150
 
    ib_cursor_attach_trx(cursor, transaction);
2151
 
  }
 
2041
  ib_cursor_attach_trx(cursor, transaction);
2152
2042
 
2153
2043
  err= ib_schema_lock_exclusive(transaction);
2154
2044
  if (err != DB_SUCCESS)
2184
2074
  ib_schema_unlock(transaction);
2185
2075
  ib_err_t rollback_err= ib_trx_rollback(transaction);
2186
2076
  assert(rollback_err == DB_SUCCESS);
2187
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2077
  return err;
2188
2078
}
2189
2079
 
2190
2080
int HailDBCursor::doStartTableScan(bool)
2191
2081
{
2192
 
  ib_err_t err= DB_SUCCESS;
 
2082
  ib_err_t err;
2193
2083
  ib_trx_t transaction;
2194
2084
 
2195
2085
  if (in_table_scan)
2200
2090
 
2201
2091
  assert(transaction != NULL);
2202
2092
 
2203
 
  if (cursor_is_sec_index)
2204
 
  {
2205
 
    err= ib_cursor_close(cursor);
2206
 
    assert(err == DB_SUCCESS);
2207
 
 
2208
 
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2209
 
    cursor_is_sec_index= false;
2210
 
  }
2211
 
  else
2212
 
  {
2213
 
    ib_cursor_attach_trx(cursor, transaction);
2214
 
  }
2215
 
 
2216
 
  if (err != DB_SUCCESS)
2217
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2093
  ib_cursor_attach_trx(cursor, transaction);
2218
2094
 
2219
2095
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2220
2096
  assert(err == DB_SUCCESS); // FIXME
2224
2100
  err= ib_cursor_first(cursor);
2225
2101
  if (err != DB_SUCCESS && err != DB_END_OF_INDEX)
2226
2102
  {
2227
 
    int reset_err= ib_cursor_reset(cursor);
2228
 
    assert(reset_err == DB_SUCCESS);
2229
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2103
    previous_error= ib_err_t_to_drizzle_error(err);
 
2104
    err= ib_cursor_reset(cursor);
 
2105
    return previous_error;
2230
2106
  }
2231
2107
 
2232
2108
  advance_cursor= false;
2233
2109
 
 
2110
  previous_error= 0;
2234
2111
  return(0);
2235
2112
}
2236
2113
 
2237
 
int read_row_from_haildb(Session *session, unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot)
 
2114
int read_row_from_haildb(unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot)
2238
2115
{
2239
2116
  ib_err_t err;
2240
2117
  ptrdiff_t row_offset= buf - table->getInsertRecord();
2241
2118
 
2242
2119
  err= ib_cursor_read_row(cursor, tuple);
2243
2120
 
2244
 
  if (err == DB_RECORD_NOT_FOUND)
 
2121
  if (err != DB_SUCCESS) // FIXME
2245
2122
    return HA_ERR_END_OF_FILE;
2246
 
  if (err != DB_SUCCESS)
2247
 
    return ib_err_t_to_drizzle_error(session, err);
2248
2123
 
2249
2124
  int colnr= 0;
2250
2125
 
2255
2130
  for (Field **field= table->getFields() ; *field ; field++, colnr++)
2256
2131
  {
2257
2132
    if (! (**field).isReadSet())
2258
 
      (**field).setReadSet(); /* Fucking broken API screws us royally. */
 
2133
      continue;
2259
2134
 
2260
2135
    (**field).move_field_offset(row_offset);
2261
2136
 
2265
2140
    if (length == IB_SQL_NULL)
2266
2141
    {
2267
2142
      (**field).set_null();
2268
 
      (**field).move_field_offset(-row_offset);
2269
2143
      continue;
2270
2144
    }
2271
2145
    else
2309
2183
 
2310
2184
    (**field).move_field_offset(-row_offset);
2311
2185
 
2312
 
    if (err != DB_SUCCESS)
2313
 
      return ib_err_t_to_drizzle_error(session, err);
2314
2186
  }
2315
2187
 
2316
2188
  if (has_hidden_primary_key)
2318
2190
    err= ib_tuple_read_u64(tuple, colnr, hidden_pkey);
2319
2191
  }
2320
2192
 
2321
 
  return ib_err_t_to_drizzle_error(session, err);
 
2193
  return 0;
2322
2194
}
2323
2195
 
2324
2196
int HailDBCursor::rnd_next(unsigned char *buf)
2326
2198
  ib_err_t err;
2327
2199
  int ret;
2328
2200
 
 
2201
  if (previous_error)
 
2202
    return previous_error;
 
2203
 
2329
2204
  if (advance_cursor)
2330
 
  {
2331
2205
    err= ib_cursor_next(cursor);
2332
 
    if (err != DB_SUCCESS)
2333
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2334
 
  }
2335
2206
 
2336
2207
  tuple= ib_tuple_clear(tuple);
2337
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2338
 
                            getTable(),
 
2208
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2339
2209
                            share->has_hidden_primary_key,
2340
2210
                            &hidden_autoinc_pkey_position);
2341
2211
 
2348
2218
  ib_err_t err;
2349
2219
 
2350
2220
  ib_tuple_delete(tuple);
2351
 
  tuple= NULL;
2352
2221
  err= ib_cursor_reset(cursor);
2353
2222
  assert(err == DB_SUCCESS);
2354
2223
  in_table_scan= false;
2355
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2224
  previous_error= 0;
 
2225
  return 0;
2356
2226
}
2357
2227
 
2358
2228
int HailDBCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
2366
2236
  {
2367
2237
    err= ib_col_set_value(search_tuple, 0,
2368
2238
                          ((uint64_t*)(pos)), sizeof(uint64_t));
2369
 
    if (err != DB_SUCCESS)
2370
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2371
2239
  }
2372
2240
  else
2373
2241
  {
2383
2251
  }
2384
2252
 
2385
2253
  err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2386
 
  if (err != DB_SUCCESS)
2387
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2254
  assert(err == DB_SUCCESS);
2388
2255
 
2389
2256
  assert(res==0);
2390
2257
  if (res != 0)
2395
2262
  tuple= ib_tuple_clear(tuple);
2396
2263
 
2397
2264
  if (ret == 0)
2398
 
    ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2399
 
                              getTable(),
 
2265
    ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2400
2266
                              share->has_hidden_primary_key,
2401
2267
                              &hidden_autoinc_pkey_position);
2402
2268
 
2434
2300
      }
2435
2301
 
2436
2302
      String str;
2437
 
      field->val_str_internal(&str);
 
2303
      field->val_str(&str);
2438
2304
 
2439
2305
      *ref++= (char)(str.length() & 0x000000ff);
2440
2306
      *ref++= (char)((str.length()>>8) & 0x000000ff);
2513
2379
 
2514
2380
  if (flag & HA_STATUS_AUTO)
2515
2381
    stats.auto_increment_value= 1;
2516
 
 
2517
 
  if (flag & HA_STATUS_ERRKEY) {
2518
 
    const char *err_table_name;
2519
 
    const char *err_index_name;
2520
 
 
2521
 
    ib_trx_t transaction= *get_trx(getTable()->in_use);
2522
 
 
2523
 
    err= ib_get_duplicate_key(transaction, &err_table_name, &err_index_name);
2524
 
 
2525
 
    errkey= UINT32_MAX;
2526
 
 
2527
 
    for (unsigned int i = 0; i < getTable()->getShare()->keys; i++)
2528
 
    {
2529
 
      if (strcmp(err_index_name, getTable()->key_info[i].name) == 0)
2530
 
      {
2531
 
        errkey= i;
2532
 
        break;
2533
 
      }
2534
 
    }
2535
 
 
2536
 
  }
2537
 
 
2538
 
  if (flag & HA_STATUS_CONST)
2539
 
  {
2540
 
    for (unsigned int i = 0; i < getTable()->getShare()->sizeKeys(); i++)
2541
 
    {
2542
 
      const char* index_name= getTable()->key_info[i].name;
2543
 
      uint64_t ncols;
2544
 
      int64_t *n_diff;
2545
 
      ha_rows rec_per_key;
2546
 
 
2547
 
      err= ib_get_index_stat_n_diff_key_vals(cursor, index_name,
2548
 
                                             &ncols, &n_diff);
2549
 
 
2550
 
      if (err != DB_SUCCESS)
2551
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2552
 
 
2553
 
      for (unsigned int j=0; j < getTable()->key_info[i].key_parts; j++)
2554
 
      {
2555
 
        if (n_diff[j+1] == 0)
2556
 
          rec_per_key= stats.records;
2557
 
        else
2558
 
          rec_per_key= stats.records / n_diff[j+1];
2559
 
 
2560
 
        /* We import this heuristic from ha_innodb, which says
2561
 
           that MySQL favours table scans too much over index searches,
2562
 
           so we pretend our index selectivity is 2 times better. */
2563
 
 
2564
 
        rec_per_key= rec_per_key / 2;
2565
 
 
2566
 
        if (rec_per_key == 0)
2567
 
          rec_per_key= 1;
2568
 
 
2569
 
        getTable()->key_info[i].rec_per_key[j]=
2570
 
          rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
2571
 
          (ulong) rec_per_key;
2572
 
      }
2573
 
 
2574
 
      free(n_diff);
2575
 
    }
2576
 
  }
2577
 
 
2578
2382
  return(0);
2579
2383
}
2580
2384
 
2581
2385
int HailDBCursor::doStartIndexScan(uint32_t keynr, bool)
2582
2386
{
2583
 
  ib_err_t err;
2584
2387
  ib_trx_t transaction= *get_trx(getTable()->in_use);
2585
2388
 
2586
2389
  active_index= keynr;
2587
2390
 
 
2391
  ib_cursor_attach_trx(cursor, transaction);
 
2392
 
2588
2393
  if (active_index == 0 && ! share->has_hidden_primary_key)
2589
2394
  {
2590
 
    if (cursor_is_sec_index)
2591
 
    {
2592
 
      err= ib_cursor_close(cursor);
2593
 
      assert(err == DB_SUCCESS);
2594
 
 
2595
 
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2596
 
 
2597
 
      if (err != DB_SUCCESS)
2598
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2599
 
 
2600
 
    }
2601
 
    else
2602
 
    {
2603
 
      ib_cursor_attach_trx(cursor, transaction);
2604
 
    }
2605
 
 
2606
 
    cursor_is_sec_index= false;
2607
2395
    tuple= ib_clust_read_tuple_create(cursor);
2608
2396
  }
2609
2397
  else
2610
2398
  {
 
2399
    ib_err_t err;
2611
2400
    ib_id_t index_id;
2612
2401
    err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2613
2402
                         getShare()->getKeyInfo(keynr).name,
2614
2403
                         &index_id);
2615
2404
    if (err != DB_SUCCESS)
2616
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2405
      return -1;
2617
2406
 
2618
2407
    err= ib_cursor_close(cursor);
2619
2408
    assert(err == DB_SUCCESS);
2620
 
 
2621
2409
    err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2622
2410
 
2623
2411
    if (err != DB_SUCCESS)
2624
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2625
 
 
2626
 
    cursor_is_sec_index= true;
 
2412
      return -1;
2627
2413
 
2628
2414
    tuple= ib_clust_read_tuple_create(cursor);
2629
2415
    ib_cursor_set_cluster_access(cursor);
2630
2416
  }
2631
2417
 
2632
 
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
 
2418
  ib_err_t err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2633
2419
  assert(err == DB_SUCCESS);
2634
2420
 
2635
2421
  advance_cursor= false;
2774
2560
 
2775
2561
  if (err != DB_SUCCESS)
2776
2562
  {
2777
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2563
    return ib_err_t_to_drizzle_error(err);
2778
2564
  }
2779
2565
 
2780
2566
  tuple= ib_tuple_clear(tuple);
2781
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2782
 
                            getTable(),
 
2567
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2783
2568
                            share->has_hidden_primary_key,
2784
2569
                            &hidden_autoinc_pkey_position,
2785
2570
                            (allocate_blobs)? &blobroot : NULL);
2856
2641
  return 0;
2857
2642
}
2858
2643
 
2859
 
int HailDBCursor::analyze(Session*)
2860
 
{
2861
 
  ib_err_t err;
2862
 
 
2863
 
  err= ib_update_table_statistics(cursor);
2864
 
 
2865
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2866
 
}
2867
 
 
2868
2644
int HailDBCursor::index_next(unsigned char *buf)
2869
2645
{
2870
2646
  int ret= HA_ERR_END_OF_FILE;
2877
2653
  }
2878
2654
 
2879
2655
  tuple= ib_tuple_clear(tuple);
2880
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2881
 
                            getTable(),
 
2656
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2882
2657
                            share->has_hidden_primary_key,
2883
2658
                            &hidden_autoinc_pkey_position);
2884
2659
 
2906
2681
      if (err == DB_END_OF_INDEX)
2907
2682
        return HA_ERR_END_OF_FILE;
2908
2683
      else
2909
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2684
        return -1; // FIXME
2910
2685
    }
2911
2686
  }
2912
2687
 
2913
2688
  tuple= ib_tuple_clear(tuple);
2914
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2915
 
                            getTable(),
 
2689
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2916
2690
                            share->has_hidden_primary_key,
2917
2691
                            &hidden_autoinc_pkey_position);
2918
2692
 
2929
2703
 
2930
2704
  err= ib_cursor_first(cursor);
2931
2705
  if (err != DB_SUCCESS)
2932
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2706
    return ib_err_t_to_drizzle_error(err);
2933
2707
 
2934
2708
  tuple= ib_tuple_clear(tuple);
2935
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2936
 
                            getTable(),
 
2709
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2937
2710
                            share->has_hidden_primary_key,
2938
2711
                            &hidden_autoinc_pkey_position);
2939
2712
 
2950
2723
 
2951
2724
  err= ib_cursor_last(cursor);
2952
2725
  if (err != DB_SUCCESS)
2953
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2726
    return ib_err_t_to_drizzle_error(err);
2954
2727
 
2955
2728
  tuple= ib_tuple_clear(tuple);
2956
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2957
 
                            getTable(),
 
2729
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2958
2730
                            share->has_hidden_primary_key,
2959
2731
                            &hidden_autoinc_pkey_position);
2960
2732
  advance_cursor= true;
3136
2908
  (void)err;
3137
2909
}
3138
2910
 
3139
 
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...);
3140
 
namespace drizzled
3141
 
{
3142
 
extern bool volatile shutdown_in_progress;
3143
 
}
3144
 
 
3145
 
extern "C" int haildb_errmsg_callback(ib_msg_stream_t, const char *fmt, ...)
3146
 
{
3147
 
  bool r= false;
3148
 
  va_list args;
3149
 
  va_start(args, fmt);
3150
 
  if (not shutdown_in_progress)
3151
 
  {
3152
 
    r= plugin::ErrorMessage::vprintf(error::WARN, fmt, args);
3153
 
  }
3154
 
  else
3155
 
  {
3156
 
    vfprintf(stderr, fmt, args);
3157
 
  }
3158
 
  va_end(args);
3159
 
 
3160
 
  return (! r==true);
3161
 
}
3162
2911
 
3163
2912
static int haildb_init(drizzled::module::Context &context)
3164
2913
{
3187
2936
  if (err != DB_SUCCESS)
3188
2937
    goto haildb_error;
3189
2938
 
3190
 
  ib_logger_set(haildb_errmsg_callback, NULL);
3191
2939
 
3192
2940
  if (not vm["data-home-dir"].as<string>().empty())
3193
2941
  {
3539
3287
  "Transactional Storage Engine using the HailDB Library",
3540
3288
  PLUGIN_LICENSE_GPL,
3541
3289
  haildb_init,     /* Plugin Init */
3542
 
  NULL, /* depends */
 
3290
  NULL, /* system variables */
3543
3291
  init_options                /* config options   */
3544
3292
}
3545
3293
DRIZZLE_DECLARE_PLUGIN_END;