97
static bool isEndStatement(const message::Statement &statement)
99
switch (statement.type())
101
case (message::Statement::INSERT):
103
const message::InsertData &data= statement.insert_data();
104
if (not data.end_segment())
108
case (message::Statement::UPDATE):
110
const message::UpdateData &data= statement.update_data();
111
if (not data.end_segment())
115
case (message::Statement::DELETE):
117
const message::DeleteData &data= statement.delete_data();
118
if (not data.end_segment())
97
128
static void printTransaction(const message::Transaction &transaction)
130
static uint64_t last_trx_id= 0;
131
bool should_commit= true;
99
132
const message::TransactionContext trx= transaction.transaction_context();
101
134
size_t num_statements= transaction.statement_size();
104
cout << "START TRANSACTION;" << endl;
138
* One way to determine when a new transaction begins is when the
139
* transaction id changes. We check that here.
141
if (trx.transaction_id() != last_trx_id)
142
cout << "START TRANSACTION;" << endl;
144
last_trx_id= trx.transaction_id();
105
146
for (x= 0; x < num_statements; ++x)
107
148
const message::Statement &statement= transaction.statement(x);
151
should_commit= isEndStatement(statement);
108
153
printStatement(statement);
110
cout << "COMMIT;" << endl;
157
* If ALL Statements are end segments, we can commit this Transaction.
158
* We can also check to see if the transaction_id changed, but this
159
* wouldn't work for the last Transaction in the transaction log since
160
* we don't have another Transaction to compare to. Checking for all
161
* end segments (like we do above) covers this case.
164
cout << "COMMIT;" << endl;
113
167
int main(int argc, char* argv[])