~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/filesystem_engine/filesystem_engine.cc

  • Committer: Brian Aker
  • Date: 2010-10-15 00:59:36 UTC
  • mfrom: (1849 staging)
  • mto: This revision was merged to the branch mainline in revision 1853.
  • Revision ID: brian@tangent.org-20101015005936-znhvkz8khs4fhlyv
Merge with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    pthread_mutex_destroy(&filesystem_mutex);
75
75
  }
76
76
 
77
 
  virtual Cursor *create(Table &table)
 
77
  virtual Cursor *create(TableShare &table)
78
78
  {
79
79
    return new FilesystemCursor(*this, table);
80
80
  }
108
108
  int doRenameTable(Session&, const TableIdentifier &, const TableIdentifier &);
109
109
  void doGetTableIdentifiers(drizzled::CachedDirectory &directory,
110
110
                             const drizzled::SchemaIdentifier &schema_identifier,
111
 
                             drizzled::TableIdentifier::vector &set_of_identifiers);
 
111
                             drizzled::TableIdentifiers &set_of_identifiers);
112
112
private:
113
113
  void getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
114
114
                                   const drizzled::SchemaIdentifier &schema_identifier,
115
115
                                   drizzled::plugin::TableNameList *set_of_names,
116
 
                                   drizzled::TableIdentifier::vector *set_of_identifiers);
 
116
                                   drizzled::TableIdentifiers *set_of_identifiers);
117
117
};
118
118
 
119
119
void FilesystemEngine::getTableNamesFromFilesystem(drizzled::CachedDirectory &directory,
120
120
                                                   const drizzled::SchemaIdentifier &schema_identifier,
121
121
                                                   drizzled::plugin::TableNameList *set_of_names,
122
 
                                                   drizzled::TableIdentifier::vector *set_of_identifiers)
 
122
                                                   drizzled::TableIdentifiers *set_of_identifiers)
123
123
{
124
124
  drizzled::CachedDirectory::Entries entries= directory.getEntries();
125
125
 
153
153
 
154
154
void FilesystemEngine::doGetTableIdentifiers(drizzled::CachedDirectory &directory,
155
155
                                             const drizzled::SchemaIdentifier &schema_identifier,
156
 
                                             drizzled::TableIdentifier::vector &set_of_identifiers)
 
156
                                             drizzled::TableIdentifiers &set_of_identifiers)
157
157
{
158
158
  getTableNamesFromFilesystem(directory, schema_identifier, NULL, &set_of_identifiers);
159
159
}
317
317
  // then columns of this table are added dynamically here.
318
318
  FormatInfo format;
319
319
  format.parseFromTable(&table_proto);
320
 
  if (not format.isTagFormat() || not format.isFileGiven())
