Changeset: db0f45fabda6 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=db0f45fabda6 Modified Files: clients/ChangeLog clients/src/mapiclient/dump.c clients/src/mapiclient/mclient.c clients/src/mapiclient/msqldump.c clients/src/mapiclient/msqldump.h Branch: default Log Message:
Allow to dump functions, or list them, using \df[S] diffs (249 lines): diff -r 886d87916d39 -r db0f45fabda6 clients/ChangeLog --- a/clients/ChangeLog Thu Nov 25 15:36:31 2010 +0100 +++ b/clients/ChangeLog Thu Nov 25 15:57:47 2010 +0100 @@ -2,6 +2,7 @@ # This file is updated with Maddlog * 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 * Mon Nov 22 2010 Fabian Groffen <[email protected]> diff -r 886d87916d39 -r db0f45fabda6 clients/src/mapiclient/dump.c --- a/clients/src/mapiclient/dump.c Thu Nov 25 15:36:31 2010 +0100 +++ b/clients/src/mapiclient/dump.c Thu Nov 25 15:57:47 2010 +0100 @@ -1112,7 +1112,7 @@ } static int -dump_external_functions(Mapi mid, stream *toConsole) +dump_external_functions(Mapi mid, const char *schema, const char *fname, stream *toConsole, const char dumpSystem) { const char functions[] = "SELECT \"f\".\"id\"," @@ -1123,12 +1123,15 @@ "\"a\".\"type\"," "\"a\".\"type_digits\"," "\"a\".\"type_scale\"," - "\"a\".\"number\" " + "\"a\".\"number\", " + "\"s\".\"name\" " "FROM \"sys\".\"args\" \"a\"," - "\"sys\".\"functions\" \"f\" " + "\"sys\".\"functions\" \"f\", " + "\"sys\".\"schemas\" \"s\" " "WHERE \"f\".\"sql\" = FALSE AND " "\"a\".\"func_id\" = \"f\".\"id\" AND " - "\"f\".\"id\" %s " + "\"f\".\"schema_id\" = \"s\".\"id\" " + "%s %s " "ORDER BY \"f\".\"id\", \"a\".\"number\""; char query[512]; MapiHdl hdl; @@ -1142,7 +1145,8 @@ char *sep = NULL; snprintf(query, sizeof(query), functions, - has_systemfunctions(mid) ? "NOT IN (SELECT \"function_id\" FROM \"sys\".\"systemfunctions\")" : "> 2000"); + dumpSystem ? "" : "AND \"f\".\"id\"", + dumpSystem ? "" : has_systemfunctions(mid) ? "NOT IN (SELECT \"function_id\" FROM \"sys\".\"systemfunctions\")" : "> 2000"); if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) goto bailout; while (!mnstr_errnr(toConsole) && mapi_fetch_row(hdl) != 0) { @@ -1155,6 +1159,12 @@ char *a_type_digits = mapi_fetch_field(hdl, 6); char *a_type_scale = mapi_fetch_field(hdl, 7); char *a_number = mapi_fetch_field(hdl, 8); + char *s_name = mapi_fetch_field(hdl, 9); + + if (schema != NULL && strcmp(s_name, schema) != 0) + continue; + if (fname != NULL && strcmp(f_name, fname) != 0) + continue; if (prev_f_id == NULL || strcmp(prev_f_id, f_id) != 0) { if (prev_f_id) { @@ -1232,26 +1242,48 @@ } int -dump_functions(Mapi mid, stream *toConsole, const char *sname) +dump_functions(Mapi mid, stream *toConsole, const char *sname, const char *fname) { const char functions[] = - "SELECT \"f\".\"func\" " + "SELECT \"f\".\"func\", \"f\".\"name\", \"s\".\"name\" " "FROM \"sys\".\"schemas\" \"s\"," "\"sys\".\"functions\" \"f\" " - "WHERE \"f\".\"id\" %s AND " + "WHERE \"f\".\"sql\" = TRUE AND " "\"s\".\"id\" = \"f\".\"schema_id\"" + "%s %s " "%s%s%s " "ORDER BY \"f\".\"id\""; MapiHdl hdl; char *q; size_t l; + char dumpSystem; - if (dump_external_functions(mid, toConsole)) + if (sname == NULL) { + char *schema; + if (fname == NULL) { + schema = NULL; + } else if ((schema = strchr(fname, '.')) != NULL) { + size_t len = schema - fname; + + schema = malloc(len + 1); + strncpy(schema, fname, len); + schema[len] = 0; + fname += len + 1; + } else if ((schema = get_schema(mid)) == NULL) { + return 1; + } + sname = schema; + } + + dumpSystem = sname && fname; + + if (dump_external_functions(mid, sname, fname, toConsole, dumpSystem)) return 1; l = sizeof(functions) + (sname ? strlen(sname) : 0) + 100; q = malloc(l); snprintf(q, l, functions, - has_systemfunctions(mid) ? "NOT IN (SELECT \"function_id\" FROM \"sys\".\"systemfunctions\")" : "> 2000", + dumpSystem ? "" : "AND \"f\".\"id\"", + dumpSystem ? "" : has_systemfunctions(mid) ? "NOT IN (SELECT \"function_id\" FROM \"sys\".\"systemfunctions\")" : "> 2000", sname ? " AND \"s\".\"name\" = '" : "", sname ? sname : "", sname ? "'" : ""); @@ -1259,9 +1291,15 @@ free(q); if (hdl == NULL || mapi_error(mid)) goto bailout; - while (!mnstr_errnr(toConsole) && - mapi_fetch_row(hdl) != 0) { + while (!mnstr_errnr(toConsole) && mapi_fetch_row(hdl) != 0) { char *query = mapi_fetch_field(hdl, 0); + char *f_name = mapi_fetch_field(hdl, 1); + char *s_name = mapi_fetch_field(hdl, 2); + + if (sname != NULL && strcmp(sname, s_name) != 0) + continue; + if (fname != NULL && strcmp(fname, f_name) != 0) + continue; mnstr_printf(toConsole, "%s\n", query); } @@ -1604,7 +1642,7 @@ hdl = NULL; /* dump tables and functions */ - if (dump_external_functions(mid, toConsole)) + if (dump_external_functions(mid, NULL, NULL, toConsole, 0)) goto bailout; snprintf(query, sizeof(query), tables_and_functions, has_systemfunctions(mid) ? "AND \"f\".\"id\" NOT IN (SELECT \"function_id\" FROM \"sys\".\"systemfunctions\") " : ""); diff -r 886d87916d39 -r db0f45fabda6 clients/src/mapiclient/mclient.c --- a/clients/src/mapiclient/mclient.c Thu Nov 25 15:36:31 2010 +0100 +++ b/clients/src/mapiclient/mclient.c Thu Nov 25 15:57:47 2010 +0100 @@ -2053,13 +2053,15 @@ describe_table(mid, NULL, line, toConsole, 1); if (x & MD_SEQ) describe_sequence(mid, NULL, line, toConsole); + if (x & MD_FUNC) + dump_functions(mid, toConsole, NULL, line); #ifdef HAVE_POPEN end_pager(saveFD, saveFD_raw); #endif } else { /* get all object names in current schema */ char *type, *name, *schema; - char q[1024]; + char q[2048]; char nameq[256]; if (!*line) { line = "%"; @@ -2075,7 +2077,7 @@ "AND \"o\".\"name\" LIKE '%s'", line); } - snprintf(q, 1024, + snprintf(q, 2048, "SELECT \"name\", " "CAST(\"type\" AS VARCHAR(30)) AS \"type\", " "\"system\", \"sname\", " @@ -2101,7 +2103,7 @@ "FROM \"sys\".\"_tables\" \"o\", " "\"sys\".\"schemas\" \"s\" " "WHERE \"o\".\"schema_id\" = \"s\".\"id\" " - "%s %s " + "%s " "AND \"o\".\"type\" IN (0, 1) " "UNION " "SELECT \"o\".\"name\", " @@ -2113,17 +2115,37 @@ "\"sys\".\"schemas\" \"s\" " "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 " ") AS \"all\" " "WHERE \"ntype\" & %d > 0 " + "%s " "ORDER BY \"system\", \"name\"", MD_TABLE, MD_VIEW, nameq, + MD_SEQ, + nameq, + MD_FUNC, + nameq, + x, (wantsSystem ? "" : - "AND \"o\".\"system\" = false"), - MD_SEQ, - nameq, - x); + "AND \"system\" = false")); hdl = mapi_query(mid, q); CHECK_RESULT(mid, hdl, buf, continue); while (fetch_row(hdl) == 5) { diff -r 886d87916d39 -r db0f45fabda6 clients/src/mapiclient/msqldump.c --- a/clients/src/mapiclient/msqldump.c Thu Nov 25 15:36:31 2010 +0100 +++ b/clients/src/mapiclient/msqldump.c Thu Nov 25 15:57:47 2010 +0100 @@ -258,7 +258,7 @@ dump_version(mid, out, "--"); } if (functions) - c = dump_functions(mid, out, NULL); + c = dump_functions(mid, out, NULL, NULL); else c = dump_database(mid, out, describe); mnstr_flush(out); diff -r 886d87916d39 -r db0f45fabda6 clients/src/mapiclient/msqldump.h --- a/clients/src/mapiclient/msqldump.h Thu Nov 25 15:36:31 2010 +0100 +++ b/clients/src/mapiclient/msqldump.h Thu Nov 25 15:57:47 2010 +0100 @@ -21,6 +21,6 @@ extern int describe_sequence(Mapi mid, char *schema, 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); +extern int dump_functions(Mapi mid, stream *toConsole, const char *sname, const char *fname); extern int dump_database(Mapi mid, stream *toConsole, int describe); extern void dump_version(Mapi mid, stream *toConsole, const char *prefix); _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
