Changeset: 35db1c518074 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=35db1c518074 Modified Files: clients/src/mapiclient/dump.c clients/src/mapiclient/mclient.c clients/src/mapiclient/msqldump.h Branch: default Log Message:
mclient: make \d backwards compatible
Allow the \d command to work on the previous release, and databases
created by that release. The sysfunctions table was only introduced
here, and hence we need to check if it is available before using it.
diffs (147 lines):
diff -r 3375a722bb1e -r 35db1c518074 clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c Fri Dec 10 13:52:46 2010 +0100
+++ b/clients/src/mapiclient/dump.c Fri Dec 10 14:29:40 2010 +0100
@@ -114,7 +114,7 @@
return NULL;
}
-static int
+int
has_systemfunctions(Mapi mid)
{
MapiHdl hdl;
diff -r 3375a722bb1e -r 35db1c518074 clients/src/mapiclient/mclient.c
--- a/clients/src/mapiclient/mclient.c Fri Dec 10 13:52:46 2010 +0100
+++ b/clients/src/mapiclient/mclient.c Fri Dec 10 14:29:40 2010 +0100
@@ -1768,6 +1768,8 @@
#define MD_FUNC 8
#define MD_SCHEMA 16
+enum hmyesno { UNKNOWN, YES, NO };
+
static int
doFileByLines(Mapi mid, FILE *fp, const char *prompt, const char useinserts)
{
@@ -1778,6 +1780,7 @@
MapiMsg rc = MOK;
int sent = 0; /* whether we sent any data to the server */
int lineno = 1;
+ enum hmyesno hassysfuncs = UNKNOWN;
#ifdef HAVE_LIBREADLINE
if (prompt == NULL)
@@ -2063,23 +2066,67 @@
} else {
/* get all object names in
current schema */
char *type, *name, *schema;
- char q[2048];
- char nameq[256];
+ char q[4096];
+ char nameq[128];
+ char funcq[512];
+
+ if (hassysfuncs == UNKNOWN)
+ hassysfuncs =
has_systemfunctions(mid) ? YES : NO;
+
if (!*line) {
line = "%";
hasSchema = 0;
}
if (hasSchema) {
- snprintf(nameq, 256,
+ snprintf(nameq,
sizeof(nameq),
"AND
\"s\".\"name\" || '.' || \"o\".\"name\" LIKE '%s'",
line);
} else {
- snprintf(nameq, 256,
+ snprintf(nameq,
sizeof(nameq),
"AND
\"s\".\"name\" = \"current_schema\" "
"AND
\"o\".\"name\" LIKE '%s'",
line);
}
- snprintf(q, 2048,
+ if (hassysfuncs == YES) {
+ snprintf(funcq,
sizeof(funcq),
+ "SELECT
\"o\".\"name\", "
+ "(CASE
WHEN \"sf\".\"function_id\" IS NOT NULL "
+
"THEN 'SYSTEM ' "
+
"ELSE '' END "
+ "||
'FUNCTION') AS \"type\", "
+
"CASE WHEN \"sf\".\"function_id\" IS NULL "
+
"THEN false "
+
"ELSE true END AS \"system\", "
+
"\"s\".\"name\" AS \"sname\", "
+ "%d
AS \"ntype\" "
+ "FROM
\"sys\".\"functions\" \"o\" "
+ "LEFT
JOIN \"sys\".\"systemfunctions\" \"sf\" "
+ "ON
\"o\".\"id\" = \"sf\".\"function_id\", "
+
"\"sys\".\"schemas\" \"s\" "
+ "WHERE
\"o\".\"schema_id\" = \"s\".\"id\" "
+ "%s ",
+ MD_FUNC,
+ nameq);
+ } else {
+ snprintf(funcq,
sizeof(funcq),
+ "SELECT
\"o\".\"name\", "
+ "(CASE
WHEN \"o\".\"id\" <= 2000 "
+
"THEN 'SYSTEM ' "
+
"ELSE '' END "
+ "||
'FUNCTION') AS \"type\", "
+
"CASE WHEN \"o\".\"id\" > 2000 "
+
"THEN false "
+
"ELSE true END AS \"system\", "
+
"\"s\".\"name\" AS \"sname\", "
+ "%d
AS \"ntype\" "
+ "FROM
\"sys\".\"functions\" \"o\", "
+
"\"sys\".\"schemas\" \"s\" "
+ "WHERE
\"o\".\"schema_id\" = \"s\".\"id\" "
+ "%s ",
+ MD_FUNC,
+ nameq);
+ }
+ snprintf(q, sizeof(q),
"SELECT
\"name\", "
"CAST(\"type\" AS VARCHAR(30)) AS \"type\", "
"\"system\", \"sname\", "
@@ -2118,22 +2165,7 @@
"WHERE
\"o\".\"schema_id\" = \"s\".\"id\" "
"%s "
"UNION "
- "SELECT
\"o\".\"name\", "
- "(CASE
WHEN \"sf\".\"function_id\" IS NOT NULL "
-
"THEN 'SYSTEM ' "
-
"ELSE '' END "
- "||
'FUNCTION') AS \"type\", "
-
"CASE WHEN \"sf\".\"function_id\" IS NULL "
-
"THEN false "
-
"ELSE true END AS \"system\", "
-
"\"s\".\"name\" AS \"sname\", "
- "%d
AS \"ntype\" "
- "FROM
\"sys\".\"functions\" \"o\" "
- "LEFT
JOIN \"sys\".\"systemfunctions\" \"sf\" "
- "ON
\"o\".\"id\" = \"sf\".\"function_id\", "
-
"\"sys\".\"schemas\" \"s\" "
- "WHERE
\"o\".\"schema_id\" = \"s\".\"id\" "
- "%s "
+ "%s "
"UNION "
"SELECT NULL AS
\"name\", "
"(CASE
WHEN \"o\".\"name\" LIKE 'sys' "
@@ -2155,8 +2187,7 @@
nameq,
MD_SEQ,
nameq,
- MD_FUNC,
- nameq,
+ funcq,
MD_SCHEMA,
line,
x,
diff -r 3375a722bb1e -r 35db1c518074 clients/src/mapiclient/msqldump.h
--- a/clients/src/mapiclient/msqldump.h Fri Dec 10 13:52:46 2010 +0100
+++ b/clients/src/mapiclient/msqldump.h Fri Dec 10 14:29:40 2010 +0100
@@ -25,3 +25,4 @@
extern int dump_functions(Mapi mid, stream *toConsole, const char *sname,
const char *fname);
extern int dump_database(Mapi mid, stream *toConsole, int describe, const char
useInserts);
extern void dump_version(Mapi mid, stream *toConsole, const char *prefix);
+extern int has_systemfunctions(Mapi mid);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list