321
 
  {
 
320
  if (!format.isTagFormat() || !format.isFileGiven()) {
322
321
    close(fd);
323
322
    return EEXIST;
324
323
  }
325
324
 
326
 
  std::vector< std::map<std::string, std::string> > vm;
327
 
  if (parseTaggedFile(format, vm) != 0)
328
 
  {
 
325
  vector< map<string, string> > vm;
 
326
  if (parseTaggedFile(format, vm) != 0) {
329
327
    close(fd);
330
328
 
331
329
    return EEXIST;
338
336
  // we don't care what user provides, just clear them all
339
337
  table_proto.clear_field();
340
338
  // we take the first section as sample
341
 
  std::map<string, string> kv= vm[0];
342
 
  for (std::map<string, string>::iterator iter= kv.begin();
 
339
  map<string, string> kv= vm[0];
 
340
  for (map<string, string>::iterator iter= kv.begin();
343
341
       iter != kv.end();
344
342
       ++iter)
345
343
  {
371
369
{
372
370
  Guard g(filesystem_mutex);
373
371
 
374
 
  FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(getEngine());
 
372
  FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(engine);
375
373
  share= a_engine->findOpenTable(table_name);
376
374
 
377
375
  /*
386
384
      return NULL;
387
385
    }
388
386
 
389
 
    share->format.parseFromTable(getTable()->getShare()->getTableProto());
 
387
    share->format.parseFromTable(table->getShare()->getTableProto());
390
388
    if (!share->format.isFileGiven())
391
389
    {
392
390
      return NULL;
416
414
  Guard g(filesystem_mutex);
417
415
 
418
416
  if (!--share->use_count){
419
 
    FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(getEngine());
 
417
    FilesystemEngine *a_engine= static_cast<FilesystemEngine *>(engine);
420
418
    a_engine->deleteOpenTable(share->table_name);
421
419
    pthread_mutex_destroy(&share->mutex);
422
420
    delete share;
455
453
  thread_locked = false;
456
454
}
457
455
 
458
 
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, Table &table_arg)
 
456
FilesystemCursor::FilesystemCursor(drizzled::plugin::StorageEngine &engine_arg, TableShare &table_arg)
459
457
  : Cursor(engine_arg, table_arg),
460
458
    file_buff(new TransparentFile),
461
459
    thread_locked(false)
489
487
 
490
488
int FilesystemCursor::doStartTableScan(bool)
491
489
{
492
 
  sql_command_type = session_sql_command(getTable()->getSession());
 
490
  sql_command_type = session_sql_command(table->getSession());
493
491
 
494
492
  if (thread_locked)
495
493
    critical_section_exit();
517
515
 
518
516
int FilesystemCursor::find_current_row(unsigned char *buf)
519
517
{
520
 
  ptrdiff_t row_offset= buf - getTable()->record[0];
 
518
  ptrdiff_t row_offset= buf - table->record[0];
521
519
 
522
520
  next_position= current_position;
523
521
 
524
522
  string content;
525
523
  bool line_done= false;
526
524
  bool line_blank= true;
527
 
  Field **field= getTable()->getFields();
 
525
  Field **field= table->getFields();
528
526
  for (; !line_done && *field; ++next_position)
529
527
  {
530
528
    char ch= file_buff->get_value(next_position);
563
561
        if ((*field)->isReadSet() || (*field)->isWriteSet())
564
562
        {
565
563
          (*field)->setWriteSet();
566
 
          (*field)->store_and_check(CHECK_FIELD_WARN,
567
 
                                    content.c_str(),
568
 
                                    (uint32_t)content.length(),
569
 
                                    &my_charset_bin);
 
564
          (*field)->store(content.c_str(),
 
565
                          (uint32_t)content.length(),
 
566
                          &my_charset_bin,
 
567
                          CHECK_FIELD_WARN);
570
568
        }
571
569
        else
572
 
        {
573
570
          (*field)->set_default();
574
 
        }
575
571
      }
576
572
      else
577
573
        (*field)->set_null();
620
616
    if (tag_depth >= share->vm.size())
621
617
      return HA_ERR_END_OF_FILE;
622
618
 
623
 
    ptrdiff_t row_offset= buf - getTable()->record[0];
624
 
    for (Field **field= getTable()->getFields(); *field; field++)
 
619
    ptrdiff_t row_offset= buf - table->record[0];
 
620
    for (Field **field= table->getFields(); *field; field++)
625
621
    {
626
622
      string key((*field)->field_name);
627
623
      string content= share->vm[tag_depth][key];
633
629
        if ((*field)->isReadSet() || (*field)->isWriteSet())
634
630
        {
635
631
          (*field)->setWriteSet();
636
 
          (*field)->store_and_check(CHECK_FIELD_WARN,
637
 
                                    content.c_str(),
638
 
                                    (uint32_t)content.length(),
639
 
                                    &my_charset_bin);
 
632
          (*field)->store(content.c_str(),
 
633
                          (uint32_t)content.length(),
 
634
                          &my_charset_bin,
 
635
                          CHECK_FIELD_WARN);
640
636
        }
641
637
        else
642
638
        {
700
696
 
701
697
int FilesystemCursor::doEndTableScan()
702
698
{
703
 
  sql_command_type = session_sql_command(getTable()->getSession());
 
699
  sql_command_type = session_sql_command(table->getSession());
704
700
 
705
701
  if (share->format.isTagFormat())
706
702
  {
788
784
{
789
785
  bool first= true;
790
786
  drizzled::String attribute;
791
 
  for (Field **field= getTable()->getFields(); *field; ++field)
 
787
  for (Field **field= table->getFields(); *field; ++field)
792
788
  {
793
789
    if (first == true)
794
790
    {
821
817
  if (share->format.isTagFormat())
822
818
    return 0;
823
819
 
824
 
  sql_command_type = session_sql_command(getTable()->getSession());
 
820
  sql_command_type = session_sql_command(table->getSession());
825
821
 
826
822
  critical_section_enter();
827
823