[SR-Dev] git:janakj/postgres: - support for timestamptz column type

Jan Janak jan at iptel.org
Sun Feb 15 18:55:28 CET 2009


Module: sip-router
Branch: janakj/postgres
Commit: c5e7623e00b0c8bbec8f15452f59c4865a47b792
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c5e7623e00b0c8bbec8f15452f59c4865a47b792

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Wed May 21 13:05:43 2008 +0000

- support for timestamptz column type

---

 modules/db_postgres/pg_fld.c |   16 ++++++++---
 modules/db_postgres/pg_mod.c |   59 ++++++++++++++++++++++++-----------------
 2 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/modules/db_postgres/pg_fld.c b/modules/db_postgres/pg_fld.c
index 8d80f56..4bac561 100644
--- a/modules/db_postgres/pg_fld.c
+++ b/modules/db_postgres/pg_fld.c
@@ -301,7 +301,8 @@ int pg_fld2pg(struct pg_params* dst, int off, pg_type_t* types,
 				db_int2pg_int2(dst, off + i, src + i);
 			else if (pfld->oid == types[PG_INT4].oid)
 				db_int2pg_int4(dst, off + i, src + i);
-			else if (pfld->oid == types[PG_TIMESTAMP].oid)
+			else if ((pfld->oid == types[PG_TIMESTAMP].oid) ||
+					 (pfld->oid == types[PG_TIMESTAMPTZ].oid))
 				db_int2pg_timestamp(dst, off + i, src + i, flags);
 			else if (pfld->oid == types[PG_INT8].oid)
 				db_int2pg_int8(dst, off + i, src + i);
@@ -331,7 +332,8 @@ int pg_fld2pg(struct pg_params* dst, int off, pg_type_t* types,
 		case DB_DATETIME:
 			if (pfld->oid == types[PG_INT4].oid)
 				db_int2pg_int4(dst, off + i, src + i);
-			else if (pfld->oid == types[PG_TIMESTAMP].oid)
+			else if ((pfld->oid == types[PG_TIMESTAMP].oid) ||
+					 (pfld->oid == types[PG_TIMESTAMPTZ].oid))
 				db_int2pg_timestamp(dst, off + i, src + i, flags);
 			else if (pfld->oid == types[PG_INT8].oid)
 				db_int2pg_int8(dst, off + i, src + i);
@@ -415,6 +417,7 @@ int pg_check_fld2pg(db_fld_t* fld, pg_type_t* types)
 			if (pfld->oid == types[PG_BOOL].oid) continue;
 			if (pfld->oid == types[PG_INET].oid) continue;
 			if (pfld->oid == types[PG_TIMESTAMP].oid) continue;
+			if (pfld->oid == types[PG_TIMESTAMPTZ].oid) continue;
 			if (pfld->oid == types[PG_BIT].oid) continue;
 			if (pfld->oid == types[PG_VARBIT].oid) continue;
 			break;
@@ -449,6 +452,7 @@ int pg_check_fld2pg(db_fld_t* fld, pg_type_t* types)
 			if (pfld->oid == types[PG_INT4].oid) continue;
 			if (pfld->oid == types[PG_INT8].oid) continue;
 			if (pfld->oid == types[PG_TIMESTAMP].oid) continue;
+			if (pfld->oid == types[PG_TIMESTAMPTZ].oid) continue;
 			break;
 
 		default:
@@ -535,6 +539,7 @@ int pg_check_pg2fld(db_fld_t* fld, pg_type_t* types)
 			if (pfld->oid == types[PG_BOOL].oid) continue;
 			if (pfld->oid == types[PG_INET].oid) continue;
 			if (pfld->oid == types[PG_TIMESTAMP].oid) continue;
+			if (pfld->oid == types[PG_TIMESTAMPTZ].oid) continue;
 			if (pfld->oid == types[PG_BIT].oid) continue;
 			if (pfld->oid == types[PG_VARBIT].oid) continue;
 			break;
@@ -580,6 +585,7 @@ int pg_check_pg2fld(db_fld_t* fld, pg_type_t* types)
 			if (pfld->oid == types[PG_INT2].oid) continue;
 			if (pfld->oid == types[PG_INT4].oid) continue;
 			if (pfld->oid == types[PG_TIMESTAMP].oid) continue;
+			if (pfld->oid == types[PG_TIMESTAMPTZ].oid) continue;
 			break;
 
 		default:
@@ -832,7 +838,8 @@ int pg_pg2fld(db_fld_t* dst, PGresult* src, int row,
 				ret |= pg_bool2db_int(dst + i, val, len);
 			else if (type == types[PG_INET].oid)
 				ret |= pg_inet2db_int(dst + i, val, len);
-			else if (type == types[PG_TIMESTAMP].oid)
+			else if ((type == types[PG_TIMESTAMP].oid) ||
+					 (type == types[PG_TIMESTAMPTZ].oid))
 				ret |= pg_timestamp2db_int(dst + i, val, len, flags);
 			else if (type == types[PG_BIT].oid)
 				ret |= pg_bit2db_int(dst + i, val, len);
@@ -860,7 +867,8 @@ int pg_pg2fld(db_fld_t* dst, PGresult* src, int row,
 				ret |= pg_int2_2_db_int(dst + i, val, len);
 			else if (type == types[PG_INT4].oid)
 				ret |= pg_int4_2_db_int(dst + i, val, len);
-			else if (type == types[PG_TIMESTAMP].oid)
+			else if ((type == types[PG_TIMESTAMP].oid) ||
+					 (type == types[PG_TIMESTAMPTZ].oid))
 				ret |= pg_timestamp2db_int(dst + i, val, len, flags);
 			else goto bug;
 			break;
diff --git a/modules/db_postgres/pg_mod.c b/modules/db_postgres/pg_mod.c
index 2316bb3..11aa9a9 100644
--- a/modules/db_postgres/pg_mod.c
+++ b/modules/db_postgres/pg_mod.c
@@ -135,20 +135,22 @@ int pg_test(void)
 	char* times;
 
 	db_fld_t int_vals[] = {
-		{.name = "col_bool",      .type = DB_INT},
-		{.name = "col_int8",      .type = DB_INT},
-		{.name = "col_int4",      .type = DB_INT},
-		{.name = "col_inet",      .type = DB_INT},
-		{.name = "col_timestamp", .type = DB_INT},
-		{.name = "col_bit",       .type = DB_INT},
-		{.name = "col_varbit",    .type = DB_INT},
+		{.name = "col_bool",        .type = DB_INT},
+		{.name = "col_int8",        .type = DB_INT},
+		{.name = "col_int4",        .type = DB_INT},
+		{.name = "col_inet",        .type = DB_INT},
+		{.name = "col_timestamp",   .type = DB_INT},
+		{.name = "col_timestamptz", .type = DB_INT},
+		{.name = "col_bit",         .type = DB_INT},
+		{.name = "col_varbit",      .type = DB_INT},
 		{.name = NULL}
 	};
 
 	db_fld_t datetime_vals[] = {
-		{.name = "col_int8",      .type = DB_INT},
-		{.name = "col_int4",      .type = DB_INT},
-		{.name = "col_timestamp", .type = DB_INT},
+		{.name = "col_int8",        .type = DB_INT},
+		{.name = "col_int4",        .type = DB_INT},
+		{.name = "col_timestamp",   .type = DB_INT},
+		{.name = "col_timestamptz", .type = DB_INT},
 		{.name = NULL}
 	};
 
@@ -197,21 +199,22 @@ int pg_test(void)
 
 
 	db_fld_t res[] = {
-		{.name = "col_bool",      .type = DB_INT},
-		{.name = "col_bytea",     .type = DB_BLOB},
-		{.name = "col_char",      .type = DB_STR},
-		{.name = "col_int8",      .type = DB_INT},
-		{.name = "col_int4",      .type = DB_INT},
-		{.name = "col_int2",      .type = DB_INT},
-		{.name = "col_text",      .type = DB_STR},
-		{.name = "col_float4",    .type = DB_FLOAT},
-		{.name = "col_float8",    .type = DB_DOUBLE},
-		{.name = "col_inet",      .type = DB_INT},
-		{.name = "col_bpchar",    .type = DB_STR},
-		{.name = "col_varchar",   .type = DB_STR},
-		{.name = "col_timestamp", .type = DB_DATETIME},
-		{.name = "col_bit",       .type = DB_BITMAP},
-		{.name = "col_varbit",    .type = DB_BITMAP},
+		{.name = "col_bool",        .type = DB_INT},
+		{.name = "col_bytea",       .type = DB_BLOB},
+		{.name = "col_char",        .type = DB_STR},
+		{.name = "col_int8",        .type = DB_INT},
+		{.name = "col_int4",        .type = DB_INT},
+		{.name = "col_int2",        .type = DB_INT},
+		{.name = "col_text",        .type = DB_STR},
+		{.name = "col_float4",      .type = DB_FLOAT},
+		{.name = "col_float8",      .type = DB_DOUBLE},
+		{.name = "col_inet",        .type = DB_INT},
+		{.name = "col_bpchar",      .type = DB_STR},
+		{.name = "col_varchar",     .type = DB_STR},
+		{.name = "col_timestamp",   .type = DB_DATETIME},
+		{.name = "col_timestamptz", .type = DB_DATETIME},
+		{.name = "col_bit",         .type = DB_BITMAP},
+		{.name = "col_varbit",      .type = DB_BITMAP},
 		{.name = NULL}
 	};
 
@@ -248,6 +251,7 @@ int pg_test(void)
 	put->vals[4].v.int4 = 0xffffffff;
 	put->vals[5].v.int4 = 0xffffffff;
 	put->vals[6].v.int4 = 0xffffffff;
+	put->vals[7].v.int4 = 0xffffffff;
 
 	if (db_exec(NULL, put)) {
 		ERR("Error while executing database command\n");
@@ -261,6 +265,7 @@ int pg_test(void)
 	put->vals[4].v.int4 = 0;
 	put->vals[5].v.int4 = 0;
 	put->vals[6].v.int4 = 0;
+	put->vals[7].v.int4 = 0;
 
 	if (db_exec(NULL, put)) {
 		ERR("Error while executing database command\n");
@@ -279,6 +284,7 @@ int pg_test(void)
 	put->vals[1].v.int4 = 0xffffffff;
 	put->vals[2].v.int4 = 0xffffffff;
 	put->vals[3].v.int4 = 0xffffffff;
+	put->vals[4].v.int4 = 0xffffffff;
 	if (db_exec(NULL, put)) {
 		ERR("Error while executing database command\n");
 		goto error;
@@ -288,6 +294,7 @@ int pg_test(void)
 	put->vals[1].v.int4 = 0;
 	put->vals[2].v.int4 = 0;
 	put->vals[3].v.int4 = 0;
+	put->vals[4].v.int4 = 0;
 	if (db_exec(NULL, put)) {
 		ERR("Error while executing database command\n");
 		goto error;
@@ -429,6 +436,7 @@ int pg_test(void)
 	put->vals[0].v.time = 0xffffffff;
 	put->vals[1].v.time = 0xffffffff;
 	put->vals[2].v.time = 0xffffffff;
+	put->vals[3].v.time = 0xffffffff;
 	if (db_exec(NULL, put)) {
 		ERR("Error while executing database command\n");
 		goto error;
@@ -437,6 +445,7 @@ int pg_test(void)
 	put->vals[0].v.time = 0;
 	put->vals[1].v.time = 0;
 	put->vals[2].v.time = 0;
+	put->vals[3].v.time = 0;
 	if (db_exec(NULL, put)) {
 		ERR("Error while executing database command\n");
 		goto error;




More information about the sr-dev mailing list