Changeset: 12774a7fb613 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=12774a7fb613
Modified Files:
        clients/odbc/driver/SQLConnect.c
Branch: Aug2011
Log Message:

Tell the server which time zone the client is in.
This way, for types with time zones, we get the local time.


diffs (59 lines):

diff --git a/clients/odbc/driver/SQLConnect.c b/clients/odbc/driver/SQLConnect.c
--- a/clients/odbc/driver/SQLConnect.c
+++ b/clients/odbc/driver/SQLConnect.c
@@ -43,6 +43,9 @@
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
 
 #ifdef HAVE_ODBCINST_H
 #include <odbcinst.h>
@@ -52,6 +55,37 @@
 #define 
SQLGetPrivateProfileString(section,entry,default,buffer,bufferlen,filename)    
(strncpy(buffer,default,bufferlen), buffer[bufferlen-1]=0, strlen(buffer))
 #endif
 
+static void
+set_timezone(Mapi mid)
+{
+#ifdef HAVE_TIMEZONE
+#ifdef _MSC_VER
+#define timezone _timezone
+#define daylight _daylight
+#define tzset _tzset
+#endif
+       char buf[128];
+       long tzone;
+       MapiHdl hdl;
+
+       /* timezone and daylight are POSIX-defined variables */
+       tzset();
+       tzone = timezone - 3600 * daylight;
+       if (tzone < 0)
+               snprintf(buf, sizeof(buf),
+                        "SET TIME ZONE INTERVAL '+%02ld:%02ld' HOUR TO MINUTE",
+                        -tzone / 3600, (-tzone % 3600) / 60);
+       else
+               snprintf(buf, sizeof(buf),
+                        "SET TIME ZONE INTERVAL '-%02ld:%02ld' HOUR TO MINUTE",
+                        tzone / 3600, (tzone % 3600) / 60);
+       if ((hdl = mapi_query(mid, buf)) != NULL)
+               mapi_close_handle(hdl);
+#else
+       (void) mid;
+#endif
+}
+
 SQLRETURN
 SQLConnect_(ODBCDbc *dbc,
            SQLCHAR *ServerName,
@@ -199,6 +233,7 @@ SQLConnect_(ODBCDbc *dbc,
                        free(dbc->dbname);
                dbc->dbname = schema ? strdup(schema) : NULL;
                mapi_setAutocommit(mid, dbc->sql_attr_autocommit == 
SQL_AUTOCOMMIT_ON);
+               set_timezone(mid);
        }
 
        return rc;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to