gnucash/libgnucash/backend/sql/gnc-sql-object-backend.cpp
Richard Cohen 1cec0cb3f3 Use internal extern "C" { ... } for C++
- removes warnings compiling swig engine
...
[ 10%] Generating swig-engine.cpp
.../libgnucash/engine/engine-helpers.h:31: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/gnc-date.h:83: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/qofquery.h:90: Warning 302: Identifier 'QofQuery' redefined (ignored),
.../libgnucash/engine/gnc-option.hpp:55: Warning 302: previous definition of 'QofQuery'.
.../libgnucash/engine/gnc-commodity.h:56: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/gncBusiness.h:40: Warning 313: Unrecognized extern type "C++".
.../libgnucash/engine/gncEntry.h:37: Warning 313: Unrecognized extern type "C++".
2023-01-23 18:40:01 +00:00

95 lines
3.5 KiB
C++

/***********************************************************************\
* gnc-sql-object-backend.hpp: Encapsulate per-class table schema. *
* *
* Copyright 2016 John Ralls <jralls@ceridwen.us> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\***********************************************************************/
#include <config.h>
#include "gnc-sql-object-backend.hpp"
#include "gnc-sql-backend.hpp"
#include "gnc-sql-column-table-entry.hpp"
#include "gnc-slots-sql.h"
static QofLogModule log_module = G_LOG_DOMAIN;
bool
GncSqlObjectBackend::commit (GncSqlBackend* sql_be, QofInstance* inst)
{
const GncGUID* guid;
gboolean is_infant;
E_DB_OPERATION op;
gboolean is_ok;
is_infant = qof_instance_get_infant (inst);
if (qof_instance_get_destroying (inst))
{
op = OP_DB_DELETE;
}
else if (sql_be->pristine() || is_infant)
{
op = OP_DB_INSERT;
}
else
{
op = OP_DB_UPDATE;
}
is_ok = sql_be->do_db_operation(op, m_table_name.c_str(),
m_type_name.c_str(), inst, m_col_table);
if (is_ok)
{
// Now, commit any slots
guid = qof_instance_get_guid (inst);
if (!qof_instance_get_destroying (inst))
{
is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
}
else
{
is_ok = gnc_sql_slots_delete (sql_be, guid);
}
}
return is_ok;
}
void
GncSqlObjectBackend::create_tables (GncSqlBackend* sql_be)
{
g_return_if_fail (sql_be != nullptr);
int version = sql_be->get_table_version (m_table_name);
if (version == 0) //No tables, otherwise version will sql_be >= 1.
{
sql_be->create_table(m_table_name, m_col_table);
sql_be->set_table_version(m_table_name, m_version);
}
else if (version != m_version)
PERR("Version mismatch in table %s, expecting %d but backend is %d."
"Table creation aborted.", m_table_name.c_str(), m_version, version);
}
bool
GncSqlObjectBackend::instance_in_db(const GncSqlBackend* sql_be,
QofInstance* inst) const noexcept
{
return sql_be->object_in_db(m_table_name.c_str(), m_type_name.c_str(),
inst, m_col_table);
}