Changeset: 4f55afd12fc1 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4f55afd12fc1 Modified Files: MonetDB5/src/mal/mal_linker.mx sql/src/backends/monet5/sql_scenario.mx sql/src/sql/Makefile.ag sql/src/sql/mtime.sql Branch: Jun2010 Log Message:
Backport of commit 8fce7ca36310 with modifications. Instead of doubling normal module lookup time, introduce a sql variant for "module" lookup. Prepare for initialization of every SQL database with sql scripts. author m...@cwi.nl date Fri May 07 14:26:18 2010 +0200 (6 days ago) diffs (148 lines): diff -r f928f414e85d -r 4f55afd12fc1 MonetDB5/src/mal/mal_linker.mx --- a/MonetDB5/src/mal/mal_linker.mx Thu May 13 19:03:24 2010 +0200 +++ b/MonetDB5/src/mal/mal_linker.mx Thu May 13 19:21:27 2010 +0200 @@ -48,6 +48,7 @@ #include "mal_module.h" #define MAL_EXT ".mal" +#define SQL_EXT ".sql" #ifdef HAVE_DLFCN_H #include <dlfcn.h> @@ -64,6 +65,7 @@ #define MONET64 1 mal_export MALfcn getAddress(str filename, str modnme, str fcnname,int silent); mal_export char *MSP_locate_script(const char *mod_name); +mal_export char *MSP_locate_sqlscript(const char *mod_name); mal_export char *MSP_locate_file(const char *mod_name); mal_export str loadLibrary(str modulename, int flag); mal_export void unloadLibraries(void); @@ -429,6 +431,13 @@ } char * +MSP_locate_sqlscript(const char *filename) +{ + /* no directory semantics (yet) */ + return locate_file(filename, SQL_EXT, 0); +} + +char * MSP_locate_file(const char *filename) { char *lib_name = GDKmalloc(strlen(filename) + strlen(SO_PREFIX) + 1); diff -r f928f414e85d -r 4f55afd12fc1 sql/src/backends/monet5/sql_scenario.mx --- a/sql/src/backends/monet5/sql_scenario.mx Thu May 13 19:03:24 2010 +0200 +++ b/sql/src/backends/monet5/sql_scenario.mx Thu May 13 19:21:27 2010 +0200 @@ -79,6 +79,7 @@ #include "mal_namespace.h" #include "mal_sabaoth.h" #include "mal_debugger.h" +#include "mal_linker.h" #include "bat5.h" #include <mtime.h> #include "optimizer.h" @@ -159,9 +160,6 @@ if (!s) throw(MAL, "sql.start", "out of scenario slots"); sqlinit = GDKgetenv("sqlinit"); - if (sqlinit == NULL) { - /* gather the database initialization scripts*/ - } s->name = "S_Q_L"; s->language = "sql"; s->initSystem = NULL; @@ -407,6 +405,8 @@ mvc *m; str schema; backend *be; + bstream *bfd = NULL; + stream *fd = NULL; #ifdef _SQL_SCENARIO_DEBUG stream_printf(GDKout, "#SQLinitClient\n"); @@ -417,11 +417,28 @@ Based on the initialization retun value we can prepare a SQLinit string with all information needed to initialize the catalog based on the mandatory scripts to be executed. @c - if ( SQLnewcatalog > 0 && sqlinit == NULL){ - stream_printf(GDKout,"# SQL catalog created, load the sql scripts once\n"); - SQLnewcatalog = 0; + if (SQLnewcatalog > 0 && sqlinit == NULL) { + str fullname; + + fullname = MSP_locate_sqlscript("createdb"); + if (fullname) { + fd = open_rastream(fullname); + GDKfree(fullname); + + if (fd) { + bfd = bstream_create(fd, 128 * BLOCK); + stream_printf(c->fdout, "# SQL catalog created, " + "initial load of sql scripts\n"); + if (bfd == 0 || bstream_next(bfd) < 0) { + sqlinit = bfd->buf; + SQLnewcatalog = INT_MAX; + } + } + } + if (SQLnewcatalog != INT_MAX) + stream_printf(c->fdout, "#WARNING: could not read createdb.sql\n"); } - if (sqlinit) { /* add sqlinit to the fdin stack */ + if (sqlinit) { /* add sqlinit to the fdin stack */ buffer *b = (buffer*)GDKmalloc(sizeof(buffer)); size_t len = strlen(sqlinit); bstream *fdin; @@ -431,6 +448,11 @@ bstream_next(fdin); MCpushClientInput(c, fdin, 0, ""); } + if (SQLnewcatalog == INT_MAX) { + stream_close(fd); + stream_destroy(fd); + } + SQLnewcatalog = 0; if (c->state[MAL_SCENARIO_PARSER] == 0) { m = mvc_create(c->idx, 0, SQLdebug, c->fdin, c->fdout); global_variables(m, "monetdb", "sys"); diff -r f928f414e85d -r 4f55afd12fc1 sql/src/sql/Makefile.ag --- a/sql/src/sql/Makefile.ag Thu May 13 19:03:24 2010 +0200 +++ b/sql/src/sql/Makefile.ag Thu May 13 19:21:27 2010 +0200 @@ -15,11 +15,13 @@ # Copyright August 2008-2010 MonetDB B.V. # All Rights Reserved. +MT_SAFE + headers_sql = { HEADERS = sql - DIR = datadir/MonetDB/sql + DIR = libdir/MonetDB5 SOURCES = \ - createdb.mx \ + creatdb.mx \ clients.sql cluster.sql \ date.sql history.sql inet.sql \ math.sql mtime.sql \ diff -r f928f414e85d -r 4f55afd12fc1 sql/src/sql/mtime.sql --- a/sql/src/sql/mtime.sql Thu May 13 19:03:24 2010 +0200 +++ b/sql/src/sql/mtime.sql Thu May 13 19:21:27 2010 +0200 @@ -17,7 +17,7 @@ create function curdate( ) returns date external name mtime."current_date"; -create function "current_date"( ) returns date; +create function "current_date"( ) returns date external name mtime."current_date"; create function curtime( ) returns TIMETZ @@ -33,6 +33,8 @@ create function "localtimestamp"( ) returns TIMESTAMP external name mtime."current_timestamp"; +create type second_interval as interval day to sec; + create function local_timezone( ) returns second_interval external name mtime.local_timezone; _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list