~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump_data.h

  • Committer: Monty Taylor
  • Date: 2010-09-26 21:24:15 UTC
  • mto: (1796.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mordred@inaugust.com-20100926212415-5fn3p3q75pgiei7r
Moved protocol doc into the docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
class DrizzleDumpDatabase;
34
34
class DrizzleDumpData;
35
35
 
36
 
class DrizzleDumpForeignKey
37
 
{
38
 
  public:
39
 
    DrizzleDumpConnection *dcon;
40
 
    std::string constraintName;
41
 
 
42
 
    DrizzleDumpForeignKey(std::string name, DrizzleDumpConnection* connection) :
43
 
      dcon(connection),
44
 
      constraintName(name)
45
 
    { }
46
 
 
47
 
    virtual ~DrizzleDumpForeignKey() { }
48
 
 
49
 
    std::string parentColumns;
50
 
    std::string childColumns;
51
 
    std::string childTable;
52
 
    std::string matchOption;
53
 
    std::string deleteRule;
54
 
    std::string updateRule;
55
 
 
56
 
    friend std::ostream& operator <<(std::ostream &os, const DrizzleDumpForeignKey &obj);
57
 
};
58
 
 
59
36
class DrizzleDumpIndex
60
37
{
61
38
  public:
64
41
 
65
42
    DrizzleDumpIndex(std::string &index, DrizzleDumpConnection* connection) :
66
43
      dcon(connection),
67
 
      indexName(index),
68
 
      isPrimary(false),
69
 
      isUnique(false),
70
 
      isHash(false)
 
44
      indexName(index)
71
45
    { }
72
46
 
73
47
    virtual ~DrizzleDumpIndex() { }
75
49
    bool isPrimary;
76
50
    bool isUnique;
77
51
    bool isHash;
78
 
    uint32_t length;
79
52
 
80
53
    std::vector<std::string> columns;
81
54
    friend std::ostream& operator <<(std::ostream &os, const DrizzleDumpIndex &obj);
86
59
  public:
87
60
    DrizzleDumpField(std::string &field, DrizzleDumpConnection* connection) :
88
61
      dcon(connection),
89
 
      fieldName(field),
90
 
      isNull(false),
91
 
      isUnsigned(false),
92
 
      isAutoIncrement(false),
93
 
      defaultIsNull(false),
94
 
      convertDateTime(false),
95
 
      rangeCheck(false)
 
62
      fieldName(field)
96
63
    { }
97
64
 
98
65
    virtual ~DrizzleDumpField() { }
110
77
    bool isAutoIncrement;
111
78
    bool defaultIsNull;
112
79
    bool convertDateTime;
113
 
    bool rangeCheck;
114
80
    std::string defaultValue;
115
81
    std::string collation;
116
 
    std::string comment;
117
82
 
118
83
    /* For enum type */
119
84
    std::string enumValues;
131
96
  public:
132
97
    DrizzleDumpTable(std::string &table, DrizzleDumpConnection* connection) :
133
98
      dcon(connection),
134
 
      tableName(table),
135
 
      database(NULL)
 
99
      tableName(table)
136
100
    { }
137
101
 
138
102
    virtual ~DrizzleDumpTable() { }
142
106
 
143
107
    virtual bool populateFields() { return false; }
144
108
    virtual bool populateIndexes() { return false; }
145
 
    virtual bool populateFkeys() { return false; }
146
109
    virtual DrizzleDumpData* getData() { return NULL; }
147
110
    std::vector<DrizzleDumpField*> fields;
148
111
    std::vector<DrizzleDumpIndex*> indexes;
149
 
    std::vector<DrizzleDumpForeignKey*> fkeys;
150
112
 
151
113
    friend std::ostream& operator <<(std::ostream &os, const DrizzleDumpTable &obj);
152
114
    std::string tableName;
153
115
    std::string displayName;
154
116
    std::string engineName;
155
117
    std::string collate;
156
 
    std::string comment;
157
118
 
158
119
    // Currently MySQL only, hard to do in Drizzle
159
120
    uint64_t autoIncrement;
195
156
    drizzle_result_st *result;
196
157
    DrizzleDumpData(DrizzleDumpTable *dataTable, DrizzleDumpConnection *connection) :
197
158
      dcon(connection),
198
 
      table(dataTable),
199
 
      result(NULL)
 
159
      table(dataTable)
200
160
    { }
201
161
 
202
162
    virtual ~DrizzleDumpData() { }
203
163
    friend std::ostream& operator <<(std::ostream &os, const DrizzleDumpData &obj);
204
164
 
205
 
    virtual std::string checkDateTime(const char*, uint32_t) const { return std::string(""); }
 
165
    virtual std::ostream& checkDateTime(std::ostream &os, const char*, uint32_t) const { return os; }
206
166
    std::string convertHex(const unsigned char* from, size_t from_size) const;
207
 
    static std::string escape(const char* from, size_t from_size);
 
167
    std::string escape(const char* from, size_t from_size) const;
208
168
};
209
169
 
210
170
class DrizzleDumpConnection
242
202
 
243
203
    void freeResult(drizzle_result_st* result);
244
204
    bool setDB(std::string databaseName);
245
 
    bool usingDrizzleProtocol(void) const { return drizzleProtocol; }
246
 
    bool getServerType(void) const { return serverType; }
 
205
    bool usingDrizzleProtocol(void) { return drizzleProtocol; }
 
206
    bool getServerType(void) { return serverType; }
247
207
    const char* getServerVersion(void) { return drizzle_con_server_version(&connection); }
248
208
};
249
209
 
264
224
 
265
225
    void writeString(std::string &str)
266
226
    {
267
 
      if (not connection->queryNoResult(str))
268
 
        throw std::exception();
 
227
      connection->queryNoResult(str);
269
228
    }
270
229
 
271
230
    void setConnection(DrizzleDumpConnection *conn) { connection= conn; }
294
253
 
295
254
    int sync()
296
255
    {
297
 
      size_t len = size_t(pptr() - pbase());
298
 
      std::string temp(pbase(), len);
299
 
 
300
 
      /* Drop newlines */
301
 
      temp.erase(std::remove(temp.begin(), temp.end(), '\n'), temp.end());
302
 
 
303
 
      if (temp.compare(0, 2, "--") == 0)
304
 
      {
305
 
        /* Drop comments */
306
 
        setp(pbase(), epptr());
307
 
      }
308
 
      if (temp.find(";") != std::string::npos)
309
 
      {
310
 
        writeString(temp);
311
 
        setp(pbase(), epptr());
312
 
      }
313
 
      return 0;
 
256
        size_t len = size_t(pptr() - pbase());
 
257
        std::string temp(pbase(), len);
 
258
 
 
259
        /* Drop newlines */
 
260
        temp.erase(std::remove(temp.begin(), temp.end(), '\n'), temp.end());
 
261
 
 
262
        if (temp.compare(0, 2, "--") == 0)
 
263
        {
 
264
          /* Drop comments */
 
265
          setp(pbase(), epptr());
 
266
        }
 
267
        if (temp.find(";") != std::string::npos)
 
268
        {
 
269
            writeString(temp);
 
270
            setp(pbase(), epptr());
 
271
        }
 
272
        return 0;
314
273
    }
315
274
};
316
275