
WaitNextCommit
WaitNextCommit allow for a listening transaction to read a transaction directly from the cyclical log file.unsigned __int64 WaitNextCommit ( unsigned int* logNumber, __int64* position, unsigned int* transactionID, __int64* length, void* buffer = NULL, unsigned int milliseconds = 15000 /*or INFINITE*/ );
Parameters
| logNumber | a value between 0-65,535 that tells the system which cyclical log file this tranaction came from. If this value is -1, then this method returns the last available transaction in the log file |
| position | for cross checking to make sure transaction is correctly copied. |
| transactionID | the Transaction ID for the retrieved transaction. This has internal use and should not be changed. |
| length | the length on the transaction buffer. |
| buffer | a buffer for the next transaction to be read into. If this value is NULL, then this function only sets the length, transactionID and logNumber parameters |
| milliseconds | The maximum length of wait time before the method will return |
Return Values
If the method succeeds, the return value is zero else see error codes for more details.Remarks
- This methods is read only and does not require the database to have begun a tranaction.
- This methods only works if cyclical logging is enabled. See GetDatabaseParameter for more information.
Example Use
- C++
#include "ODBPP.h"
int wmain(int argc, wchar_t* argv[])
{
CODBPP database, backup;
unsigned int logFile, transactionID;
__int64 length = 0, size, position;
BYTE *buffer = NULL;
const char16_t *message;
//production database is read only
if((error = database.OpenDatabase(u"YourDatabase")) == NO_ERROR){
if((error = backup.OpenDatabase(u"YourBackupDatabase")) == NO_ERROR){
//lock backup database from other transactions
if((error = backup.BeginTransaction(CODBPP::EXCLUSIVE)) == NO_ERROR{
//get last transaction from backup log file
if ((error = backup.WaitNextCommit(&logFile, &position, &transactionID, &size)) == NO_ERROR) {
while (error == NO_ERROR) {
//gets next after the the inputted commit
if ((error = database.WaitNextCommit(&logFile, &position, &transactionID, &size)) == NO_ERROR) {
if (length < size || (size << 4) < length) {
if(buffer != NULL) delete[] buffer;
buffer = new BYTE[(length = (size + 0x3f)&~0x3f)];
}
size = length;//resets length to maximum size
//reads the next commit
if ((error = database.WaitNextCommit(&logFile, &position, &transactionID, &size, buffer)) == NO_ERROR)
//append the previous transaction to the backup database
error = backup.AppendTransaction(logFile, position, transactionID, size, buffer);
}
else if (ERROR_MASK(error) == WAIT_TIMEOUT) error = NO_ERROR;
}
}
}
backup.EndTransaction();
}
backup.CloseDatabase();
}
if(error && database.GetErrorMessage(&message) == NO_ERROR)
MessageBox(message);
database.CloseDatabase();
return NO_ERROR;
}Since
Version 4.5.1
Also See
AppendTransactionListen All
Comments (0)

