~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/csv/ha_tina.cc

  • Committer: Brian Aker
  • Date: 2010-10-06 18:16:00 UTC
  • mto: (1818.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1819.
  • Revision ID: brian@tangent.org-20101006181600-q7zuzw31zlq030ra
Convert sql_string to use size_t (this should clean up ICC warnings).

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
 -Brian
42
42
*/
43
 
#include <config.h>
 
43
#include "config.h"
44
44
#include <drizzled/field.h>
45
45
#include <drizzled/field/blob.h>
 
46
#include <drizzled/field/timestamp.h>
46
47
#include <drizzled/error.h>
47
48
#include <drizzled/table.h>
48
49
#include <drizzled/session.h>
49
 
#include <drizzled/internal/my_sys.h>
 
50
#include "drizzled/internal/my_sys.h"
50
51
 
51
52
#include "ha_tina.h"
52
53
 
63
64
/*
64
65
  unsigned char + unsigned char + uint64_t + uint64_t + uint64_t + uint64_t + unsigned char
65
66
*/
66
 
static const int META_BUFFER_SIZE = sizeof(unsigned char) + sizeof(unsigned char) + sizeof(uint64_t)
67
 
  + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(unsigned char);
68
 
static const int TINA_CHECK_HEADER = 254; // The number we use to determine corruption
69
 
static const int BLOB_MEMROOT_ALLOC_SIZE = 8192;
 
67
#define META_BUFFER_SIZE sizeof(unsigned char) + sizeof(unsigned char) + sizeof(uint64_t) \
 
68
  + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(unsigned char)
 
69
#define TINA_CHECK_HEADER 254 // The number we use to determine corruption
 
70
#define BLOB_MEMROOT_ALLOC_SIZE 8192
70
71
 
71
72
/* The file extension */
72
 
static const char* CSV_EXT = ".CSV"               // The data file
73
 
static const char* CSN_EXT = ".CSN"               // Files used during repair and update
74
 
static const char* CSM_EXT = ".CSM"               // Meta file
 
73
#define CSV_EXT ".CSV"               // The data file
 
74
#define CSN_EXT ".CSN"               // Files used during repair and update
 
75
#define CSM_EXT ".CSM"               // Meta file
75
76
 
76
77
 
77
78
static int read_meta_file(int meta_file, ha_rows *rows);
111
112
    pthread_mutex_destroy(&tina_mutex);
112
113
  }
113
114
 
114
 
  virtual Cursor *create(Table &table)
 
115
  virtual Cursor *create(TableShare &table)
115
116
  {
116
117
    return new ha_tina(*this, table);
117
118
  }
122
123
 
123
124
  int doCreateTable(Session &,
124
125
                    Table &table_arg,
125
 
                    const drizzled::identifier::Table &identifier,
 
126
                    const drizzled::TableIdentifier &identifier,
126
127
                    drizzled::message::Table&);
127
128
 
128
129
  int doGetTableDefinition(Session& session,
129
 
                           const drizzled::identifier::Table &identifier,
 
130
                           const drizzled::TableIdentifier &identifier,
130
131
                           drizzled::message::Table &table_message);
131
132
 
132
 
  int doDropTable(Session&, const drizzled::identifier::Table &identifier);
 
133
  int doDropTable(Session&, const drizzled::TableIdentifier &identifier);
133
134
  TinaShare *findOpenTable(const string table_name);
134
135
  void addOpenTable(const string &table_name, TinaShare *);
135
136
  void deleteOpenTable(const string &table_name);
138
139
  uint32_t max_keys()          const { return 0; }
139
140
  uint32_t max_key_parts()     const { return 0; }
140
141
  uint32_t max_key_length()    const { return 0; }
141
 
  bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
142
 
  int doRenameTable(Session&, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
 
142
  bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
 
143
  int doRenameTable(Session&, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
143
144
 
144
145
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
145
 
                             const drizzled::identifier::Schema &schema_identifier,
146
 
                             drizzled::identifier::Table::vector &set_of_identifiers);
 
146
                             const drizzled::SchemaIdentifier &schema_identifier,
 
147
                             drizzled::TableIdentifiers &set_of_identifiers);
147
148
};
148
149
 
149
150
void Tina::doGetTableIdentifiers(drizzled::CachedDirectory&,
150
 
                                 const drizzled::identifier::Schema&,
151
 
                                 drizzled::identifier::Table::vector&)
 
151
                                 const drizzled::SchemaIdentifier&,
 
152
                                 drizzled::TableIdentifiers&)
152
153
{
153
154
}
154
155
 
155
156
int Tina::doRenameTable(Session &session,
156
 
                        const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)
 
157
                        const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)
157
158
{
158
159
  int error= 0;
159
160
  for (const char **ext= bas_ext(); *ext ; ext++)
166
167
    }
167
168
  }
168
169
 
169
 
  session.getMessageCache().renameTableMessage(from, to);
 
170
  session.renameTableMessage(from, to);
170
171
 
171
172
  return error;
172
173
}
173
174
 
174
 
bool Tina::doDoesTableExist(Session &session, const drizzled::identifier::Table &identifier)
 
175
bool Tina::doDoesTableExist(Session &session, const drizzled::TableIdentifier &identifier)
175
176
{
176
 
  return session.getMessageCache().doesTableMessageExist(identifier);
 
177
  return session.doesTableMessageExist(identifier);
177
178
}
178
179
 
179
180
 
180
181
int Tina::doDropTable(Session &session,
181
 
                      const drizzled::identifier::Table &identifier)
 
182
                      const drizzled::TableIdentifier &identifier)
182
183
{
183
184
  int error= 0;
184
185
  int enoent_or_zero= ENOENT;                   // Error if no file was deleted
200
201
    error= enoent_or_zero;
201
202
  }
