~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-20 12:30:46 UTC
  • mto: (1792.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1793.
  • Revision ID: andrew@linuxjedi.co.uk-20100920123046-rjvv0haeksmmrrms
Add basic data dump output

Show diffs side-by-side

added added

removed removed

Lines of Context:
689
689
{
690
690
  drizzle_return_t ret;
691
691
  std::string query;
692
 
  query= "SELECT * FROM '";
 
692
  query= "SELECT * FROM `";
693
693
  query.append(table->tableName);
694
 
  query.append("'");
 
694
  query.append("`");
 
695
  result= new drizzle_result_st;
695
696
 
696
 
  if (drizzle_query_str(connection, &result, query.c_str(), &ret) == NULL ||
 
697
  if (drizzle_query_str(connection, result, query.c_str(), &ret) == NULL ||
697
698
      ret != DRIZZLE_RETURN_OK)
698
699
  {
699
700
    if (ret == DRIZZLE_RETURN_ERROR_CODE)
700
701
    {
701
702
      errmsg << _("Could not get tables list due to error: ") <<
702
 
        drizzle_result_error(&result);
703
 
      drizzle_result_free(&result);
 
703
        drizzle_result_error(result);
 
704
      drizzle_result_free(result);
704
705
    }
705
706
    else
706
707
    {
710
711
    return;
711
712
  }
712
713
 
713
 
  if (drizzle_result_buffer(&result) != DRIZZLE_RETURN_OK)
 
714
  if (drizzle_result_buffer(result) != DRIZZLE_RETURN_OK)
714
715
  {
715
716
    errmsg << _("Could not get tables list due to error: ") <<
716
717
        drizzle_con_error(connection);
719
720
}
720
721
DrizzleDumpData::~DrizzleDumpData()
721
722
{
722
 
  drizzle_result_free(&result);
 
723
  drizzle_result_free(result);
 
724
  if (result) delete result;
723
725
}
724
726
ostream& operator <<(ostream &os,const DrizzleDumpData &obj)
725
727
{
 
728
  bool new_insert= true;
 
729
  bool first= true;
726
730
  drizzle_row_t row;
727
 
  while((row= drizzle_row_next(&result)))
728
 
  {
729
 
 
730
 
  }
 
731
 
 
732
  if (drizzle_result_row_count(obj.result) < 1)
 
733
  {
 
734
    os << "--" << endl
 
735
       << "-- No data to dump for table `" << obj.table->tableName << "`" << endl
 
736
       << "--" << endl << endl;
 
737
    return os;
 
738
  }
 
739
  else
 
740
  {
 
741
    os << "--" << endl
 
742
       << "-- Dumping data for table `" << obj.table->tableName << "`" << endl
 
743
       << "--" << endl << endl;
 
744
  }
 
745
 
 
746
  while((row= drizzle_row_next(obj.result)))
 
747
  {
 
748
    if (not first)
 
749
    {
 
750
      if (extended_insert)
 
751
        os << "),(";
 
752
      else
 
753
        os << ");" << endl;
 
754
    }
 
755
    else
 
756
      first= false;
 
757
 
 
758
    if (new_insert)
 
759
    {
 
760
      if (opt_replace_into)
 
761
        os << "REPLACE ";
 
762
      else
 
763
        os << "INSERT ";
 
764
      os << "INTO `" << obj.table->tableName << "` VALUES (";
 
765
      if (extended_insert)
 
766
        new_insert= false;
 
767
    }
 
768
    for (uint32_t i= 0; i < drizzle_result_column_count(obj.result); i++)
 
769
    {
 
770
      // time/date conversion probably needs to happen here
 
771
      os << row[i];
 
772
      if (i != obj.table->fields.size() - 1)
 
773
        os << ",";
 
774
    }
 
775
  }
 
776
  os << ");" << endl << endl;
731
777
  return os;
732
778
}
733
779