~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to backend/wbpublic/sqlide/table_inserts_loader_be.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; version 2 of the
 
7
 * License.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
 
 
21
#include "stdafx.h"
 
22
 
 
23
#include "table_inserts_loader_be.h"
 
24
#include "recordset_table_inserts_storage.h"
 
25
#include "recordset_be.h"
 
26
 
 
27
 
 
28
using namespace grt;
 
29
 
 
30
 
 
31
TableInsertsLoader::TableInsertsLoader(bec::GRTManager *grtm)
 
32
:
 
33
_grtm(grtm)
 
34
{
 
35
}
 
36
 
 
37
 
 
38
void TableInsertsLoader::process_table(db_TableRef table, const std::string &inserts_script) //!
 
39
{
 
40
  if (!table.is_valid() || inserts_script.empty())
 
41
    return;
 
42
 
 
43
  Recordset_sql_storage::Ref input_storage= Recordset_sql_storage::create(_grtm);
 
44
  input_storage->sql_script(inserts_script);
 
45
  input_storage->schema_name(table->owner()->name());
 
46
  input_storage->table_name(table->name());
 
47
  {
 
48
    Sql_inserts_loader::Strings affective_columns;
 
49
    affective_columns.reserve(table->columns().count());
 
50
    GRTLIST_FOREACH (db_Column, table->columns(), col)
 
51
      affective_columns.push_back((*col)->name());
 
52
    input_storage->affective_columns(affective_columns);
 
53
  }
 
54
 
 
55
  Recordset::Ref rs= Recordset::create(_grtm);
 
56
  rs->data_storage(input_storage);
 
57
  rs->reset();
 
58
  
 
59
  Recordset_table_inserts_storage::Ref output_storage= Recordset_table_inserts_storage::create(_grtm);
 
60
  output_storage->table(table);
 
61
  // provoke creation of underlying table
 
62
  {
 
63
    Recordset::Ref rs= Recordset::create(_grtm);
 
64
    output_storage->unserialize(rs);
 
65
  }
 
66
  output_storage->serialize(rs);
 
67
}