Changeset: 3a6c072d21dc for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/3a6c072d21dc
Modified Files:
        ChangeLog.Dec2025
        clients/mapiclient/mclient.1
        clients/mapiclient/mclient.c
Branch: Dec2025
Log Message:

Implemented option --relative-dir (aka -/) in mclient.  See manual.


diffs (102 lines):

diff --git a/ChangeLog.Dec2025 b/ChangeLog.Dec2025
--- a/ChangeLog.Dec2025
+++ b/ChangeLog.Dec2025
@@ -1,3 +1,7 @@
 # ChangeLog file for devel
 # This file is updated with Maddlog
 
+* Fri Oct 23 2026 Sjoerd Mullender <[email protected]>
+- Added an option --relative-dir to mclient to specify the directory
+  for relative path names when using the ON CLIENT option in SQL queries.
+
diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1
--- a/clients/mapiclient/mclient.1
+++ b/clients/mapiclient/mclient.1
@@ -342,6 +342,14 @@ dumping the data of a table.
 This option can be used when trying to load data from MonetDB into
 another database, or when e.g. JDBC applications are used to reload
 the dump.
+.TP
+\fB\-\-relative\-dir=\fP\fIdirectory\fP (\fB\-/\fP \fIdirectory\fP)
+Directory used to find files specified using a relative path name when
+using the \fBON CLIENT\fP option in SQL queries that support them.
+Normally when a file is given as command line argument, such files are
+located relative to the directory of the input file.
+This option overrides that, and also specifies a directory for when
+queries are read from standard input.
 .SH BACKSLASH COMMANDS
 .SS
 General Commands
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -69,6 +69,7 @@ static bool echoquery = false;
 static bool errseen = false;
 static bool allow_remote = false;
 static const char *curfile = NULL;
+static const char *reldir = NULL;
 
 #define setPrompt() snprintf(promptbuf, sizeof(promptbuf), "%.*s>", (int) 
sizeof(promptbuf) - 2, language)
 #define debugMode() (strncmp(promptbuf, "mdb", 3) == 0)
@@ -3316,7 +3317,13 @@ getfile(void *data, const char *filename
 #endif
                }
                if (f == NULL) {
-                       if (curfile != NULL) {
+                       if (reldir != NULL) {
+                               size_t x = strlen(reldir) + strlen(fname) + 2;
+                               char *b = malloc(x);
+                               snprintf(b, x, "%s/%s", reldir, fname);
+                               f = binary ? open_rstream(b) : open_rastream(b);
+                               free(b);
+                       } else if (curfile != NULL) {
                                const char *p = strrchr(curfile, '/');
 #ifdef _MSC_VER
                                const char *q = strrchr(curfile, '\\');
@@ -3445,9 +3452,7 @@ putfile(void *data, const char *filename
        return NULL;            /* success */
 }
 
-static _Noreturn void usage(const char *prog, int xit);
-
-static void
+static _Noreturn void
 usage(const char *prog, int xit)
 {
        mnstr_printf(stderr_stream, "Usage: %s [ options ] [ file or database [ 
file ... ] ]\n", prog);
@@ -3477,6 +3482,7 @@ usage(const char *prog, int xit)
 #ifdef HAVE_POPEN
        mnstr_printf(stderr_stream, " -| cmd      | --pager=cmd        for 
pagination\n");
 #endif
+       mnstr_printf(stderr_stream, " -/ dir      | --relative-dir=dir 
directory for relative paths in ON CLIENT\n");
        mnstr_printf(stderr_stream, " -v          | --version          show 
version information and exit\n");
        mnstr_printf(stderr_stream, " -q          | --quiet            don't 
print welcome message\n");
        mnstr_printf(stderr_stream, " -?          | --help             show 
this usage message\n");
@@ -3596,6 +3602,7 @@ main(int argc, char **argv)
                {"Xdebug", 0, 0, 'X'},
                {"timezone", 0, 0, 'z'},
                {"allow-remote", 0, 0, 'R'},
+               {"relative-dir", 1, 0, '/'},
                {0, 0, 0, 0}
        };
 
@@ -3674,7 +3681,7 @@ main(int argc, char **argv)
 #ifdef HAVE_POPEN
                                "|:"
 #endif
-                               "?",
+                               "/:?",
                                long_options, &option_index)) != -1) {
                switch (c) {
                case 0:
@@ -3835,6 +3842,10 @@ main(int argc, char **argv)
                        pager = optarg;
                        break;
 #endif
+               case '/':
+                       assert(optarg);
+                       reldir = optarg;
+                       break;
                case '?':
                        /* a bit of a hack: look at the option that the
                         * current `c' is based on and see if we recognize
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to