MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
consumer.cpp
1 /*
2  Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "consumer.hpp"
19 
20 #ifdef USE_MYSQL
21 int
22 BackupConsumer::create_table_string(const TableS & table,
23  char * tableName,
24  char *buf){
25  int pos = 0;
26  int pos2 = 0;
27  char buf2[2048];
28 
29  pos += sprintf(buf+pos, "%s%s", "CREATE TABLE ", tableName);
30  pos += sprintf(buf+pos, "%s", "(");
31  pos2 += sprintf(buf2+pos2, "%s", " primary key(");
32 
33  for (int j = 0; j < table.getNoOfAttributes(); j++)
34  {
35  const AttributeDesc * desc = table[j];
36  // ndbout << desc->name << ": ";
37  pos += sprintf(buf+pos, "%s%s", desc->m_column->getName()," ");
38  switch(desc->m_column->getType()){
40  pos += sprintf(buf+pos, "%s", "int");
41  break;
43  pos += sprintf(buf+pos, "%s", "int unsigned");
44  break;
46  pos += sprintf(buf+pos, "%s", "float");
47  break;
50  pos += sprintf(buf+pos, "%s", "decimal");
51  break;
52  case NdbDictionary::Column::Olddecimalunsigned:
53  case NdbDictionary::Column::Decimalunsigned:
54  pos += sprintf(buf+pos, "%s", "decimal unsigned");
55  break;
57  pos += sprintf(buf+pos, "%s", "char");
58  break;
60  pos += sprintf(buf+pos, "%s", "varchar");
61  break;
63  pos += sprintf(buf+pos, "%s", "binary");
64  break;
66  pos += sprintf(buf+pos, "%s", "varchar binary");
67  break;
69  pos += sprintf(buf+pos, "%s", "bigint");
70  break;
72  pos += sprintf(buf+pos, "%s", "bigint unsigned");
73  break;
75  pos += sprintf(buf+pos, "%s", "double");
76  break;
78  pos += sprintf(buf+pos, "%s", "datetime");
79  break;
81  pos += sprintf(buf+pos, "%s", "date");
82  break;
84  pos += sprintf(buf+pos, "%s", "time");
85  break;
87  // pos += sprintf(buf+pos, "%s", "varchar binary");
88  return -1;
89  break;
90  default:
91  //pos += sprintf(buf+pos, "%s", "varchar binary");
92  return -1;
93  }
94  if (desc->arraySize > 1) {
95  int attrSize = desc->arraySize;
96  pos += sprintf(buf+pos, "%s%u%s",
97  "(",
98  attrSize,
99  ")");
100  }
101  if (desc->m_column->getPrimaryKey()) {
102  pos += sprintf(buf+pos, "%s", " not null");
103  pos2 += sprintf(buf2+pos2, "%s%s", desc->m_column->getName(), ",");
104  }
105  pos += sprintf(buf+pos, "%s", ",");
106  } // for
107  pos2--; // remove trailing comma
108  pos2 += sprintf(buf2+pos2, "%s", ")");
109  // pos--; // remove trailing comma
110 
111  pos += sprintf(buf+pos, "%s", buf2);
112  pos += sprintf(buf+pos, "%s", ") type=ndbcluster");
113  return 0;
114 }
115 
116 #endif // USE_MYSQL