Bug #638543: Split the qof_book_get_counter function.

Patch by Matthijs Kooijman:

The qof_book_get_counter function now only gets the current counter
value. The new qof_book_get_and_increment_counter function now does the
incrementing.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20053 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-01-10 21:38:54 +00:00
parent d565bdb982
commit 670b3b63da
8 changed files with 57 additions and 17 deletions

View File

@ -951,5 +951,5 @@ gboolean gncCustomerRegister (void)
gint64 gncCustomerNextID (QofBook *book)
{
return qof_book_get_counter (book, _GNC_MOD_NAME);
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
}

View File

@ -742,5 +742,5 @@ gboolean gncEmployeeRegister (void)
gint64 gncEmployeeNextID (QofBook *book)
{
return qof_book_get_counter (book, _GNC_MOD_NAME);
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
}

View File

@ -2131,16 +2131,16 @@ gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner)
switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
{
case GNC_OWNER_CUSTOMER:
nextID = qof_book_get_counter (book, "gncInvoice");
nextID = qof_book_increment_and_get_counter (book, "gncInvoice");
break;
case GNC_OWNER_VENDOR:
nextID = qof_book_get_counter (book, "gncBill");
nextID = qof_book_increment_and_get_counter (book, "gncBill");
break;
case GNC_OWNER_EMPLOYEE:
nextID = qof_book_get_counter (book, "gncExpVoucher");
nextID = qof_book_increment_and_get_counter (book, "gncExpVoucher");
break;
default:
nextID = qof_book_get_counter (book, _GNC_MOD_NAME);
nextID = qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
break;
}
return nextID;

View File

@ -585,5 +585,5 @@ gboolean gncJobRegister (void)
gint64 gncJobNextID (QofBook *book)
{
return qof_book_get_counter (book, _GNC_MOD_NAME);
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
}

View File

@ -606,5 +606,5 @@ gboolean gncOrderRegister (void)
gint64 gncOrderNextID (QofBook *book)
{
return qof_book_get_counter (book, _GNC_MOD_NAME);
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
}

View File

@ -861,5 +861,5 @@ gboolean gncVendorRegister (void)
gint64 gncVendorNextID (QofBook *book)
{
return qof_book_get_counter (book, _GNC_MOD_NAME);
return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
}

View File

@ -392,10 +392,8 @@ void qof_book_set_version (QofBook *book, gint32 version)
gint64
qof_book_get_counter (QofBook *book, const char *counter_name)
{
QofBackend *be;
KvpFrame *kvp;
KvpValue *value;
gint64 counter;
if (!book)
{
@ -422,17 +420,54 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
if (value)
{
/* found it */
counter = kvp_value_get_gint64 (value);
return kvp_value_get_gint64 (value);
}
else
{
/* New counter */
counter = 0;
return 0;
}
}
gint64
qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
{
QofBackend *be;
KvpFrame *kvp;
KvpValue *value;
gint64 counter;
if (!book)
{
PWARN ("No book!!!");
return -1;
}
/* Counter is now valid; increment it */
if (!counter_name || *counter_name == '\0')
{
PWARN ("Invalid counter name.");
return -1;
}
/* Get the current counter value from the KVP in the book. */
counter = qof_book_get_counter(book, counter_name);
/* Check if an error occured */
if (counter < 0)
return -1;
/* Increment the counter */
counter++;
/* Get the KVP from the current book */
kvp = qof_book_get_slots (book);
if (!kvp)
{
PWARN ("Book has no KVP_Frame");
return -1;
}
/* Save off the new counter */
qof_book_begin_edit(book);
value = kvp_value_new_gint64 (counter);
@ -441,7 +476,6 @@ qof_book_get_counter (QofBook *book, const char *counter_name)
qof_book_mark_dirty(book);
qof_book_commit_edit(book);
/* and return the value */
return counter;
}

View File

@ -278,11 +278,17 @@ void qof_book_kvp_changed (QofBook *book);
*/
gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
/** This will 'get and increment' the named counter for this book.
* The return value is -1 on error or the incremented counter.
/** This will get the named counter for this book. The return value is
* -1 on error or the current value of the counter.
*/
gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
/** This will increment the named counter for this book and return it.
* The return value is -1 on error or the (new) value of the
* counter.
*/
gint64 qof_book_increment_and_get_counter (QofBook *book, const char *counter_name);
const char* qof_book_get_string_option(const QofBook* book, const char* opt_name);
void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val);