1
#include <drizzled/global.h>
9
#include <drizzled/serialize/replication_event.pb.h>
12
using namespace drizzle;
15
Example reader application for master.info data.
18
void printRecord(const ::drizzle::EventList *list)
22
for (e_size= 0; e_size < list->event_size(); e_size++)
24
const Event event= list->event(e_size);
27
cout << endl << "##########################################################################################" << endl << endl;
38
cout << "INSERT INTO " << event.table() << " (";
40
for (x= 0; x < event.field_names_size() ; x++)
45
cout << event.field_names(x);
48
cout << ") VALUES " << endl;
50
for (x= 0; x < event.values_size(); x++)
53
Event_Value values= event.values(x);
59
for (y= 0; y < values.value_size() ; y++)
64
cout << "\"" << values.value(y) << "\"";
75
Event_Value values= event.values(0);
77
cout << "DELETE FROM " << event.table() << " WHERE " << event.primary_key() << " IN (";
79
for (x= 0; x < values.value_size() ; x++)
84
cout << "\"" << values.value(x) << "\"";
94
for (count= 0; count < event.values_size() ; count++)
97
Event_Value values= event.values(count);
99
cout << "UPDATE " << event.table() << " SET ";
101
for (x= 1; x < values.value_size() ; x++)
106
cout << event.field_names(x - 1) << " = \"" << values.value(x) << "\"";
109
cout << " WHERE " << event.primary_key() << " = " << values.value(0) << endl;
115
cout << "COMMIT" << endl;
121
cout << "Original SQL: " << event.sql() << endl;
123
cout << "AUTOCOMMIT: " << event.autocommit() << endl;
124
cout << "Server id: " << event.server_id() << endl;
125
cout << "Query id: " << event.query_id() << endl;
126
cout << "Transaction id: " << event.transaction_id() << endl;
127
cout << "Schema: " << event.schema() << endl;
128
if (event.type() != Event::DDL)
129
cout << "Table Name: " << event.table() << endl;
133
int main(int argc, char* argv[])
135
GOOGLE_PROTOBUF_VERIFY_VERSION;
140
cerr << "Usage: " << argv[0] << " replication event log " << endl;
146
if ((file= open(argv[1], O_RDONLY)) == -1)
148
cerr << "Can not open file: " << argv[0] << endl;
158
if (read(file, &length, sizeof(uint64_t)) != sizeof(uint64_t))
161
if (length > SIZE_MAX)
163
cerr << "Attempted to read record bigger than SIZE_MAX" << endl;
166
temp_buffer= (char *)realloc(buffer, (size_t)length);
167
if (temp_buffer == NULL)
169
cerr << "Memory allocation failure trying to " << length << "." << endl;
174
/* Read the record */
175
if (read(file, buffer, (off_t)length) != (off_t)length)
177
cerr << "Could not read entire record." << endl;
180
list.ParseFromArray(buffer, length);
182
/* Print the record */