1833
* Template for removing Statement records of different types.
1835
* The code for removing records from different Statement message types
1836
* is identical except for the class types that are embedded within the
1839
* There are 3 scenarios we need to look for:
1840
* - We've been asked to remove more records than exist in the Statement
1841
* - We've been asked to remove less records than exist in the Statement
1842
* - We've been asked to remove ALL records that exist in the Statement
1844
* If we are removing ALL records, then effectively we would be left with
1845
* an empty Statement message, so we should just remove it and clean up
1846
* message pointers in the Session object.
1848
template <class DataType, class RecordType>
1849
static bool removeStatementRecordsWithType(Session *session,
1853
uint32_t num_avail_recs= static_cast<uint32_t>(data->record_size());
1855
/* If there aren't enough records to remove 'count' of them, error. */
1856
if (num_avail_recs < count)
1860
* If we are removing all of the data records, we'll just remove this
1861
* entire Statement message.
1863
if (num_avail_recs == count)
1865
message::Transaction *transaction= session->getTransactionMessage();
1866
protobuf::RepeatedPtrField<message::Statement> *statements= transaction->mutable_statement();
1867
statements->RemoveLast();
1870
* Now need to set the Session Statement pointer to either the previous
1871
* Statement, or NULL if there isn't one.
1873
if (statements->size() == 0)
1875
session->setStatementMessage(NULL);
1880
* There isn't a great way to get a pointer to the previous Statement
1881
* message using the RepeatedPtrField object, so we'll just get to it
1882
* using the Transaction message.
1884
int last_stmt_idx= transaction->statement_size() - 1;
1885
session->setStatementMessage(transaction->mutable_statement(last_stmt_idx));
1888
/* We only need to remove 'count' records */
1889
else if (num_avail_recs > count)
1891
protobuf::RepeatedPtrField<RecordType> *records= data->mutable_record();
1893
records->RemoveLast();
1900
bool TransactionServices::removeStatementRecords(Session *session,
1903
ReplicationServices &replication_services= ReplicationServices::singleton();
1904
if (! replication_services.isActive())
1907
/* Get the most current Statement */
1908
message::Statement *statement= session->getStatementMessage();
1910
/* Make sure we have work to do */
1911
if (statement == NULL)
1916
switch (statement->type())
1918
case message::Statement::INSERT:
1920
message::InsertData *data= statement->mutable_insert_data();
1921
retval= removeStatementRecordsWithType<message::InsertData, message::InsertRecord>(session, data, count);
1925
case message::Statement::UPDATE:
1927
message::UpdateData *data= statement->mutable_update_data();
1928
retval= removeStatementRecordsWithType<message::UpdateData, message::UpdateRecord>(session, data, count);
1932
case message::Statement::DELETE: /* not sure if this one is possible... */
1934
message::DeleteData *data= statement->mutable_delete_data();
1935
retval= removeStatementRecordsWithType<message::DeleteData, message::DeleteRecord>(session, data, count);
1829
1948
void TransactionServices::createTable(Session *in_session,
1830
1949
const message::Table &table)