~posulliv/drizzle/memcached_applier

« back to all changes in this revision

Viewing changes to drizzled/message/command_reader.cc

  • Committer: Jay Pipes
  • Date: 2009-08-03 14:23:22 UTC
  • mfrom: (1039.2.68 staging)
  • mto: This revision was merged to the branch mainline in revision 1078.
  • Revision ID: jpipes@serialcoder-20090803142322-1g67h7su9mocg9ig
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include "drizzled/korr.h"
12
12
 
13
13
using namespace std;
14
 
using namespace drizzled::message;
 
14
using namespace drizzled;
15
15
 
16
16
/**
17
17
 * @file Example application for reading change records (Command messages)
22
22
 * the log written by that plugin.
23
23
 */
24
24
 
25
 
static void printInsert(const drizzled::message::Command &container, const drizzled::message::InsertRecord &record)
 
25
static void printInsert(const message::Command &container,
 
26
                        const message::InsertRecord &record)
26
27
{
27
28
 
28
29
  cout << "INSERT INTO `" << container.schema() << "`.`" << container.table() << "` (";
39
40
    if (x != 0)
40
41
      cout << ", ";
41
42
 
42
 
    const Table::Field f= record.insert_field(x);
 
43
    const message::Table::Field f= record.insert_field(x);
43
44
 
44
45
    cout << "`" << f.name() << "`";
45
46
  }
77
78
  cout << ";";
78
79
}
79
80
 
80
 
static void printDeleteWithPK(const drizzled::message::Command &container, const drizzled::message::DeleteRecord &record)
 
81
static void printDeleteWithPK(const message::Command &container,
 
82
                              const message::DeleteRecord &record)
81
83
{
82
84
  cout << "DELETE FROM `" << container.schema() << "`.`" << container.table() << "`";
83
85
  
98
100
    if (x != 0)
99
101
      cout << " AND "; /* Always AND condition with a multi-column PK */
100
102
 
101
 
    const Table::Field f= record.where_field(x);
 
103
    const message::Table::Field f= record.where_field(x);
102
104
 
103
105
    /* Always equality conditions */
104
106
    cout << "`" << f.name() << "` = \"" << record.where_value(x) << "\"";
107
109
  cout << ";";
108
110
}
109
111
 
110
 
static void printUpdateWithPK(const drizzled::message::Command &container, const drizzled::message::UpdateRecord &record)
 
112
static void printUpdateWithPK(const message::Command &container,
 
113
                              const message::UpdateRecord &record)
111
114
{
112
115
  int32_t num_update_fields= record.update_field_size();
113
116
  int32_t x;
120
123
 
121
124
  for (x= 0;x < num_update_fields; x++)
122
125
  {
123
 
    Table::Field f= record.update_field(x);
 
126
    message::Table::Field f= record.update_field(x);
124
127
    
125
128
    if (x != 0)
126
129
      cout << ", ";
141
144
    if (x != 0)
142
145
      cout << " AND "; /* Always AND condition with a multi-column PK */
143
146
 
144
 
    const Table::Field f= record.where_field(x);
 
147
    const message::Table::Field f= record.where_field(x);
145
148
 
146
149
    /* Always equality conditions */
147
150
    cout << "`" << f.name() << "` = \"" << record.where_value(x) << "\"";
149
152
  cout << ";";
150
153
}
151
154
 
152
 
static void printCommand(const drizzled::message::Command &command)
 
155
static void printCommand(const message::Command &command)
153
156
{
154
157
  cout << "/* Timestamp: " << command.timestamp() << " */"<< endl;
155
158
 
156
 
  drizzled::message::TransactionContext trx= command.transaction_context();
 
159
  message::TransactionContext trx= command.transaction_context();
157
160
 
158
161
  cout << "/* SID: " << trx.server_id() << " XID: " << trx.transaction_id() << " */ ";
159
162
 
160
163
  switch (command.type())
161
164
  {
162
 
    case Command::START_TRANSACTION:
 
165
    case message::Command::START_TRANSACTION:
163
166
      cout << "START TRANSACTION;";
164
167
      break;
165
 
    case Command::COMMIT:
 
168
    case message::Command::COMMIT:
166
169
      cout << "COMMIT;";
167
170
      break;
168
 
    case Command::ROLLBACK:
 
171
    case message::Command::ROLLBACK:
169
172
      cout << "ROLLBACK;";
170
173
      break;
171
 
    case Command::INSERT:
 
174
    case message::Command::INSERT:
172
175
    {
173
176
      printInsert(command, command.insert_record());
174
177
      break;
175
178
    }
176
 
    case Command::DELETE:
 
179
    case message::Command::DELETE:
177
180
    {
178
181
      printDeleteWithPK(command, command.delete_record());
179
182
      break;
180
183
    }
181
 
    case Command::UPDATE:
 
184
    case message::Command::UPDATE:
182
185
    {
183
186
      printUpdateWithPK(command, command.update_record());
184
187
      break;
185
188
    }
186
 
    case Command::RAW_SQL:
 
189
    case message::Command::RAW_SQL:
187
190
    {
188
191
      std::string sql= command.sql();
189
192
      /* Replace \n with spaces */
211
214
    return -1;
212
215
  }
213
216
 
214
 
  Command command;
 
217
  message::Command command;
215
218
 
216
219
  if ((file= open(argv[1], O_RDONLY)) == -1)
217
220
  {