Changeset: a6c47ad22cca for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a6c47ad22cca Added Files: sql/backends/monet5/mal_backend.c sql/backends/monet5/mal_backend.h Modified Files: sql/backends/monet5/Makefile.ag sql/backends/monet5/datacell/basket.c sql/backends/monet5/datacell/datacell.c sql/backends/monet5/rest/rest_jsonstore_handle_get.c sql/backends/monet5/sql.mx sql/backends/monet5/sql_gencode.h sql/backends/monet5/sql_result.c sql/backends/monet5/sql_result.h sql/backends/monet5/sql_scenario.c sql/backends/monet5/vaults/fits.c Branch: default Log Message:
made is possible to output JSON instead of CSV (json output needs work) diffs (truncated from 1331 to 300 lines): diff --git a/sql/backends/monet5/Makefile.ag b/sql/backends/monet5/Makefile.ag --- a/sql/backends/monet5/Makefile.ag +++ b/sql/backends/monet5/Makefile.ag @@ -37,6 +37,7 @@ lib__sql = { DIR = libdir/monetdb5 SOURCES = \ sql.mx \ + mal_backend.c mal_backend.h \ sql_user.c sql_user.h \ sql_scenario.c sql_scenario.h \ rel_bin.c rel_bin.h \ diff --git a/sql/backends/monet5/datacell/basket.c b/sql/backends/monet5/datacell/basket.c --- a/sql/backends/monet5/datacell/basket.c +++ b/sql/backends/monet5/datacell/basket.c @@ -179,7 +179,7 @@ BSKTregister(Client cntxt, MalBlkPtr mb, BSKTtolower(ltbl); - if (msg != MAL_SUCCEED) + if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED) return msg; tr = m->session->tr; diff --git a/sql/backends/monet5/datacell/datacell.c b/sql/backends/monet5/datacell/datacell.c --- a/sql/backends/monet5/datacell/datacell.c +++ b/sql/backends/monet5/datacell/datacell.c @@ -60,7 +60,7 @@ DCprocedureStmt(Client cntxt, MalBlkPtr sql_func *f; /*sql_trans *tr;*/ - if (msg) + if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED) return msg; s = mvc_bind_schema(m, schema); if (s == NULL) @@ -109,7 +109,7 @@ DCinitialize(Client cntxt, MalBlkPtr mb, sql_func *f; sql_trans *tr; - if (msg) + if ((msg = checkSQLContext(cntxt)) != MAL_SUCCEED) return msg; assert(m != NULL); diff --git a/sql/backends/monet5/mal_backend.c b/sql/backends/monet5/mal_backend.c new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/mal_backend.c @@ -0,0 +1,37 @@ + +#include "monetdb_config.h" +#include "sql.h" +#include "mal_backend.h" + +backend * +backend_reset(backend *b) +{ + b->out = b->client->fdout; + b->language = 0; + + b->vtop = 0; + b->q = NULL; + b->mvc_var = 0; + b->output_format = OFMT_CSV; + return b; +} + +backend * +backend_create(mvc *m, Client c) +{ + backend *b = NEW(backend); + + b->console = isAdministrator(c); + b->mvc = m; + b->client = c; + b->mvc_var = 0; + b->output_format = OFMT_CSV; + return backend_reset(b); +} + +void +backend_destroy(backend *b) +{ + _DELETE(b); +} + diff --git a/sql/backends/monet5/mal_backend.h b/sql/backends/monet5/mal_backend.h new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/mal_backend.h @@ -0,0 +1,40 @@ +#ifndef MAL_BACKEND_H +#define MAL_BACKEND_H + +#include <streams.h> +#include <mal_client.h> +#include <sql_mvc.h> +#include <sql_qc.h> + +/* + * The back-end structure collects the information needed to support + * compilation and execution of the SQL code against the Monet Version 5 + * back end. Note that the back-end can be called upon by the front-end + * to handle specific tasks, such as catalog management (sql_mvc) + * and query execution (sql_qc). For this purpose, the front-end needs + * access to operations defined in the back-end, in particular for + * freeing the stack and code segment. + */ + +typedef enum output_format { + OFMT_CSV = 0, + OFMT_JSON = 1 +} ofmt; + +typedef struct backend { + int console; + char language; /* 'S' or 's' or 'X' */ + mvc *mvc; + stream *out; + ofmt output_format; /* csv, json */ + Client client; + int mvc_var; + int vtop; /* top of the variable stack before the current function */ + cq *q; /* pointer to the cached query */ +} backend; + +extern backend *backend_reset(backend *b); +extern backend *backend_create(mvc *m, Client c); +extern void backend_destroy(backend *b); + +#endif /*MAL_BACKEND_H*/ diff --git a/sql/backends/monet5/rest/rest_jsonstore_handle_get.c b/sql/backends/monet5/rest/rest_jsonstore_handle_get.c --- a/sql/backends/monet5/rest/rest_jsonstore_handle_get.c +++ b/sql/backends/monet5/rest/rest_jsonstore_handle_get.c @@ -26,6 +26,7 @@ #include "sql_scenario.h" #include <mapi.h> #include <rest_jsonstore_handle_get.h> +#include "mal_backend.h" static str RESTsqlQuery(char **result, char * query); char * result_ok = "select true as ok;"; @@ -41,6 +42,7 @@ RESTsqlQuery(char **result, char * query Client c; bstream *fin = NULL; int len = 0; + backend *be; resultbuffer = buffer_create(BLOCK); resultstream = buffer_wastream(resultbuffer, "resultstring"); @@ -53,6 +55,8 @@ RESTsqlQuery(char **result, char * query initLibraries(); msg = setScenario(c, "sql"); msg = SQLinitClient(c); + be = (backend*)c->sqlcontext; + be->output_format = OFMT_JSON; MSinitClientPrg(c, "user", "main"); (void) MCinitClientThread(c); diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx --- a/sql/backends/monet5/sql.mx +++ b/sql/backends/monet5/sql.mx @@ -1310,6 +1310,7 @@ sql.prelude(); #define sql5_export extern #endif +#include "mal_backend.h" #include "sql_mvc.h" #include <sql_backend.h> #include <mal_session.h> @@ -1336,37 +1337,6 @@ sql.prelude(); #include <bat/bat_storage.h> #include <bat/bat_utils.h> -/* - * @- - * The back-end structure collects the information needed to support - * compilation and execution of the SQL code against the Monet Version 5 - * back end. Note that the back-end can be called upon by the front-end - * to handle specific tasks, such as catalog management (sql_mvc) - * and query execution (sql_qc). For this purpose, the front-end needs - * access to operations defined in the back-end, in particular for - * freeing the stack and code segment. - * @- - */ -typedef struct backend { - int console; - char language; /* 'S' or 's' or 'X' */ - mvc *mvc; - stream *out; - Client client; - sql_schema *currSchema; - sql_table *currTable; - sql_column *currColumn; - sql_key *currKey; - sql_idx *currIndex; - int mvc_var; - int vtop; /* top of the variable stack before the current function */ - cq *q; /* pointer to the cached query */ -} backend; - -extern backend *backend_reset(backend *b); -extern backend *backend_create(mvc *m, Client c); -extern void backend_destroy(backend *b); - extern int sqlcleanup(mvc *c, int err); extern sql_rel *sql_symbol2relation(mvc *c, symbol *sym); extern stmt *sql_relation2stmt(mvc *c, sql_rel *r); @@ -1611,6 +1581,7 @@ sql5_export str bat@2_num2dec_@1( int *r @:numcastdown_export(int,lng)@ @:numcastdown_export(wrd,lng)@ +sql5_export str checkSQLContext(Client cntxt); sql5_export str getSQLContext(Client cntxt, MalBlkPtr mb, mvc **c, backend **b ); sql5_export void freeVariables(Client c, MalBlkPtr mb, MalStkPtr glb, int start); @@ -1671,41 +1642,6 @@ trunc(double val) } #endif -backend * -backend_reset(backend *b) -{ - b->out = b->client->fdout; - b->language = 0; - - b->currSchema = NULL; - b->currTable = NULL; - b->currColumn = NULL; - b->currKey = NULL; - b->currIndex = NULL; - b->vtop = 0; - b->q = NULL; - b->mvc_var = 0; - return b; -} - -backend * -backend_create(mvc *m, Client c) -{ - backend *b = NEW(backend); - - b->console = isAdministrator(c); - b->mvc = m; - b->client = c; - b->mvc_var = 0; - return backend_reset(b); -} - -void -backend_destroy(backend *b) -{ - _DELETE(b); -} - static int rel_is_table( sql_rel *rel ) { @@ -1855,27 +1791,41 @@ sqlcleanup(mvc *c, int err) } /* - * @- * The internal administration of the SQL compilation and execution state * is administered by a state descriptor accessible in each phase. * Failure to find the state descriptor aborts the session. */ -str -getSQLContext(Client cntxt, MalBlkPtr mb, mvc **c, backend **b) + +str +checkSQLContext(Client cntxt) { backend *be; - (void) mb; if (cntxt == NULL) throw(SQL, "mvc", "No client record"); if (cntxt->sqlcontext == NULL) throw(SQL, "mvc", "SQL module not initialized"); be = (backend *) cntxt->sqlcontext; - if (c) { + if (be->mvc == NULL) + throw(SQL, "mvc", "SQL module not initialized, mvc struct missing"); + return MAL_SUCCEED; +} + +str +getSQLContext(Client cntxt, MalBlkPtr mb, mvc **c, backend **b) +{ + backend *be; + (void) mb; + + if (cntxt == NULL) + throw(SQL, "mvc", "No client record"); + if (cntxt->sqlcontext == NULL) + throw(SQL, "mvc", "SQL module not initialized"); + be = (backend *) cntxt->sqlcontext; + if (be->mvc == NULL) + throw(SQL, "mvc", "SQL module not initialized, mvc struct missing"); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list