Commit Graph

17510 Commits

Author SHA1 Message Date
John Ralls
451f3ffe4d DBI: Convert all of the gchar to char, remove a few gratuitous g_funcs.
Except where we're explicitly using other GLib functions.
2016-10-28 10:33:54 -07:00
John Ralls
5065bce45c Combine Postgres and MySql gnc_dbi_session_begin into a single template. 2016-10-28 10:33:53 -07:00
John Ralls
c141711425 Move creation of the provider to GncDbiSqlConnection's constructor.
Making GncDbiProviderImpl private to GncDbiSqlConnection.
2016-10-28 10:33:53 -07:00
John Ralls
5d38c7a729 Make conn_setup and the error handler functions templates on DbType. 2016-10-28 10:33:53 -07:00
John Ralls
314a5e10c2 Make gnc_lock_database a GncDbiSqlConnection member function.
Called from the constructor, so effective RAII with unlock_database called
from the destructor.
2016-10-28 10:33:53 -07:00
John Ralls
00e0a6e8b6 Change parameter of save_may_clobber_data from QofBackend to dbi_conn.
It actually needs the dbi_conn and that's known to its caller. Plus,
the backend's conn parameter hasn't actually been set so it was somewhat
coincidental that it worked.
2016-10-28 10:33:53 -07:00
John Ralls
fc47b63265 Templatize the session_begin functions and new_backend().
Thus removing the need for specializations of
QofDbiBackendProvider::create_backend().
2016-10-28 10:33:53 -07:00
John Ralls
61beed5686 Make sure that all of the GncDbiProviderImpl functions are in the right file.
Also merge create_table_ddl back into the only function that used it.
2016-10-28 10:33:53 -07:00
John Ralls
31c73a141e Extract functions conn_setup and create_database. 2016-10-28 10:33:53 -07:00
John Ralls
37d4257336 Extract-function conn_test_dbi_library.
Renaming the previous so-named function dbi_library_test.
2016-10-28 10:33:53 -07:00
John Ralls
5074bd590f Don't leak the quoted string returned from dbi_conn_quote_string_copy. 2016-10-28 10:33:53 -07:00
John Ralls
b38be9fe20 Get rid of gotos.
By replacing all of the char*s on the heap to std::strings, mostly in
a new UriString struct. Also lets us simplify the call to
set_standard_connection_options.
2016-10-28 10:33:53 -07:00
John Ralls
d8556ca7b5 Reformat adjust_sql_options a bit to reduce nesting. 2016-10-28 10:33:52 -07:00
John Ralls
431b704c92 Abstract setting database string-value options to function set_options. 2016-10-28 10:33:52 -07:00
John Ralls
ccc1cc49ab Separate DBI classes into their own files. 2016-10-28 10:33:52 -07: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
a303ae688a Remove some GList and GSList uses from tests. 2016-10-28 10:33:52 -07:00
John Ralls
4b62deee42 Rework gnc_sql_append_guid_list_to_sql to eliminate GString and GList.
Which in turn forced rework of its users since the GString and GList were
passed-in parameters.
2016-10-28 10:33:52 -07:00
John Ralls
cb464da599 Replace GHashTable in GncSqlConnection with a std::vector. 2016-10-28 10:33:52 -07:00
John Ralls
885470b3e7 Replace std::vector<std::string> with StrVec. 2016-10-28 10:33:52 -07:00
John Ralls
d1fd223f9f Make conn_table_operation and add_columns_ddl members of GncDbiSqlConnection.
So they don't need to be friends.
2016-10-28 10:33:51 -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
d106346316 Minimally document GncDbiResult. 2016-10-28 10:33:51 -07:00
John Ralls
97b6e3a6c6 Pass ownership of the dbi_conn to GncDbiSqlConnection. 2016-10-28 10:33:51 -07:00
John Ralls
e0d5cc5b0b New function GncSqlConnection::dberror().
GncDbiSqlResult::dberror() just calls it instead of retrieving the dbi_conn
to call dbi_conn_error() itself.
2016-10-28 10:33:51 -07:00
John Ralls
583c951adc Use the right include delineators, it's not in the current source dir. 2016-10-28 10:33:51 -07:00
John Ralls
5823bf0d9a Move GncDbiSqlConnection into a separate file.
The declaration stays in gnc-backend-dbi.h because the dependencies are
still a little too tangled to be able to separate it.
2016-10-28 10:33:51 -07:00
John Ralls
ccbfb69cf1 Delete unused or duplicated member variables from GncSqlBackend & GncDbiBackend. 2016-10-28 10:33:51 -07:00
John Ralls
c0a193c593 Remove unused/never implemented QofBackend functions.
Note that the QofQuery functions that sort-of used them are ifdefed out
instead of deleted to serve as place-holders since we'll be bringing
back backend querying later.
2016-10-28 10:33:51 -07:00
John Ralls
eed4a012c3 Remove no-longer-needed gnc_table_slist_free. 2016-10-28 10:33:51 -07:00
John Ralls
1f52839271 Templatize QofDbiBackendProvider. 2016-10-28 10:33:50 -07:00
John Ralls
3894a2e8b7 Convert struct provider_functions_t into virtual class GncDbiProvider.
Implementation templated as template <DbType> GncDbiProviderImpl.
Converted GSLists to std::vectors and GStrings to std::strings.
2016-10-28 10:33:50 -07:00
John Ralls
faf59964e4 Rename gnc-backend-dbi-priv.h to gnc-backend-dbi.hpp.
Also remove "#ifdef __cplusplus" from both gnc-backend-dbi.hpp and
gnc-backend-dbi.h, these files are always C++.
2016-10-28 10:33:50 -07:00
John Ralls
7fe404808a Delete some no-longer (or in some cases never) used functions. 2016-10-28 10:33:50 -07:00
John Ralls
cfa3ab24f6 Convert GncSqlConnection to a C++ class. 2016-10-28 10:33:50 -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
64c1fda6ec gnc-backend-dbi.cpp: NULL -> nullptr. 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
e20c17b642 Change the object type string defines to an enum.
Because doing unnecessary string compares is dumb.
2016-10-28 10:33:49 -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
576bc8ae7d Don't override an already-set QofBackend error. 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
2f0b5ec8fe Remove tabs from gnc-backend-sql*. 2016-10-28 10:33:49 -07:00
John Ralls
7e3ba421d7 Fix potential dereference error.
Thanks Geert Janssens.
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