Changeset: 0b7d194f9111 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0b7d194f9111
Modified Files:
        NT/monetdb_config.h.in
        clients/ChangeLog.Aug2011
        clients/mapiclient/Tests/mclient--help.stable.err
        clients/mapiclient/mclient.1
        clients/mapiclient/mclient.c
        configure.ag
        sql/test/Tests/mclient-t-s.stable.err
Branch: Aug2011
Log Message:

mclient: set server's time zone to client's local time zone.


diffs (177 lines):

diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -592,6 +592,11 @@
 /* Define to 1 if you have the <time.h> header file. */
 /* #undef HAVE_TIME_H */
 
+/* Define to 1 if you have the timezone and daylight variables. */
+#define HAVE_TIMEZONE 1
+#define timezone _timezone
+#define daylight _daylight
+
 /* Define to 1 if you have the `trunc' function. */
 /* #undef HAVE_TRUNC */
 
diff --git a/clients/ChangeLog.Aug2011 b/clients/ChangeLog.Aug2011
--- a/clients/ChangeLog.Aug2011
+++ b/clients/ChangeLog.Aug2011
@@ -1,6 +1,10 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Fri Aug  5 2011 Sjoerd Mullender <[email protected]>
+- mclient now automatically sets the SQL `TIME ZONE' variable to its
+  (the client's) time zone.
+
 * Sun Jul 24 2011 Fabian Groffen <[email protected]>
 - Removed perl/Cimpl, MonetDB-CLI-MapiLib and MonetDB-CLI-MapiXS
 - Switched implementation of MonetDB::CLI::MapiPP to Mapi.pm, and made
diff --git a/clients/mapiclient/Tests/mclient--help.stable.err 
b/clients/mapiclient/Tests/mclient--help.stable.err
--- a/clients/mapiclient/Tests/mclient--help.stable.err
+++ b/clients/mapiclient/Tests/mclient--help.stable.err
@@ -26,6 +26,7 @@ Options are:
  -L logfile  | --log=logfile     save client/server interaction
  -s stmt     | --statement=stmt  run single statement
  -X          | --Xdebug          trace mapi network interaction
+ -z          | --timezone         do not tell server our timezone
  -| cmd      | --pager=cmd        for pagination
  -?          | --help             show this usage message
 
diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1
--- a/clients/mapiclient/mclient.1
+++ b/clients/mapiclient/mclient.1
@@ -173,6 +173,9 @@ files specified on the command line are 
 interactive session is started (if the \fB\-\-interactive\fP option is
 given).
 .TP
+\fB\--timezone\fP (\fB\-z\fP)
+Do not tell the client's timezone to the server.
+.TP
 \fB\-\-Xdebug\fP (\fB\-X\fP)
 Trace network interaction between
 .I mclient
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -2358,6 +2358,36 @@ doFileByLines(Mapi mid, FILE *fp, const 
        return errseen;
 }
 
+static void
+set_timezone(Mapi mid)
+{
+#ifdef HAVE_TIMEZONE
+       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_explain(mid, stderr);
+               errseen = 1;
+               return;
+       }
+       mapi_close_handle(hdl);
+#else
+       (void) mid;
+#endif
+}
+
 static void usage(const char *prog, int xit)
        __attribute__((__noreturn__));
 
@@ -2386,6 +2416,7 @@ usage(const char *prog, int xit)
        fprintf(stderr, " -L logfile  | --log=logfile      save client/server 
interaction\n");
        fprintf(stderr, " -s stmt     | --statement=stmt   run single 
statement\n");
        fprintf(stderr, " -X          | --Xdebug           trace mapi network 
interaction\n");
+       fprintf(stderr, " -z          | --timezone         do not tell server 
our timezone\n");
 #ifdef HAVE_POPEN
        fprintf(stderr, " -| cmd      | --pager=cmd        for pagination\n");
 #endif
@@ -2421,6 +2452,7 @@ main(int argc, char **argv)
        int interactive = 0;
        int has_fileargs = 0;
        int option_index = 0;
+       int settz = 1;
        struct stat statb;
        stream *config = NULL;
        char user_set_as_flag = 0;
@@ -2453,6 +2485,7 @@ main(int argc, char **argv)
                {"version", 0, 0, 'v'},
                {"width", 1, 0, 'w'},
                {"Xdebug", 0, 0, 'X'},
+               {"timezone", 0, 0, 'z'},
                {0, 0, 0, 0}
        };
 
@@ -2582,7 +2615,7 @@ main(int argc, char **argv)
 #if 0
                                "t"
 #endif
-                               "w:r:p:s:Xu:vH?",
+                               "w:r:p:s:Xu:vzH?",
                                long_options, &option_index)) != -1) {
                switch (c) {
                case 0:
@@ -2688,6 +2721,9 @@ main(int argc, char **argv)
                                        "support for command-line editing 
compiled-in\n");
 #endif
                        return(0);
+               case 'z':
+                       settz = 0;
+                       break;
                case '?':
                        /* a bit of a hack: look at the option that the
                           current `c' is based on and see if we recognize
@@ -2799,6 +2835,9 @@ main(int argc, char **argv)
                        mnstr_printf(toConsole, "auto commit mode: on\n");
        }
 
+       if (mode == SQL && settz)
+               set_timezone(mid);
+
        if (command != NULL) {
 #ifdef HAVE_ICONV
                if (encoding != NULL && cd_in != (iconv_t) -1) {
diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -2534,6 +2534,16 @@ AH_VERBATIM([__attribute__],
 #endif
 ])
 
+AC_MSG_CHECKING([if you have timezone and daylight variables])
+AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+               [[#include <time.h>]],
+               [[printf("%ld %d\n", timezone, daylight);]])],
+       AC_MSG_RESULT([yes])
+       AC_DEFINE([HAVE_TIMEZONE], 1,
+               [Define to 1 if you have the timezone and daylight variables.]),
+       AC_MSG_RESULT([no]))
+
 dnl     checks for library functions
 case $host in
        *-darwin10*)
diff --git a/sql/test/Tests/mclient-t-s.stable.err 
b/sql/test/Tests/mclient-t-s.stable.err
--- a/sql/test/Tests/mclient-t-s.stable.err
+++ b/sql/test/Tests/mclient-t-s.stable.err
@@ -93,6 +93,7 @@ Options are:
  -L logfile  | --log=logfile      save client/server interaction
  -s stmt     | --statement=stmt   run single statement
  -X          | --Xdebug           trace mapi network interaction
+ -z          | --timezone         do not tell server our timezone
  -| cmd      | --pager=cmd        for pagination
  -?          | --help             show this usage message
 
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to