~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/transaction_reader.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-08 19:03:09 UTC
  • mfrom: (1750 staging)
  • mto: (1750.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1751.
  • Revision ID: andrew@linuxjedi.co.uk-20100908190309-mya1nu7xvo1fpvk8
Merge trunk into branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
  }
96
96
}
97
97
 
 
98
static bool isEndStatement(const message::Statement &statement)
 
99
{
 
100
  switch (statement.type())
 
101
  {
 
102
    case (message::Statement::INSERT):
 
103
    {
 
104
      const message::InsertData &data= statement.insert_data();
 
105
      if (not data.end_segment())
 
106
        return false;
 
107
      break;
 
108
    }
 
109
    case (message::Statement::UPDATE):
 
110
    {
 
111
      const message::UpdateData &data= statement.update_data();
 
112
      if (not data.end_segment())
 
113
        return false;
 
114
      break;
 
115
    }
 
116
    case (message::Statement::DELETE):
 
117
    {
 
118
      const message::DeleteData &data= statement.delete_data();
 
119
      if (not data.end_segment())
 
120
        return false;
 
121
      break;
 
122
    }
 
123
    default:
 
124
      return true;
 
125
  }
 
126
  return true;
 
127
}
 
128
 
98
129
static void printTransaction(const message::Transaction &transaction)
99
130
{
 
131
  static uint64_t last_trx_id= 0;
 
132
  bool should_commit= true;
100
133
  const message::TransactionContext trx= transaction.transaction_context();
101
134
 
102
135
  size_t num_statements= transaction.statement_size();
103
136
  size_t x;
104
137
 
105
 
  cout << "START TRANSACTION;" << endl;
 
138
  /*
 
139
   * One way to determine when a new transaction begins is when the
 
140
   * transaction id changes. We check that here.
 
141
   */
 
142
  if (trx.transaction_id() != last_trx_id)
 
143
    cout << "START TRANSACTION;" << endl;
 
144
 
 
145
  last_trx_id= trx.transaction_id();
 
146
 
106
147
  for (x= 0; x < num_statements; ++x)
107
148
  {
108
149
    const message::Statement &statement= transaction.statement(x);
 
150
 
 
151
    if (should_commit)
 
152
      should_commit= isEndStatement(statement);
 
153
 
109
154
    printStatement(statement);
110
155
  }
111
 
  cout << "COMMIT;" << endl;
 
156
 
 
157
  /*
 
158
   * If ALL Statements are end segments, we can commit this Transaction.
 
159
   * We can also check to see if the transaction_id changed, but this
 
160
   * wouldn't work for the last Transaction in the transaction log since
 
161
   * we don't have another Transaction to compare to. Checking for all
 
162
   * end segments (like we do above) covers this case.
 
163
   */
 
164
  if (should_commit)
 
165
    cout << "COMMIT;" << endl;
112
166
}
113
167
 
114
168
int main(int argc, char* argv[])