202
203
 
203
 
  session.getMessageCache().removeTableMessage(identifier);
 
204
  session.removeTableMessage(identifier);
204
205
 
205
206
  return error;
206
207
}
228
229
 
229
230
 
230
231
int Tina::doGetTableDefinition(Session &session,
231
 
                               const drizzled::identifier::Table &identifier,
 
232
                               const drizzled::TableIdentifier &identifier,
232
233
                               drizzled::message::Table &table_message)
233
234
{
234
 
  if (session.getMessageCache().getTableMessage(identifier, table_message))
 
235
  if (session.getTableMessage(identifier, table_message))
235
236
    return EEXIST;
236
237
 
237
238
  return ENOENT;
278
279
{
279
280
  pthread_mutex_lock(&tina_mutex);
280
281
 
281
 
  Tina *a_tina= static_cast<Tina *>(getEngine());
 
282
  Tina *a_tina= static_cast<Tina *>(engine);
282
283
  share= a_tina->findOpenTable(table_name);
283
284
 
284
285
  std::string meta_file_name;
480
481
      share->tina_write_opened= false;
481
482
    }
482
483
 
483
 
    Tina *a_tina= static_cast<Tina *>(getEngine());
 
484
    Tina *a_tina= static_cast<Tina *>(engine);
484
485
    a_tina->deleteOpenTable(share->table_name);
485
486
    delete share;
486
487
  }
529
530
 
530
531
 
531
532
 
532
 
ha_tina::ha_tina(drizzled::plugin::StorageEngine &engine_arg, Table &table_arg)
 
533
ha_tina::ha_tina(drizzled::plugin::StorageEngine &engine_arg, TableShare &table_arg)
533
534
  :Cursor(engine_arg, table_arg),
534
535
  /*
535
536
    These definitions are found in Cursor.h
556
557
 
557
558
  buffer.length(0);
558
559
 
559
 
  for (Field **field= getTable()->getFields() ; *field ; field++)
 
560
  for (Field **field= table->getFields() ; *field ; field++)
560
561
  {
561
562
    const char *ptr;
562
563
    const char *end_ptr;
596
597
        {
597
598
          buffer.append('\\');
598
599
          buffer.append('"');
599
 
          (void) *ptr++;
 
600
          *ptr++;
600
601
        }
601
602
        else if (*ptr == '\r')
602
603
        {
603
604
          buffer.append('\\');
604
605
          buffer.append('r');
605
 
          (void) *ptr++;
 
606
          *ptr++;
606
607
        }
607
608
        else if (*ptr == '\\')
608
609
        {
609
610
          buffer.append('\\');
610
611
          buffer.append('\\');
611
 
          (void) *ptr++;
 
612
          *ptr++;
612
613
        }
613
614
        else if (*ptr == '\n')
614
615
        {
615
616
          buffer.append('\\');
616
617
          buffer.append('n');
617
 
          (void) *ptr++;
 
618
          *ptr++;
618
619
        }
619
620
        else
620
621
          buffer.append(*ptr++);
674
675
 
675
676
  error= HA_ERR_CRASHED_ON_USAGE;
676
677
 
677
 
  memset(buf, 0, getTable()->getShare()->null_bytes);
 
678
  memset(buf, 0, table->getShare()->null_bytes);
678
679
 
679
 
  for (Field **field= getTable()->getFields() ; *field ; field++)
 
680
  for (Field **field=table->getFields() ; *field ; field++)
680
681
  {
681
682
    char curr_char;
682
683
 
745
746
    {
746
747
      /* This masks a bug in the logic for a SELECT * */
747
748
      (*field)->setWriteSet();
748
 
      if ((*field)->store_and_check(CHECK_FIELD_WARN, buffer.c_ptr(), buffer.length(), buffer.charset()))
749
 
      {
 
749
      if ((*field)->store(buffer.ptr(), buffer.length(), buffer.charset(),
 
750
                          CHECK_FIELD_WARN))
750
751
        goto err;
751
 
      }
752
752
 
753
753
      if ((*field)->flags & BLOB_FLAG)
754
754
      {
781
781
  this will not be called for every request. Any sort of positions
782
782
  that need to be reset should be kept in the ::extra() call.
783
783
*/
784
 
int ha_tina::doOpen(const identifier::Table &identifier, int , uint32_t )
 
784
int ha_tina::doOpen(const TableIdentifier &identifier, int , uint32_t )
785
785
{
786
786
  if (not (share= get_share(identifier.getPath().c_str())))
787
787
    return(ENOENT);
1268
1268
 
1269
1269
int Tina::doCreateTable(Session &session,
1270
1270
                        Table& table_arg,
1271
 
                        const drizzled::identifier::Table &identifier,
 
1271
                        const drizzled::TableIdentifier &identifier,
1272
1272
                        drizzled::message::Table &create_proto)
1273
1273
{
1274
1274
  char name_buff[FN_REFLEN];
1308
1308
 
1309
1309
  internal::my_close(create_file, MYF(0));
1310
1310
 
1311
 
  session.getMessageCache().storeTableMessage(identifier, create_proto);
 
1311
  session.storeTableMessage(identifier, create_proto);
1312
1312
 
1313
1313
  return 0;
1314
1314
}
1323
1323
  "CSV storage engine",
1324
1324
  PLUGIN_LICENSE_GPL,
1325
1325
  tina_init_func, /* Plugin Init */
1326
 
  NULL,                       /* depends */
 
1326
  NULL,                       /* system variables                */
1327
1327
  NULL                        /* config options                  */
1328
1328
}
1329
1329
DRIZZLE_DECLARE_PLUGIN_END;