Changeset: d723e3582935 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d723e3582935
Modified Files:
        clients/ChangeLog
        clients/src/mapiclient/dump.c
        clients/src/mapiclient/mclient.c
        clients/src/mapiclient/msqldump.h
Branch: default
Log Message:

Added support for \dn to list schemas or describe a specific one.

(it doesn't really cool down the high temperature and fireworks here,
but at least it is something productive)


diffs (132 lines):

diff -r b00f5f33afd3 -r d723e3582935 clients/ChangeLog
--- a/clients/ChangeLog Wed Dec 08 16:18:06 2010 +0100
+++ b/clients/ChangeLog Wed Dec 08 18:03:22 2010 +0100
@@ -1,6 +1,9 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Wed Dec  8 2010 Fabian Groffen <[email protected]>
+- Added support for \dn to list schemas or describe a specific one
+
 * Thu Nov 25 2010 Fabian Groffen <[email protected]>
 - Added support for \df to list functions or describe a specific one
 - Added support for \ds to list sequences or describe a specific one
diff -r b00f5f33afd3 -r d723e3582935 clients/src/mapiclient/dump.c
--- a/clients/src/mapiclient/dump.c     Wed Dec 08 16:18:06 2010 +0100
+++ b/clients/src/mapiclient/dump.c     Wed Dec 08 18:03:22 2010 +0100
@@ -961,6 +961,49 @@
 }
 
 int
+describe_schema(Mapi mid, char *sname, stream *toConsole)
+{
+       MapiHdl hdl = NULL;
+       char schemas[256];
+
+       snprintf(schemas, 256,
+               "SELECT \"s\".\"name\", \"a\".\"name\" "
+               "FROM \"sys\".\"schemas\" \"s\", "
+                    "\"sys\".\"auths\" \"a\" "
+               "WHERE \"s\".\"authorization\" = \"a\".\"id\" AND "
+                     "\"s\".\"name\" = '%s' "
+               "ORDER BY \"s\".\"name\"",
+               sname);
+
+       if ((hdl = mapi_query(mid, schemas)) == NULL || mapi_error(mid)) {
+               if (hdl) {
+                       if (mapi_result_error(hdl))
+                               mapi_explain_result(hdl, stderr);
+                       else
+                               mapi_explain_query(hdl, stderr);
+                       mapi_close_handle(hdl);
+               } else
+                       mapi_explain(mid, stderr);
+
+               return 1;
+       }
+
+       while (mapi_fetch_row(hdl) != 0) {
+               char *sname = mapi_fetch_field(hdl, 0);
+               char *aname = mapi_fetch_field(hdl, 1);
+
+               mnstr_printf(toConsole, "CREATE SCHEMA \"%s\"", sname);
+               if (strcmp(aname, "sysadmin") != 0) {
+                       mnstr_printf(toConsole,
+                                        " AUTHORIZATION \"%s\"", aname);
+               }
+               mnstr_printf(toConsole, ";\n");
+       }
+
+       return 0;
+}
+
+int
 dump_table_data(Mapi mid, char *schema, char *tname, stream *toConsole)
 {
        int cnt, i;
diff -r b00f5f33afd3 -r d723e3582935 clients/src/mapiclient/mclient.c
--- a/clients/src/mapiclient/mclient.c  Wed Dec 08 16:18:06 2010 +0100
+++ b/clients/src/mapiclient/mclient.c  Wed Dec 08 18:03:22 2010 +0100
@@ -2055,6 +2055,8 @@
                                                        describe_sequence(mid, 
NULL, line, toConsole);
                                                if (x & MD_FUNC)
                                                        dump_functions(mid, 
toConsole, NULL, line);
+                                               if (x & MD_SCHEMA)
+                                                       describe_schema(mid, 
line, toConsole);
 #ifdef HAVE_POPEN
                                                end_pager(saveFD, saveFD_raw);
 #endif
@@ -2132,6 +2134,19 @@
                                                                          
"\"sys\".\"schemas\" \"s\" "
                                                                "WHERE 
\"o\".\"schema_id\" = \"s\".\"id\" "
                                                                  "%s "
+                                                               "UNION "
+                                                               "SELECT NULL AS 
\"name\", "
+                                                                      "(CASE 
WHEN \"o\".\"name\" LIKE 'sys' "
+                                                                           
"THEN 'SYSTEM ' "
+                                                                               
"ELSE '' END "
+                                                                               
"|| 'SCHEMA') AS \"type\", "
+                                                                          
"CASE WHEN \"o\".\"name\" LIKE 'sys' "
+                                                                          
"THEN true "
+                                                                          
"ELSE false END AS \"system\", "
+                                                                          
"\"o\".\"name\" AS \"sname\", "
+                                                                          "%d 
AS \"ntype\" "
+                                                               "FROM 
\"sys\".\"schemas\" \"o\" "
+                                                               "WHERE 
\"o\".\"name\" LIKE '%s' "
                                                                ") AS \"all\" "
                                                                "WHERE 
\"ntype\" & %u > 0 "
                                                                  "%s "
@@ -2142,6 +2157,8 @@
                                                                nameq,
                                                                MD_FUNC,
                                                                nameq,
+                                                               MD_SCHEMA,
+                                                               line,
                                                                x,
                                                                (wantsSystem ?
                                                                  "" :
@@ -2153,9 +2170,11 @@
                                                        type = 
mapi_fetch_field(hdl, 1);
                                                        schema = 
mapi_fetch_field(hdl, 3);
                                                        mnstr_printf(toConsole,
-                                                                         "%-*s 
 %s.%s\n",
+                                                                         "%-*s 
 %s%s%s\n",
                                                                          
mapi_get_len(hdl, 1),
-                                                                         type, 
schema, name);
+                                                                         type, 
schema,
+                                                                         name 
!= NULL ? "." : "",
+                                                                         name 
!= NULL ? name : "");
                                                }
                                                mapi_close_handle(hdl);
                                                hdl = NULL;
diff -r b00f5f33afd3 -r d723e3582935 clients/src/mapiclient/msqldump.h
--- a/clients/src/mapiclient/msqldump.h Wed Dec 08 16:18:06 2010 +0100
+++ b/clients/src/mapiclient/msqldump.h Wed Dec 08 18:03:22 2010 +0100
@@ -19,6 +19,7 @@
 
 extern int describe_table(Mapi mid, char *schema, char *tname, stream 
*toConsole, int foreign);
 extern int describe_sequence(Mapi mid, char *schema, char *sname, stream 
*toConsole);
+extern int describe_schema(Mapi mid, char *sname, stream *toConsole);
 extern int dump_table_data(Mapi mid, char *schema, char *tname, stream 
*toConsole);
 extern int dump_table(Mapi mid, char *schema, char *tname, stream *toConsole, 
int describe, int foreign);
 extern int dump_functions(Mapi mid, stream *toConsole, const char *sname, 
const char *fname);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to