Commit Graph

21 Commits

Author SHA1 Message Date
John Ralls
c470d006ee Remove no-longer-necessary GncSqlBackend parameter.
Where it was required only to pass down to the CT_TIMESPEC specialization
of template<GncSqlObjectType Type>GncSqlColumnTableEntryImpl::add_to_query().
2016-11-07 12:48:51 -08:00
John Ralls
ee0e61a07e Replace C API with C++ API for functions used by GncSqlDbiBackend.
Since these are now parent-class member functions they can be called
directly from dbi_be without any casting gymnastics.

Also: Move the GncSqlObjectBackend registry to its own class, a private
member of GncSqlBackend. This eliminates a static variable in gnc-backend-sql.cpp
and allows the GncSqlBackend::ObjectRegistry constructor to insert all of
the backends into the list, eliminating gnc_sql_init() and all of the
gnc_sql_init_foo_handler() functions. The cost of this is that the objects
are now created on the free store instead of the text segment.

Because the object backends are created at GncSqlBackend construction
there is now a GncSqlBookBackend in the registry and the second error
message in test_gnc_sql_commit_edit is no longer emitted; instead, the
object is properly committed.
2016-11-07 12:48:49 -08:00
John Ralls
b2a644c29d Separate SQL backend classes into their own header and source files.
And adjust includes accordingly.
2016-11-07 12:48:48 -08:00
John Ralls
4ae5abf83b Distinguish variables of various backend types by naming.
QofBackend* qof_be, GncSqlBackend* sql_be, and GncDbiBackend* dbi_be.\nRequested by Geert Janssens.
2016-11-07 12:48:47 -08:00
John Ralls
c2082bea99 Convert upgrade_table to member, remove some convenience functions.
To wit, gnc_sql_execute_select_sql, gnc_sql_execute_nonselect_sql,
gnc_sql_create_temp_table, and gnc_sql_create_select_statement.
2016-10-28 10:33:52 -07:00
John Ralls
54acef27c2 Remove a bunch of free functions already implemented as GncSqlBackend members. 2016-10-28 10:33:52 -07:00
John Ralls
6f67e2dd1a Convert GncSqlBackend and GncDbiBackend into a class hierarchy.
This is a rather complex change, because it also begins to separate the
responsibilities of the backends and GncSqlConnection.
2016-10-28 10:33:51 -07:00
John Ralls
12e763884e Use a std::unique_ptr for GncSqlStatement for better memory management. 2016-10-28 10:33:50 -07:00
John Ralls
92f2f2765e Replace the ptr-to-func GncSqlObjectBackend struct with a class hierarchy.
Can't template them because we need to iterate on the collection when loading.
2016-10-28 10:33:50 -07:00
John Ralls
6e84ccac75 Move GncSqlColumnTypeHandler functions into GncSqlColumnTableEntry.
Unfortunately a rather massive change. Gets rid of GncSqlColumnTypeHandler
and its hideous run-time registry by making the handler functions members
of GncSqlColumnTableEntry. GncSqlColumnTableEntry becomes an abstract super-
class with a templatized subclass GncSqlColumnTableEntryImpl whose template
parameter is the GncSqlObjectType that's also the GncSqlColumnTableEntryImpl's
m_col_type member. That member is a candidate for future removal as it's not
necessary. An explicit specialization is provided for each GncSqlObjectType and
that's a candidate for future code-shrinkage as there's still a fair amount
of duplication in spite of adding several helper template functions to absorb
most of the meat. The abstract GncSqlColumnTableEntry class is motivated by
the need to have an iterable container which in turn requires runtime
polymorphism. This can probably be replaced with a variadic-template
pseudo-container.

The two major benefits of this change are that it gets rid of one more set
of macro functions and provides vtable dispatch that has only one level
of indirection instead of the cumbersome string-hash-table-lookup to
find the handler followed by invoking the handler's function.

The two header files are removed because they exposed only the initialization
function which in turn only registered the respective GncSqlColumnTypeHandler.
2016-10-28 10:33:50 -07:00
John Ralls
a716636e00 Convert GncSqlStatement to a virtual class.
Implemented by GncDbiSqlStatement. Use class function semantics.
2016-10-28 10:33:49 -07:00
John Ralls
0d548da223 Create a new set_parameter template function to reduce repetition. 2016-10-28 10:33:49 -07:00
John Ralls
a0ae59a96a Reimplement row retrieval as an iterator on GncSqlResults.
Replaces a much-copied and longish while loop with a simple range-for loop
that's guaranteed not to iterate if the result-set is empty.
2016-10-28 10:33:49 -07:00
John Ralls
8078c41a35 Make GncSqlRow a class and replace GValues with typed transfer functions. 2016-10-28 10:33:49 -07:00
John Ralls
7d4ca43fd0 Combine add_colname_to_list and add_gvalue_to_slist into single function add_value_to_vec.
The two lists were always used together so replace them with a single
vector of std::pair<std::string, std::string>; this also gets rid of the
intermediate GValue which was used to convert the returned value to a string.
operator<<() can do that for us more transparently.

Also template most of the add_value_to_vec functions.
2016-10-28 10:33:49 -07:00
John Ralls
96a8a7b99f Make GncSqlColumnTableEntry arrays into std::vectors.
Allows use of range for.
2016-10-28 10:33:48 -07:00
John Ralls
049b905d86 Replace qof_object_foo_backend with c++ native containers.
Since C++ provides find and for_each on native containers there's no need
for a hand-rolled version in libqof.
2016-10-28 10:33:48 -07:00
lmat
293a286693 Add C++ header for guid.cpp and tests. 2016-06-09 15:07:54 -07:00
John Ralls
34e34334c7 Backends: astyle -xd -k1 -m0 -M60 -xL -xC79 -OHpUcZns4 --brackets=break
More extensive than usual, but these files had a lot of format issues.
2016-05-23 13:12:24 -07:00
John Ralls
a2863ab370 Remove old static analysis markup from backend. 2016-05-23 13:12:23 -07:00
John Ralls
0178492663 Convert SQL & DBI backends to compile as C++. 2015-11-29 17:23:43 -08:00