static void load_all_books( GncSqlBackend* be ) { GncSqlStatement* stmt; GncSqlResult* result; g_return_if_fail( be != NULL ); stmt = gnc_sql_create_select_statement( be, BOOK_TABLE ); if ( stmt != NULL ) { result = gnc_sql_execute_select_statement( be, stmt ); gnc_sql_statement_dispose( stmt ); if ( result != NULL ) { GncSqlRow* row = gnc_sql_result_get_first_row( result ); // If there are no rows, try committing the book if ( row == NULL ) { (void)gnc_sql_save_book( be, QOF_INSTANCE(be->book) ); } else { // Otherwise, load the 1st book. load_single_book( be, row ); } gnc_sql_result_dispose( result ); } } }
void GncSqlBookBackend::load_all (GncSqlBackend* sql_be) { g_return_if_fail (sql_be != NULL); std::stringstream sql; sql << "SELECT * FROM " << BOOK_TABLE; auto stmt = sql_be->create_statement_from_sql(sql.str()); if (stmt != nullptr) { auto result = sql_be->execute_select_statement(stmt); auto row = result->begin(); /* If there are no rows, try committing the book; unset * loading so that it will actually get saved. */ if (row == result->end()) { sql_be->set_loading(false); commit (sql_be, QOF_INSTANCE (sql_be->book())); sql_be->set_loading(true); } else { // Otherwise, load the 1st book. load_single_book (sql_be, *row); } } }