From 9c4635e3930f6026080cf18ea7ca92133733c944 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Thu, 23 Nov 2017 11:41:09 -0800 Subject: [PATCH] Bug 784623 - GNUCash does not work with sql backend. Wherin the problem is that MySQL's TIMESTAMP has a date range of 1970-01-01 00:00:01 to 2038-01-19 03:14:07 and is unable to handle time_t of 0. MySQL's TIMESTAMP also assumes that input is in the server's timezone and adjusts it to UTC. GnuCash has already done that conversion. --- libgnucash/backend/dbi/gnc-dbiproviderimpl.hpp | 2 +- libgnucash/backend/sql/gnc-entry-sql.cpp | 3 ++- libgnucash/backend/sql/gnc-invoice-sql.cpp | 3 ++- libgnucash/backend/sql/gnc-price-sql.cpp | 7 +++++-- libgnucash/backend/sql/gnc-slots-sql.cpp | 7 ++++--- libgnucash/backend/sql/gnc-transaction-sql.cpp | 3 ++- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libgnucash/backend/dbi/gnc-dbiproviderimpl.hpp b/libgnucash/backend/dbi/gnc-dbiproviderimpl.hpp index 47795f91ab..32f3ec604b 100644 --- a/libgnucash/backend/dbi/gnc-dbiproviderimpl.hpp +++ b/libgnucash/backend/dbi/gnc-dbiproviderimpl.hpp @@ -130,7 +130,7 @@ GncDbiProviderImpl::append_col_def (std::string& ddl, } else if (info.m_type == BCT_DATETIME) { - type_name = "TIMESTAMP NULL DEFAULT 0"; + type_name = "DATETIME NULL DEFAULT '1970-01-01 00:00:00'"; } else { diff --git a/libgnucash/backend/sql/gnc-entry-sql.cpp b/libgnucash/backend/sql/gnc-entry-sql.cpp index c8be0d9a6d..9beb95b96c 100644 --- a/libgnucash/backend/sql/gnc-entry-sql.cpp +++ b/libgnucash/backend/sql/gnc-entry-sql.cpp @@ -57,7 +57,7 @@ extern "C" static QofLogModule log_module = G_LOG_DOMAIN; #define TABLE_NAME "entries" -#define TABLE_VERSION 3 +#define TABLE_VERSION 4 #define MAX_DESCRIPTION_LEN 2048 #define MAX_ACTION_LEN 2048 #define MAX_NOTES_LEN 2048 @@ -226,6 +226,7 @@ GncSqlEntryBackend::create_tables (GncSqlBackend* sql_be) /* Upgrade: 1->2: 64 bit int handling 2->3: "entered" -> "date_entered", and it can be NULL + 3->4: Use DATETIME instead of TIMESTAMP in MySQL */ sql_be->upgrade_table(TABLE_NAME, col_table); sql_be->set_table_version (TABLE_NAME, TABLE_VERSION); diff --git a/libgnucash/backend/sql/gnc-invoice-sql.cpp b/libgnucash/backend/sql/gnc-invoice-sql.cpp index 5cfffadaba..769aa2da99 100644 --- a/libgnucash/backend/sql/gnc-invoice-sql.cpp +++ b/libgnucash/backend/sql/gnc-invoice-sql.cpp @@ -56,7 +56,7 @@ extern "C" static QofLogModule log_module = G_LOG_DOMAIN; #define TABLE_NAME "invoices" -#define TABLE_VERSION 3 +#define TABLE_VERSION 4 #define MAX_ID_LEN 2048 #define MAX_NOTES_LEN 2048 @@ -164,6 +164,7 @@ GncSqlInvoiceBackend::create_tables (GncSqlBackend* sql_be) /* Upgrade: 1->2: 64 bit int handling 2->3: invoice open date can be NULL + 3->4: Use DATETIME instead of TIMESTAMP in MySQL */ sql_be->upgrade_table(TABLE_NAME, col_table); sql_be->set_table_version (TABLE_NAME, TABLE_VERSION); diff --git a/libgnucash/backend/sql/gnc-price-sql.cpp b/libgnucash/backend/sql/gnc-price-sql.cpp index eaf99eb007..f2cc188511 100644 --- a/libgnucash/backend/sql/gnc-price-sql.cpp +++ b/libgnucash/backend/sql/gnc-price-sql.cpp @@ -51,7 +51,7 @@ extern "C" static QofLogModule log_module = G_LOG_DOMAIN; #define TABLE_NAME "prices" -#define TABLE_VERSION 2 +#define TABLE_VERSION 3 #define PRICE_MAX_SOURCE_LEN 2048 #define PRICE_MAX_TYPE_LEN 2048 @@ -148,7 +148,10 @@ GncSqlPriceBackend::create_tables (GncSqlBackend* sql_be) } else if (version < m_version) { - /* Upgrade 64 bit int handling */ + /* + 1->2: Upgrade 64 bit int handling + 2->3: Use DATETIME instead of TIMESTAMP in MySQL + */ sql_be->upgrade_table(TABLE_NAME, col_table); sql_be->set_table_version (TABLE_NAME, TABLE_VERSION); diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp index 7cd80fdf89..8b35b27ef5 100644 --- a/libgnucash/backend/sql/gnc-slots-sql.cpp +++ b/libgnucash/backend/sql/gnc-slots-sql.cpp @@ -54,7 +54,7 @@ extern "C" static QofLogModule log_module = G_LOG_DOMAIN; #define TABLE_NAME "slots" -#define TABLE_VERSION 3 +#define TABLE_VERSION 4 typedef enum { @@ -958,11 +958,12 @@ GncSqlSlotsBackend::create_tables (GncSqlBackend* sql_be) PERR ("Unable to create index\n"); } } - else if (version < TABLE_VERSION) + else if (version < m_version) { /* Upgrade: 1->2: 64-bit int values to proper definition, add index 2->3: Add gdate field + 3->4: Use DATETIME instead of TIMESTAMP in MySQL */ if (version == 1) { @@ -982,7 +983,7 @@ GncSqlSlotsBackend::create_tables (GncSqlBackend* sql_be) PERR ("Unable to add gdate column\n"); } } - else if (version < m_version) + else { sql_be->upgrade_table(TABLE_NAME, col_table); } diff --git a/libgnucash/backend/sql/gnc-transaction-sql.cpp b/libgnucash/backend/sql/gnc-transaction-sql.cpp index e3ff00f248..266d35657d 100644 --- a/libgnucash/backend/sql/gnc-transaction-sql.cpp +++ b/libgnucash/backend/sql/gnc-transaction-sql.cpp @@ -69,7 +69,7 @@ extern "C" static QofLogModule log_module = G_LOG_DOMAIN; #define TRANSACTION_TABLE "transactions" -#define TX_TABLE_VERSION 3 +#define TX_TABLE_VERSION 4 #define SPLIT_TABLE "splits" #define SPLIT_TABLE_VERSION 4 @@ -481,6 +481,7 @@ GncSqlTransBackend::create_tables (GncSqlBackend* sql_be) /* Upgrade: 1->2: 64 bit int handling 2->3: allow dates to be NULL + 3->4: Use DATETIME instead of TIMESTAMP in MySQL */ sql_be->upgrade_table(m_table_name.c_str(), tx_col_table); sql_be->set_table_version (m_table_name.c_str(), m_version);