Changeset: 5408dd2f90a1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5408dd2f90a1
Modified Files:
Branch: default
Log Message:
Merge it
diffs (truncated from 535 to 300 lines):
diff -r 3de8927d961b -r 5408dd2f90a1 MonetDB5/configure.ag
--- a/MonetDB5/configure.ag Sat Dec 11 17:37:44 2010 +0100
+++ b/MonetDB5/configure.ag Sat Dec 11 17:38:20 2010 +0100
@@ -214,7 +214,7 @@
AC_CHECK_LIB(sphinxclient, sphinx_create,
AC_DEFINE(HAVE_SPHINXCLIENT, 1, [Define if you have the
sphinxclient library])
have_sphinxclient=yes
- SPHINXCLIENT_LIBS="SPHINXCLIENT_LIBS -lsphinxclient",
+ SPHINXCLIENT_LIBS="$SPHINXCLIENT_LIBS -lsphinxclient",
[ if test "x$have_sphinxclient" != xauto; then
AC_MSG_ERROR([-lsphinxclient library not found]); fi; have_sphinxclient=no ]),
[ if test "x$have_sphinxclient" != xauto; then
AC_MSG_ERROR([sphinxclient.h header not found]); fi; have_sphinxclient=no ])
LDFLAGS="$save_LDFLAGS"
diff -r 3de8927d961b -r 5408dd2f90a1 clients/ChangeLog
--- a/clients/ChangeLog Sat Dec 11 17:37:44 2010 +0100
+++ b/clients/ChangeLog Sat Dec 11 17:38:20 2010 +0100
@@ -1,6 +1,11 @@
# ChangeLog file for clients
# This file is updated with Maddlog
+* Fri Dec 10 2010 Fabian Groffen <[email protected]>
+- Allow to dump table data using INSERT INTO statements, rather than COPY
+ INTO + CSV data using the -N/--inserts flag of mclient and msqldump.
+ Bug #2727
+
* Wed Dec 8 2010 Fabian Groffen <[email protected]>
- Added support for \dn to list schemas or describe a specific one
diff -r 3de8927d961b -r 5408dd2f90a1 clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c Sat Dec 11 17:37:44 2010 +0100
+++ b/clients/src/mapiclient/dump.c Sat Dec 11 17:38:20 2010 +0100
@@ -34,14 +34,23 @@
#endif
static void
-quoted_print(stream *f, const char *s)
+quoted_print(stream *f, const char *s, const char singleq)
{
- mnstr_write(f, "\"", 1, 1);
+ mnstr_write(f, singleq ? "'" : "\"", 1, 1);
while (*s) {
switch (*s) {
case '\\':
+ mnstr_write(f, "\\", 1, 1);
+ mnstr_write(f, s, 1, 1);
+ break;
case '"':
- mnstr_write(f, "\\", 1, 1);
+ if (!singleq)
+ mnstr_write(f, "\\", 1, 1);
+ mnstr_write(f, s, 1, 1);
+ break;
+ case '\'':
+ if (singleq)
+ mnstr_write(f, "\\", 1, 1);
mnstr_write(f, s, 1, 1);
break;
case '\n':
@@ -59,7 +68,7 @@
}
s++;
}
- mnstr_write(f, "\"", 1, 1);
+ mnstr_write(f, singleq ? "'" : "\"", 1, 1);
}
static char *actions[] = {
@@ -105,7 +114,7 @@
return NULL;
}
-static int
+int
has_systemfunctions(Mapi mid)
{
MapiHdl hdl;
@@ -1004,7 +1013,8 @@
}
int
-dump_table_data(Mapi mid, char *schema, char *tname, stream *toConsole)
+dump_table_data(Mapi mid, char *schema, char *tname, stream *toConsole,
+ const char useInserts)
{
int cnt, i;
MapiHdl hdl = NULL;
@@ -1042,9 +1052,9 @@
goto bailout;
if (mapi_rows_affected(hdl) != 1) {
if (mapi_rows_affected(hdl) == 0)
- fprintf(stderr, "Table %s.%s does not exist.\n",
schema, tname);
+ fprintf(stderr, "table '%s.%s' does not exist\n",
schema, tname);
else
- fprintf(stderr, "Table %s.%s not unique.\n", schema,
tname);
+ fprintf(stderr, "table '%s.%s' is not unique\n",
schema, tname);
goto bailout;
}
while ((mapi_fetch_row(hdl)) != 0) {
@@ -1058,25 +1068,27 @@
mapi_close_handle(hdl);
hdl = NULL;
- snprintf(query, maxquerylen, "SELECT count(*) FROM \"%s\".\"%s\"",
- schema, tname);
- if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
- goto bailout;
- if (mapi_fetch_row(hdl)) {
- char *cntfld = mapi_fetch_field(hdl, 0);
+ if (!useInserts) {
+ snprintf(query, maxquerylen, "SELECT count(*) FROM
\"%s\".\"%s\"",
+ schema, tname);
+ if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
+ goto bailout;
+ if (mapi_fetch_row(hdl)) {
+ char *cntfld = mapi_fetch_field(hdl, 0);
- if (strcmp(cntfld, "0") == 0) {
- /* no records to dump, so return early */
- goto doreturn;
+ if (strcmp(cntfld, "0") == 0) {
+ /* no records to dump, so return early */
+ goto doreturn;
+ }
+
+ mnstr_printf(toConsole,
+ "COPY %s RECORDS INTO \"%s\".\"%s\" "
+ "FROM stdin USING DELIMITERS
'\\t','\\n','\"';\n",
+ cntfld, schema, tname);
}
-
- mnstr_printf(toConsole,
- "COPY %s RECORDS INTO \"%s\".\"%s\" "
- "FROM stdin USING DELIMITERS '\\t','\\n','\"';\n",
- cntfld, schema, tname);
+ mapi_close_handle(hdl);
+ hdl = NULL;
}
- mapi_close_handle(hdl);
- hdl = NULL;
snprintf(query, maxquerylen, "SELECT * FROM \"%s\".\"%s\"",
schema, tname);
@@ -1096,20 +1108,32 @@
while (mapi_fetch_row(hdl)) {
char *s;
+ if (useInserts)
+ mnstr_printf(toConsole, "INSERT INTO \"%s\".\"%s\"
VALUES (",
+ schema, tname);
+
for (i = 0; i < cnt; i++) {
s = mapi_fetch_field(hdl, i);
if (s == NULL)
mnstr_printf(toConsole, "NULL");
else if (string[i]) {
- /* write double-quoted string with
+ /* write double or single-quoted string with
certain characters escaped */
- quoted_print(toConsole, s);
+ quoted_print(toConsole, s, useInserts);
} else
mnstr_printf(toConsole, "%s", s);
- if (i < cnt - 1)
- mnstr_write(toConsole, "\t", 1, 1);
- else
- mnstr_write(toConsole, "\n", 1, 1);
+
+ if (useInserts) {
+ if (i < cnt - 1)
+ mnstr_printf(toConsole, ", ");
+ else
+ mnstr_printf(toConsole, ");\n");
+ } else {
+ if (i < cnt - 1)
+ mnstr_write(toConsole, "\t", 1, 1);
+ else
+ mnstr_write(toConsole, "\n", 1, 1);
+ }
}
if (mnstr_errnr(toConsole))
goto bailout;
@@ -1144,13 +1168,13 @@
}
int
-dump_table(Mapi mid, char *schema, char *tname, stream *toConsole, int
describe, int foreign)
+dump_table(Mapi mid, char *schema, char *tname, stream *toConsole, int
describe, int foreign, const char useInserts)
{
int rc;
rc = describe_table(mid, schema, tname, toConsole, foreign);
if (rc == 0 && !describe)
- rc = dump_table_data(mid, schema, tname, toConsole);
+ rc = dump_table_data(mid, schema, tname, toConsole, useInserts);
return rc;
}
@@ -1364,7 +1388,7 @@
}
int
-dump_database(Mapi mid, stream *toConsole, int describe)
+dump_database(Mapi mid, stream *toConsole, int describe, const char useInserts)
{
const char *start = "START TRANSACTION";
const char *end = "ROLLBACK";
@@ -1715,7 +1739,7 @@
if (schema)
schema = strdup(schema);
tname = strdup(tname);
- rc = dump_table(mid, schema, tname, toConsole,
describe, describe);
+ rc = dump_table(mid, schema, tname, toConsole,
describe, describe, useInserts);
if (schema)
free(schema);
free(tname);
diff -r 3de8927d961b -r 5408dd2f90a1 clients/src/mapiclient/mclient.1
--- a/clients/src/mapiclient/mclient.1 Sat Dec 11 17:37:44 2010 +0100
+++ b/clients/src/mapiclient/mclient.1 Sat Dec 11 17:38:20 2010 +0100
@@ -218,6 +218,12 @@
.TP
\fB\-\-dump\fP (\fB\-D\fP)
Create an SQL dump.
+.TP
+\fB\-\-inserts\fP (\fB\-N\fP)
+Use INSERT INTO statements instead of COPY INTO + CSV values when
+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.
.SS
XQuery Options
.TP
@@ -365,10 +371,11 @@
The object can be given with or without a schema, separated by a dot.
The object name
can contain the wildcard characters \fB*\fP and \fB_\fP that represent
-zero or more, and exactly a single character respectively. An object
+zero or more, and exactly one character respectively. An object
name is converted to lowercase, unless the object name is quoted by
-double quotes (\fB"\fP). Examples of this, are e.g. \fI*.mytable\fP or
-\fItabletype*\fP.
+double quotes (\fB"\fP). Examples of this, are e.g. \fI*.mytable\fP,
+\fItabletype*\fP or \fI"myschema.FOO"\fP. Note that wildcard characters
+do not work in quoted objects.
.TP
\fB\eA\fP
Enable auto commit mode.
diff -r 3de8927d961b -r 5408dd2f90a1 clients/src/mapiclient/mclient.c
--- a/clients/src/mapiclient/mclient.c Sat Dec 11 17:37:44 2010 +0100
+++ b/clients/src/mapiclient/mclient.c Sat Dec 11 17:38:20 2010 +0100
@@ -1768,8 +1768,10 @@
#define MD_FUNC 8
#define MD_SCHEMA 16
+enum hmyesno { UNKNOWN, YES, NO };
+
static int
-doFileByLines(Mapi mid, FILE *fp, const char *prompt)
+doFileByLines(Mapi mid, FILE *fp, const char *prompt, const char useinserts)
{
char *line = NULL;
char *oldbuf = NULL, *buf = NULL;
@@ -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),
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list