8
#include <drizzled/serialize/replication_event.pb.h>
12
Example reader application for master.info data.
15
void printRecord(const drizzle::EventList *list)
17
using namespace drizzle;
20
for (x= 0; x < list->event_size(); x++)
22
const drizzle::Event event= list->event(x);
25
cout << endl << "##########################################################################################" << endl << endl;
36
cout << "INSERT INTO " << event.table() << " (";
38
for (x= 0; x < event.field_names_size() ; x++)
43
cout << event.field_names(x);
46
cout << ") VALUES " << endl;
48
for (x= 0; x < event.values_size(); x++)
51
Event_Value values= event.values(x);
57
for (y= 0; y < values.value_size() ; y++)
62
cout << "\"" << values.value(y) << "\"";
73
Event_Value values= event.values(0);
75
cout << "DELETE FROM " << event.table() << " WHERE " << event.primary_key() << " IN (";
77
for (x= 0; x < values.value_size() ; x++)
82
cout << "\"" << values.value(x) << "\"";
92
for (count= 0; count < event.values_size() ; count++)
95
Event_Value values= event.values(count);
97
cout << "UPDATE " << event.table() << " SET ";
99
for (x= 1; x < values.value_size() ; x++)
104
cout << event.field_names(x - 1) << " = \"" << values.value(x) << "\"";
107
cout << " WHERE " << event.primary_key() << " = " << values.value(0) << endl;
113
cout << "COMMIT" << endl;
119
cout << "Original SQL: " << event.sql() << endl;
121
cout << "AUTOCOMMIT: " << event.autocommit() << endl;
122
cout << "Server id: " << event.server_id() << endl;
123
cout << "Query id: " << event.query_id() << endl;
124
cout << "Transaction id: " << event.transaction_id() << endl;
125
cout << "Schema: " << event.schema() << endl;
126
if (event.type() != Event::DDL)
127
cout << "Table Name: " << event.table() << endl;
131
int main(int argc, char* argv[])
133
GOOGLE_PROTOBUF_VERIFY_VERSION;
138
cerr << "Usage: " << argv[0] << " replication event log " << endl;
142
drizzle::EventList list;
144
if ((file= open(argv[1], O_RDONLY)) == -1)
146
cerr << "Can not open file: " << argv[0] << endl;
156
if (read(file, &length, sizeof(uint64_t)) != sizeof(uint64_t))
159
temp_buffer= (char *)realloc(buffer, length);
160
if (temp_buffer == NULL)
162
cerr << "Memory allocation failure trying to " << length << "." << endl;
167
/* Read the record */
168
if (read(file, buffer, length) != length)
170
cerr << "Could not read entire record." << endl;
173
list.ParseFromArray(buffer, length);
175
/* Print the record */