From 18ac7691c3de3ed9dca89020a3544da4a485e8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sun, 6 Dec 2015 00:12:15 +0000 Subject: [PATCH] [GB.DB.POSTGRESQL] * BUG: Gambas date/time values without date is now stored as the minimum possible date that PostgreSQL accepts, '4713-01-01 BC'. git-svn-id: svn://localhost/gambas/trunk@7506 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.db.postgresql/src/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gb.db.postgresql/src/main.c b/gb.db.postgresql/src/main.c index 0332c71a2..d3e4fd39b 100644 --- a/gb.db.postgresql/src/main.c +++ b/gb.db.postgresql/src/main.c @@ -456,6 +456,11 @@ static void conv_data(const char *data, int len, GB_VARIANT_VALUE *val, Oid type if (bc) date.year = (-date.year); + // 4713-01-01 BC is used for null dates + + if (date.year == -4713 && date.month == 1 && date.day == 1) + date.year = date.month = date.day = 0; + GB.MakeDate(&date, (GB_DATE *)&conv); val->type = GB_T_DATE; @@ -867,9 +872,13 @@ static int format_value(GB_VALUE *arg, DB_FORMAT_CALLBACK add) date = GB.SplitDate((GB_DATE *)arg); + // Gambas year is between -4801 and +9999 + // PostgreSQL year is between -4713 and +294276 + // So let's use -4713 for representing null dates. + if (date->year == 0) { - l = sprintf(_buffer, "'%02d:%02d:%02d'", date->hour, date->min, date->sec); + l = sprintf(_buffer, "'4713-01-01 %02d:%02d:%02d BC'", date->hour, date->min, date->sec); add(_buffer, l); } else