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.
This commit is contained in:
John Ralls 2017-11-23 11:41:09 -08:00
parent 937f8c5083
commit 9c4635e393
6 changed files with 16 additions and 9 deletions

View File

@ -130,7 +130,7 @@ GncDbiProviderImpl<DbType::DBI_MYSQL>::append_col_def (std::string& ddl,
} }
else if (info.m_type == BCT_DATETIME) 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 else
{ {

View File

@ -57,7 +57,7 @@ extern "C"
static QofLogModule log_module = G_LOG_DOMAIN; static QofLogModule log_module = G_LOG_DOMAIN;
#define TABLE_NAME "entries" #define TABLE_NAME "entries"
#define TABLE_VERSION 3 #define TABLE_VERSION 4
#define MAX_DESCRIPTION_LEN 2048 #define MAX_DESCRIPTION_LEN 2048
#define MAX_ACTION_LEN 2048 #define MAX_ACTION_LEN 2048
#define MAX_NOTES_LEN 2048 #define MAX_NOTES_LEN 2048
@ -226,6 +226,7 @@ GncSqlEntryBackend::create_tables (GncSqlBackend* sql_be)
/* Upgrade: /* Upgrade:
1->2: 64 bit int handling 1->2: 64 bit int handling
2->3: "entered" -> "date_entered", and it can be NULL 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->upgrade_table(TABLE_NAME, col_table);
sql_be->set_table_version (TABLE_NAME, TABLE_VERSION); sql_be->set_table_version (TABLE_NAME, TABLE_VERSION);

View File

@ -56,7 +56,7 @@ extern "C"
static QofLogModule log_module = G_LOG_DOMAIN; static QofLogModule log_module = G_LOG_DOMAIN;
#define TABLE_NAME "invoices" #define TABLE_NAME "invoices"
#define TABLE_VERSION 3 #define TABLE_VERSION 4
#define MAX_ID_LEN 2048 #define MAX_ID_LEN 2048
#define MAX_NOTES_LEN 2048 #define MAX_NOTES_LEN 2048
@ -164,6 +164,7 @@ GncSqlInvoiceBackend::create_tables (GncSqlBackend* sql_be)
/* Upgrade: /* Upgrade:
1->2: 64 bit int handling 1->2: 64 bit int handling
2->3: invoice open date can be NULL 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->upgrade_table(TABLE_NAME, col_table);
sql_be->set_table_version (TABLE_NAME, TABLE_VERSION); sql_be->set_table_version (TABLE_NAME, TABLE_VERSION);

View File

@ -51,7 +51,7 @@ extern "C"
static QofLogModule log_module = G_LOG_DOMAIN; static QofLogModule log_module = G_LOG_DOMAIN;
#define TABLE_NAME "prices" #define TABLE_NAME "prices"
#define TABLE_VERSION 2 #define TABLE_VERSION 3
#define PRICE_MAX_SOURCE_LEN 2048 #define PRICE_MAX_SOURCE_LEN 2048
#define PRICE_MAX_TYPE_LEN 2048 #define PRICE_MAX_TYPE_LEN 2048
@ -148,7 +148,10 @@ GncSqlPriceBackend::create_tables (GncSqlBackend* sql_be)
} }
else if (version < m_version) 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->upgrade_table(TABLE_NAME, col_table);
sql_be->set_table_version (TABLE_NAME, TABLE_VERSION); sql_be->set_table_version (TABLE_NAME, TABLE_VERSION);

View File

@ -54,7 +54,7 @@ extern "C"
static QofLogModule log_module = G_LOG_DOMAIN; static QofLogModule log_module = G_LOG_DOMAIN;
#define TABLE_NAME "slots" #define TABLE_NAME "slots"
#define TABLE_VERSION 3 #define TABLE_VERSION 4
typedef enum typedef enum
{ {
@ -958,11 +958,12 @@ GncSqlSlotsBackend::create_tables (GncSqlBackend* sql_be)
PERR ("Unable to create index\n"); PERR ("Unable to create index\n");
} }
} }
else if (version < TABLE_VERSION) else if (version < m_version)
{ {
/* Upgrade: /* Upgrade:
1->2: 64-bit int values to proper definition, add index 1->2: 64-bit int values to proper definition, add index
2->3: Add gdate field 2->3: Add gdate field
3->4: Use DATETIME instead of TIMESTAMP in MySQL
*/ */
if (version == 1) if (version == 1)
{ {
@ -982,7 +983,7 @@ GncSqlSlotsBackend::create_tables (GncSqlBackend* sql_be)
PERR ("Unable to add gdate column\n"); PERR ("Unable to add gdate column\n");
} }
} }
else if (version < m_version) else
{ {
sql_be->upgrade_table(TABLE_NAME, col_table); sql_be->upgrade_table(TABLE_NAME, col_table);
} }

View File

@ -69,7 +69,7 @@ extern "C"
static QofLogModule log_module = G_LOG_DOMAIN; static QofLogModule log_module = G_LOG_DOMAIN;
#define TRANSACTION_TABLE "transactions" #define TRANSACTION_TABLE "transactions"
#define TX_TABLE_VERSION 3 #define TX_TABLE_VERSION 4
#define SPLIT_TABLE "splits" #define SPLIT_TABLE "splits"
#define SPLIT_TABLE_VERSION 4 #define SPLIT_TABLE_VERSION 4
@ -481,6 +481,7 @@ GncSqlTransBackend::create_tables (GncSqlBackend* sql_be)
/* Upgrade: /* Upgrade:
1->2: 64 bit int handling 1->2: 64 bit int handling
2->3: allow dates to be NULL 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->upgrade_table(m_table_name.c_str(), tx_col_table);
sql_be->set_table_version (m_table_name.c_str(), m_version); sql_be->set_table_version (m_table_name.c_str(), m_version);