Changeset: dba2879f5230 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dba2879f5230
Added Files:
        clients/mapiclient/mhelp.c
Modified Files:
        clients/ChangeLog
        clients/mapiclient/mclient.c
Branch: default
Log Message:

Extends the mclient \help
The \help and \help *  commands provide access to a more elaborate
description of the SQL syntax accepted by MonetDB.
It does not yet cover the complete grammar, but is in line what other
systems provide. Next round for another 'free' day.


diffs (truncated from 705 to 300 lines):

diff --git a/clients/ChangeLog b/clients/ChangeLog
--- a/clients/ChangeLog
+++ b/clients/ChangeLog
@@ -1,3 +1,6 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Sun Oct 30 2016 Martin Kersten <[email protected]>
+- Added an more elaborate \help command for SQL expressions.
+
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -44,6 +44,7 @@
 #include "msqldump.h"
 #include "mprompt.h"
 #include "dotmonetdb.h"
+
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
@@ -188,6 +189,9 @@ static char *nullstring = default_nullst
 
 #define my_isspace(c)  ((c) == '\f' || (c) == '\n' || (c) == ' ')
 
+#include <ctype.h>
+#include "mhelp.c"
+
 static timertype
 gettime(void)
 {
@@ -2713,11 +2717,14 @@ doFile(Mapi mid, stream *fp, int useinse
                                        int h;
                                        char *nl;
 
-                                       for (h = 0; h < history_length; h++) {
-                                               nl = history_get(h) ? 
history_get(h)->line : 0;
-                                               if (nl)
-                                                       mnstr_printf(toConsole, 
"%d %s\n", h, nl);
-                                       }
+                                       if( strcmp(line,"\\history") ==0){
+                                               for (h = 0; h < history_length; 
h++) {
+                                                       nl = history_get(h) ? 
history_get(h)->line : 0;
+                                                       if (nl)
+                                                               
mnstr_printf(toConsole, "%d %s\n", h, nl);
+                                               }
+                                       } else
+                                               sql_help(line);
                                        continue;
                                }
 /* for later
diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c
new file mode 100644
--- /dev/null
+++ b/clients/mapiclient/mhelp.c
@@ -0,0 +1,649 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V.
+ */
+
+/**
+ * 2016 Martin Kersten
+ *
+ * The SQL syntax help synopsis.
+ */
+
+/* produce a synposis of the SQL syntax, inspired by a competing product */
+
+typedef struct{
+       char *command;
+       char *synopsis;
+       char *syntax;
+       char *rules;
+       char *comments;
+} SQLhelp;
+
+SQLhelp sqlhelp[]={
+       // major commands
+       { "ALTER TABLE",
+         "",
+         "ALTER TABLE qname ADD [ COLUMN ] { column_def | table_constraint }\n"
+         "ALTER TABLE qname ADD TABLE qname\n"
+         "ALTER TABLE qname ALTER alter_table_element\n"
+         "ALTER TABLE qname DROP drop_table_element\n"
+         "ALTER TABLE qname SET { { READ | INSERT } ONLY | READ WRITE }",
+         "column_def,table_constraint,alter_table_element,drop_table_element",
+       0
+       },
+       { "ALTER SEQUENCE",
+         "",
+         "ALTER SEQUENCE ident [ AS datatype] [ RESTART [WITH start]] 
[INCREMENT BY increment]\n"
+         "[MINVALUE minvalue | NO MINVALUE]  [MAXVALUE maxvalue | NOMAXVALUE] 
| [ [ NO] CYCLE]",
+         0,0
+       },
+       { "ALTER USER",
+         "",
+         "ALTER USER ident { password_scheme  | RENAME TO ident }",
+         "password_scheme", 0
+       },
+    { "ANALYZE",
+         "Collect statistics for optimizations",
+         "ANALYZE qname [column_list] [sample] [MINMAX]",
+         "column_list,sample",
+         0
+       },
+       { "CALL",
+         "",
+         "CALL qname '(' [ [scalar_expression ] [ ',' ...]  ]')' | CALL ident 
'.' ident",
+         0,0
+       },
+       { "CASE",
+         "",
+         "CASE  scalar_expression [ when_statement ...]  [ELSE 
procedure_statement ... ] END CASE",
+         0,0
+       },
+    { "COMMIT",
+         "Commit the current transaction",
+         "COMMIT [ WORK ] [ AND CHAIN | AND NO CHAIN ]",
+         0,0
+       },
+       { "COPY BINARY",
+         "",
+         "COPY [integer OFFSET] [integer RECORDS] BINARY INTO qname 
column_list FROM string_list [NO CONSTRAINT]",
+         "",
+         0
+       },
+       { "COPY INTO",
+         "",
+         "COPY query_expression INTO [STDOUT | string] [seps] [null_string]",
+         "seps",
+         0
+       },
+       { "COPY LOADER",
+         "",
+         "COPY LOADER INTO qname FROM qname '(' [ scalar_expression ... ] ')'",
+        0,0
+       },
+       { "CREATE AGGREGATE FUNCTION",
+         "",
+         "CREATE AGGREGATE  FUNCTION qname '(' { '*' | [ param [',' ...]] } 
')'\n"
+         "    RETURNS { data_type | TABLE '(' function_return [ ',' ... ] ')' 
}\n"
+         "    EXTERNAL NAME ident ',' ident\n"
+         "CREATE AGGREGATE FUNCTION qname '(' { '*' | [ param [',' ...]] 
}')'\n"
+         "    RETURNS { data_type | TABLE '(' function_return [ ',' ... ] ')' 
}\n"
+         "    LANGUAGE ident external_code",
+         "param,data_type,function_return",
+         0
+       },
+       { "CREATE FILTER FUNCTION",
+         "",
+         "CREATE FILTER  FUNCTION qname '(' { '*' | [ param [',' ...]] } ')'\n"
+         "    RETURNS { data_type | TABLE '(' function_return [ ',' ... ] ')' 
}\n"
+         "    EXTERNAL NAME ident ',' ident\n",
+         "param,data_type,function_return",
+         0
+       },
+       { "CREATE FUNCTION",
+         "",
+         "CREATE FUNCTION qname '(' { '*' | [ param [',' ...]] } ')'\n"
+         "    RETURNS { data_type | TABLE '(' function_return [ ',' ... ] ')' 
}\n"
+         "    EXTERNAL NAME ident ',' ident\n"
+         "CREATE FUNCTION qname '(' { '*' | [ param [',' ...]] } ')'\n"
+         "    RETURNS { data_type | TABLE '(' function_return [ ',' ... ] ')' 
}\n"
+         "    BEGIN [ ATOMIC ] statement [ ';' ...] END\n"
+         "CREATE FUNCTION qname '(' { '*' | [ param [',' ...]] }')'\n"
+         "    RETURNS { data_type | TABLE '(' function_return [ ',' ... ] ')' 
}\n"
+         "    LANGUAGE ident external_code",
+         "param,data_type,function_return,external_code",
+         0
+       },
+       { "CREATE INDEX",
+         "",
+         "CREATE [ UNIQUE | ORDERED | IMPRINTS ] INDEX ident ON qname '(' 
ident_list ')'",
+         0,0
+       },
+       { "CREATE PROCEDURE",
+         "",
+         "CREATE PROCEDURE qname '(' { '*' | [ param [',' ...]] }')'\n"
+         "    EXTERNAL NAME ident ',' ident\n"
+         "CREATE PROCEDURE qname '(' { '*' | [ param [',' ...]] } ')'\n"
+         "    BEGIN [ ATOMIC ] procedure_statement [ ';' ...] END\n"
+         "CREATE PROCEDURE qname '(' { '*' | [ param [',' ...]] } ')'\n"
+         "    LANGUAGE ident external_code\n",
+         "param,data_type,external_code",
+         0
+       },
+       { "CREATE LOADER",
+         "",
+         "CREATE LOADER qname '(' [ param [',' ...]] ')'\n"
+         "    LANGUAGE ident external_code\n",
+         "param,data_type,function_return,external_code",
+         0
+       },
+       { "CREATE REMOTE TABLE",
+         "",
+         "CREATE REMOTE TABLE qname ON string",
+        0,"remote name should match 
mapi:monetdb://host:port/database[/schema[/table]]"
+       },
+    { "CREATE SCHEMA",
+         "",
+         "CREATE SCHEMA schema_name [default_char_set] [path_spec] 
[schema_element]",
+         "schema_name,default_char_set,path_spec,schema_element",
+         0
+       },
+       { "CREATE SEQUENCE",
+         "Define a new sequence generator",
+         "CREATE SEQUENCE ident   [ AS datatype] [ START [WITH start]] 
[INCREMENT BY increment]\n"
+         "[MINVALUE minvalue | NO MINVALUE] [MAXVALUE maxvalue | NOMAXVALUE] | 
[ [ NO] CYCLE]",
+         0, 0
+       },
+       { "CREATE STREAM TABLE",
+         "",
+         "CREATE REMOTE TABLE qname ON string",
+        0,"Temporary table, locked during updates/ continues query processing"
+       },
+       { "CREATE TABLE",
+         "",
+         "CREATE TABLE qname table_source [STORAGE ident string]\n"
+         "CREATE TABLE qname FROM LOADER function_ref\n"
+         "CREATE REMOTE TABLE qname ON string"
+         "CREATE [ STREAM | MERGE | REPLICA ] TABLE qname table_source;"
+         "CREATE [ LOCAL | GLOBAL ] TEMP[ORARY] TABLE qname table_source 
[on_commit]\n",
+         "table_source,on_commit,function_ref",0
+       },
+       { "CREATE TRIGGER",
+         "",
+         "CREATE TRIGGER wname { BEFORE | AFTER } {INSERT | DELETE | UPDATE [ 
OF ident [',' ident]...\n"
+         "ON qname [REFERENCING trigger_reference... triggered_action",
+         "trigger_reference",
+         0
+       },
+       { "CREATE TYPE",
+         "",
+         "CREATE TYPE qname EXTERNAL NAME ident",
+         0,0
+       },
+       { "CREATE VIEW",
+         "",
+         "CREATE VIEW qname [ column_list ] AS { query_expression | '(' 
query_expression ') } [ WITH CHECK OPTION]",
+         "column_list,query_expression", 0
+       },
+       { "CURRENT_DATE",
+         "",
+         "CURRENT_DATE [ '(' ')']",
+        0,0
+       },
+       { "CURRENT_TIME",
+         "",
+         "CURRENT_TIME [ '(' ')']",
+        0,0
+       },
+       { "CURRENT_TIMESTAMP",
+         "",
+         "CURRENT_TIMESTAMP [ '(' ')']",
+        0,0
+       },
+       { "EXPLAIN",
+         "Give execution plan details",
+         "EXPLAIN statement",
+         0,0
+       },
+       { "LOCAL_TIMESTAMP",
+         "",
+         "LOCAL_TIMESTAMP [ '(' ')']",
+        0,0
+       },
+       { "EXTRACT",
+          "",
+         "EXTRACT '(' { YEAR | MONTH | DAY | HOUR | MINUTE | SECOND } FROM 
scalar_expression ')'",
+         0,0
+       },
+    { "DECLARE",
+         "Define a local variable",
+         "DECLARE ident_list data_type",
+         "ident_list,data_type",
+         0
+       },
+       { "DELETE",
+         "",
+         "[ WITH with_list] DELETE FROM qname [WHERE search_condition]",
+         "with_list,search_condition",
+         0
+       },
+       { "DROP AGGREGATE",
+         "",
+         "DROP AGGREGATE qname [ RESTRICT | CASCADE ]",
+         0,0
+       },
+       { "DROP FUNCTION",
+         "",
+         "DROP ALL [FILTER] FUNCTION qname [ RESTRICT | CASCADE ]\n"
+         "DROP routine_designator [ RESTRICT | CASCADE ]",
+         0,0
+       },
+       { "DROP INDEX",
+         "",
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to