From 47c07a28035c4c618e0b47dc923eb1e471c8cfec Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Tue, 1 Sep 2020 19:16:01 -0400 Subject: [PATCH 1/4] Fix links in README file --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 9e44cfb..69b2859 100644 --- a/README +++ b/README @@ -65,7 +65,7 @@ If you want to build the ODBC driver, you'll need unixodbc (version 2.2.10 or above) or iodbc. If you want to build man pages, you'll need txt2man. Source is available at -http://mvertes.free.fr/download/. +https://github.com/mvertes/txt2man. If you want to generate the html version of the docbook, you'll need openjade and basic dsl catalogs. @@ -74,7 +74,7 @@ and basic dsl catalogs. Installation from source: ========================= -Last version is available at https://github.com/brianb/mdbtools +Last version is available at https://github.com/mdbtools/mdbtools $ autoreconf -i -f @@ -117,7 +117,7 @@ The mailing list from the old site is available at http://mdbtools.sourceforge.net Please send bug repports to the new github platform. -https://github.com/brianb/mdbtools/issues +https://github.com/mdbtools/mdbtools/issues Brian Bruns From 9c8b67b8f8661573c41032291d436d56ac4094fc Mon Sep 17 00:00:00 2001 From: James Woodcock Date: Sat, 19 Sep 2020 11:28:00 +0100 Subject: [PATCH 2/4] mdb-sql: support ';' as an SQL terminator --- src/util/mdb-sql.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/util/mdb-sql.c b/src/util/mdb-sql.c index 4531095..44bdab6 100644 --- a/src/util/mdb-sql.c +++ b/src/util/mdb-sql.c @@ -334,6 +334,28 @@ dump_results_pp(FILE *out, MdbSQL *sql) } } +static char * +find_sql_terminator(char *s) +{ + char *sp; + int len = strlen(s); + + if (len == 0) { + return NULL; + } + + sp = &s[len-1]; + while (sp > s && isspace(*sp)) { + sp--; + } + + if (*sp == ';') { + return sp; + } + + return NULL; +} + int main(int argc, char **argv) { @@ -454,6 +476,8 @@ main(int argc, char **argv) } else if (!strncmp(s,":r",2)) { line += read_file(&s[2], line, &bufsz, mybuf); } else { + char *p; + while (strlen(mybuf) + strlen(s) > bufsz) { bufsz *= 2; mybuf = (char *) g_realloc(mybuf, bufsz); @@ -465,6 +489,13 @@ main(int argc, char **argv) strcat(mybuf,s); /* preserve line numbering for the parser */ strcat(mybuf,"\n"); + + if ((p = find_sql_terminator(mybuf))) { + *p = '\0'; + line = 0; + run_query((out) ? out : stdout, sql, mybuf, delimiter); + mybuf[0]='\0'; + } } } mdb_sql_exit(sql); From eab60a6060f3a060d0c1fa6f66fe90329c406a0f Mon Sep 17 00:00:00 2001 From: James Woodcock Date: Sat, 19 Sep 2020 11:28:44 +0100 Subject: [PATCH 3/4] mdb-sql: Handle ';' as terminators in SQL input files --- src/util/mdb-sql.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/util/mdb-sql.c b/src/util/mdb-sql.c index 44bdab6..63f4326 100644 --- a/src/util/mdb-sql.c +++ b/src/util/mdb-sql.c @@ -443,15 +443,16 @@ main(int argc, char **argv) if (s) free(s); if (in) { - s=malloc(256); - if ((!s) || (!fgets(s, 256, in))) { - /* if we have something in the buffer, run it */ + s=malloc(bufsz); + if (!fgets(s, bufsz, in)) { + // Backwards compatibility with older MDBTools + // Files read from the command line had an + // implicit "go" at the end if (strlen(mybuf)) - run_query((out) ? out : stdout, - sql, mybuf, delimiter); - break; - } - if (s[strlen(s)-1]=='\n') + strcpy(s, "go"); + else + break; + } else if (s[strlen(s)-1]=='\n') s[strlen(s)-1]=0; } else { sprintf(prompt, "%d => ", line); @@ -483,8 +484,8 @@ main(int argc, char **argv) mybuf = (char *) g_realloc(mybuf, bufsz); } #ifdef HAVE_READLINE_HISTORY - /* don't record blank lines */ - if (strlen(s)) add_history(s); + /* don't record blank lines, or lines read from files */ + if (!in && strlen(s)) add_history(s); #endif strcat(mybuf,s); /* preserve line numbering for the parser */ From 833985043f65aa29ae2de7650bf09737edfc1aec Mon Sep 17 00:00:00 2001 From: James Woodcock Date: Sat, 19 Sep 2020 11:29:41 +0100 Subject: [PATCH 4/4] mdb-sql: Simplify handling files loaded by ":r" :r is an undocumented command to load SQL files from the msb-sql prompt --- src/util/mdb-sql.c | 66 ++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/src/util/mdb-sql.c b/src/util/mdb-sql.c index 63f4326..7303dae 100644 --- a/src/util/mdb-sql.c +++ b/src/util/mdb-sql.c @@ -156,40 +156,6 @@ do_set_cmd(MdbSQL *sql, char *s) } } -int -read_file(char *s, int line, unsigned int *bufsz, char *mybuf) -{ - char *fname; - FILE *in; - char buf[256]; - unsigned int cursz = 0; - int lines = 0; - - fname = s; - while (*fname && *fname==' ') fname++; - - if (! (in = fopen(fname, "r"))) { - fprintf(stderr,"Unable to open file %s\n", fname); - mybuf[0]=0; - return 0; - } - while (fgets(buf, 255, in)) { - cursz += strlen(buf) + 1; - if (cursz > (*bufsz)) { - (*bufsz) *= 2; - mybuf = (char *) realloc(mybuf, *bufsz); - } - strcat(mybuf, buf); -#ifdef HAVE_READLINE_HISTORY - /* don't record blank lines */ - if (strlen(buf)) add_history(buf); -#endif - strcat(mybuf, "\n"); - lines++; - printf("%d => %s",line+lines, buf); - } - return lines; -} void run_query(FILE *out, MdbSQL *sql, char *mybuf, char *delimiter) { @@ -370,6 +336,7 @@ main(int argc, char **argv) char *home = getenv("HOME"); char *histpath; char *delimiter = NULL; + int in_from_colon_r = 0; GOptionEntry entries[] = { @@ -443,14 +410,19 @@ main(int argc, char **argv) if (s) free(s); if (in) { - s=malloc(bufsz); + s=calloc(bufsz, 1); if (!fgets(s, bufsz, in)) { // Backwards compatibility with older MDBTools // Files read from the command line had an // implicit "go" at the end - if (strlen(mybuf)) + if (!in_from_colon_r && strlen(mybuf)) strcpy(s, "go"); - else + else if (in_from_colon_r) { + line = 0; + fclose(in); + in = NULL; + in_from_colon_r = 0; + } else break; } else if (s[strlen(s)-1]=='\n') s[strlen(s)-1]=0; @@ -475,7 +447,19 @@ main(int argc, char **argv) line = 0; mybuf[0]='\0'; } else if (!strncmp(s,":r",2)) { - line += read_file(&s[2], line, &bufsz, mybuf); + char *fname = &s[2]; + if (in) { + fprintf(stderr, "Can not handle nested opens\n"); + } else { + while (*fname && isspace(*fname)) + fname++; + if (!(in = fopen(fname, "r"))) { + fprintf(stderr,"Unable to open file %s\n", fname); + mybuf[0]=0; + } else { + in_from_colon_r = 1; + } + } } else { char *p; @@ -484,8 +468,10 @@ main(int argc, char **argv) mybuf = (char *) g_realloc(mybuf, bufsz); } #ifdef HAVE_READLINE_HISTORY - /* don't record blank lines, or lines read from files */ - if (!in && strlen(s)) add_history(s); + /* don't record blank lines, or lines read from files + * specified on the command line */ + if ((!in || in_from_colon_r) && strlen(s)) + add_history(s); #endif strcat(mybuf,s); /* preserve line numbering for the parser */