Update of /cvsroot/monetdb/clients/src/mapiclient
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28843
Modified Files:
dump.c
Log Message:
Test that the to-be-dumped/described table exists.
Allow dumping/describing tables in other schemata (use e.g. \dsys.idxs
in MapiClient).
Index: dump.c
===================================================================
RCS file: /cvsroot/monetdb/clients/src/mapiclient/dump.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- dump.c 13 Aug 2007 12:29:16 -0000 1.12
+++ dump.c 14 Aug 2007 08:17:27 -0000 1.13
@@ -99,22 +99,68 @@
int
dump_table(Mapi mid, char *tname, FILE *toConsole, int describe)
{
- int cnt = 0, i;
+ int cnt, i;
MapiHdl hdl;
char *query;
size_t maxquerylen = BUFSIZ + strlen(tname);
int *string;
char *sname;
+ if ((sname = strchr(tname, '.')) != NULL) {
+ size_t len = sname - tname;
+
+ sname = malloc(len + 1);
+ strncpy(sname, tname, len);
+ sname[len] = 0;
+ tname += len + 1;
+ } else if ((sname = get_schema(mid)) == NULL) {
+ return 1;
+ }
+
query = malloc(maxquerylen);
+ snprintf(query, maxquerylen,
+ "SELECT \"t\".\"name\" "
+ "FROM \"sys\".\"_tables\" \"t\", \"sys\".\"schemas\" \"s\" "
+ "WHERE \"s\".\"name\" = '%s' "
+ "AND \"t\".\"schema_id\" = \"s\".\"id\" "
+ "AND \"t\".\"name\" = '%s'",
+ sname, tname);
- fprintf(toConsole, "CREATE TABLE ");
+ if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) {
+ if (hdl) {
+ mapi_explain_query(hdl, stderr);
+ mapi_close_handle(hdl);
+ } else
+ mapi_explain(mid, stderr);
+ free(query);
+ free(sname);
+ return 1;
+ }
+ cnt = 0;
+ while ((mapi_fetch_row(hdl)) != 0) {
+ cnt++;
+ }
+ if (mapi_error(mid)) {
+ mapi_explain_query(hdl, stderr);
+ mapi_close_handle(hdl);
+ free(query);
+ free(sname);
+ return 1;
+ }
+ mapi_close_handle(hdl);
- sname = get_schema(mid);
- if (sname == NULL) {
+ if (cnt != 1) {
+ if (cnt == 0)
+ fprintf(stderr, "Table %s.%s does not exist.\n", sname,
tname);
+ else
+ fprintf(stderr, "Table %s.%s not unique.\n", sname,
tname);
free(query);
+ free(sname);
return 1;
}
+
+ fprintf(toConsole, "CREATE TABLE ");
+
quoted_print(toConsole, sname);
free(sname);
fprintf(toConsole, ".");
@@ -148,6 +194,7 @@
return 1;
}
+ cnt = 0;
while ((mapi_fetch_row(hdl)) != 0) {
char *c_name = mapi_fetch_field(hdl, 0);
char *c_type = mapi_fetch_field(hdl, 1);
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins