Update of /cvsroot/monetdb/sql/src/backends/monet4
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv24554/src/backends/monet4
Modified Files:
Makefile.ag
Added Files:
Mserver.mx embeddedExample.c embeddedclient.mx initmodules.mx
monetdb.py.i mysqldump2bulkload.py prog.c static_modules.mx
Log Message:
Moved the MonetDB4-specific content from src/tools to src/backends/monet4 and
moved the new MonetDB5-specific content to src/backends/monet5.
--- NEW FILE: initmodules.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.
@f initmodules
@t The Monet Database System
@v Version 4.00
@a Florian Waas
@+ Module loading
The script modules require that the module_push/pop functionality is available.
As these functions are in the builtin dynamic loadable library module we first
load the dynamic libraries before we load and run the scripts.
@= install_module
{
extern oid [EMAIL PROTECTED](TBLinstall*, str);
DL_regfcn(DL_reglib("[EMAIL PROTECTED]", NULL, 40),
(ptr) [EMAIL PROTECTED], "[EMAIL PROTECTED]" );
}
@= load_module
monet_exec("module(@1);");
@= install_load_module
{
@:install_module(@1)@
@:load_module(@1)@
}
@h
void static_module_init(void);
@c
#include "sql_config.h"
#include "gdk.h"
#include "monet.h"
#include "initmodules.h"
void
static_module_init(void)
{
@include static_modules.mx
}
--- NEW FILE: prog.c ---
/*
* The contents of this file are subject to the MonetDB Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the MonetDB Database System.
*
* The Initial Developer of the Original Code is CWI.
* Portions created by CWI are Copyright (C) 1997-2007 CWI.
* All Rights Reserved.
*/
#include <monetdb4_config.h>
#include <monet_options.h>
#include "embeddedclient.h"
#ifdef HAVE_STRING_H
#include <string.h>
#endif
/* stolen piece */
#ifdef HAVE_FTIME
#include <sys/timeb.h>
#endif
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
static long
gettime(void)
{
#ifdef HAVE_GETTIMEOFDAY
struct timeval tp;
gettimeofday(&tp, NULL);
return (long) tp.tv_sec * 1000000 + (long) tp.tv_usec;
#else
#ifdef HAVE_FTIME
struct timeb tb;
ftime(&tb);
return (long) tb.time * 1000000 + (long) tb.millitm * 1000;
#endif
#endif
}
void
usage(char *prog)
{
fprintf(stderr, "Usage: %s [ options ] [ script+ ]
\n", prog);
fprintf(stderr, "Options are:
\n");
fprintf(stderr, " -c <config_file> | --config=<config_file>
\n");
fprintf(stderr, " -d<debug_level> | --debug=<debug_level>
\n");
fprintf(stderr, " -t | --time
\n");
fprintf(stderr, " --dbname=<database_name>
\n");
fprintf(stderr, "
--dbfarm=<database_directory>\n");
fprintf(stderr, " -s <option>=<value> | --set <option>=<value>
\n");
fprintf(stderr, " -? | --help
\n");
exit(-1);
}
int
main(int argc, char **av)
{
size_t curlen = 0, maxlen = BUFSIZ*8;
char *prog = *av;
opt *set = NULL;
int setlen = 0, time = 0;
long t0 = 0;
Mapi mid;
MapiHdl hdl;
char *buf, *line;
FILE *fp = NULL;
static struct option long_options[] = {
{"config", 1, 0, 'c'},
{"dbname", 1, 0, 0},
{"dbfarm", 1, 0, 0},
{"debug", 2, 0, 'd'},
{"time", 0, 0, 't'},
{"set", 1, 0, 's'},
{"help", 0, 0, '?'},
{0, 0, 0, 0}
};
if (!(setlen = mo_builtin_settings(&set)))
usage(prog);
/* needed, to prevent the MonetDB config file to be used */
setlen = mo_add_option(&set, setlen, opt_config, "prefix",
MONETDBPREFIX);
setlen = mo_add_option(&set, setlen, opt_config, "config",
MONETDBCONFIG);
for (;;) {
int option_index = 0;
int c = getopt_long(argc, av, "c:d::?s:t",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 0:
if (strcmp(long_options[option_index].name, "dbname")
== 0) {
setlen = mo_add_option(&set, setlen,
opt_cmdline, "gdk_dbname", optarg);
break;
}
if (strcmp(long_options[option_index].name, "dbfarm")
== 0) {
setlen = mo_add_option(&set, setlen,
opt_cmdline, "gdk_dbfarm", optarg);
break;
}
usage(prog);
break;
case 't':
time = 1;
break;
case 'c':
setlen = mo_add_option(&set, setlen, opt_cmdline,
"config", optarg);
break;
case 'd':
if (optarg) {
setlen = mo_add_option(&set, setlen,
opt_cmdline, "gdk_debug", optarg);
}
break;
case 's':{
/* should add option to a list */
char *tmp = strchr(optarg, '=');
if (tmp) {
*tmp = '\0';
setlen = mo_add_option(&set, setlen,
opt_cmdline, optarg, tmp + 1);
} else {
fprintf(stderr, "!ERROR: wrong format %s\n",
optarg);
}
}
break;
case '?':
usage(prog);
default:
fprintf(stderr, "!ERROR: getopt returned character code
0%o ??\n", c);
usage(prog);
}
}
setlen = mo_system_config(&set, setlen);
mid = embedded_sql(set, setlen);
/* now for each file given on the command line (or stdin)
read the query and execute it
*/
buf = malloc(maxlen);
if (buf == NULL) {
fprintf(stderr, "Cannot allocate memory for query buffer\n");
return -1;
}
if (optind == argc)
fp = stdin;
while (optind < argc || fp) {
if (!fp && (fp=fopen(av[optind],"r")) == NULL){
fprintf(stderr,"could no open file %s\n", av[optind]);
break;
}
while ((line = fgets(buf+curlen, 1024, fp)) != NULL) {
size_t n = strlen(line);
curlen += n;
if (curlen+1024 > maxlen) {
maxlen += 8*BUFSIZ;
buf = realloc(buf, maxlen + 1);
if (buf == NULL) {
fprintf(stderr, "Cannot allocate memory
for query buffer\n");
return -1;
}
}
}
if (fp != stdin) {
fclose(fp);
}
fp = NULL;
optind++;
curlen = 0;
if (time)
t0 = gettime();
hdl = mapi_query(mid, buf);
do {
if (mapi_result_error(hdl) != NULL)
mapi_explain_result(hdl, stderr);
while ((line = mapi_fetch_line(hdl)) != NULL)
printf("%s\n", line);
} while (mapi_next_result(hdl) == 1);
mapi_close_handle(hdl);
if (time)
printf("Timer: %ld (usec)\n", gettime()-t0);
}
free(buf);
mapi_destroy(mid);
return 0;
}
--- NEW FILE: embeddedclient.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.
@f embeddedclient
@a K.S. Mullender
@* Embedded MonetDB
The purpose of this Embedded MonetDB is to illustrate how the
code base can be easily linked with a stand-alone application.
The current implementation uses a minimalistic approach, i.e.
using the Mapi prototol to communicate between application thread
and the database kernel.
This communication is not optimized for speed.
An area that has undergone some tweaking for performance improvement
are the large number of lock calls needed in the GDK kernel to safely run
multiple clients against the database.
For direct linkage to an application we suggest to use the monet_embedded
option, which allows just one mapi connection to be set up. This allows
for removal of all lock calls in the kernel. This improves performance
between 25-50%.
@h
#ifndef _EMBEDDEDCLIENT_H_
#define _EMBEDDEDCLIENT_H_
#include "monet_options.h"
#ifdef WIN32
#ifndef LIBEMBEDDEDSQL
#define embeddedclient_export extern __declspec(dllimport)
#else
#define embeddedclient_export extern __declspec(dllexport)
#endif
#else
#define embeddedclient_export extern
#endif
#include <stream.h>
#include <Mapi.h>
embeddedclient_export Mapi monetdb_sql(char *dbfarm, char *dbname);
embeddedclient_export Mapi embedded_sql(opt *set, int len);
#endif /* _EMBEDDEDCLIENT_H_ */
@c
#include "sql_config.h"
#include "embeddedclient.h"
#include "gdk.h"
#ifdef HAVE_PTHREAD_H
/* pthread.h on Windows includes config.h if HAVE_CONFIG_H is set */
#undef HAVE_CONFIG_H
#ifdef pid_t
#undef pid_t
#endif
#include <sched.h>
#include <pthread.h>
#endif
#include "monet.h"
#include "monet_options.h"
#include "initmodules.h"
static Client
Monet_init(opt *set, int setlen)
{
char *p;
opt *n = (opt *) GDKmalloc(setlen * sizeof(opt));
int i, j, nlen = 0;
char *dbname = mo_find_option(set, setlen, "gdk_dbname");
char *dbfarm = mo_find_option(set, setlen, "gdk_dbfarm");
char *alloc_map = mo_find_option(set, setlen, "gdk_alloc_map");
if (n == NULL || dbname == NULL || dbfarm == NULL || alloc_map == NULL)
{
if (n != NULL)
GDKfree(n);
return NULL;
}
dbfarm = mo_substitute(set, setlen, dbfarm);
/* determine Monet's kernel settings. */
if (!GDKinit(dbname, dbfarm, strcasecmp(alloc_map, "yes") == 0)) {
free(dbfarm);
GDKfree(n);
return NULL;
}
free(dbfarm);
for (i = 0; i < setlen; i++) {
int done = 0;
for (j = 0; j < nlen; j++) {
if (strcmp(n[j].name, set[i].name) == 0) {
if (n[j].kind < set[i].kind)
n[j] = set[i];
done = 1;
break;
}
}
if (!done) {
n[nlen] = set[i];
nlen++;
}
}
for (i = 0; i < nlen; i++) {
char *value;
value = mo_substitute(n, nlen, n[i].value);
GDKsetenv(n[i].name, value);
free(value);
}
GDKfree(n);
if ((p = GDKgetenv("gdk_debug")) != NULL)
GDKdebug = strtol(p, NULL, 10);
if ((p = GDKgetenv("gdk_mem_bigsize")) != NULL)
GDK_mem_bigsize = strtol(p, NULL, 10);
if ((p = GDKgetenv("gdk_vm_minsize")) != NULL)
GDK_vm_minsize = strtol(p, NULL, 10);
if (GDKgetenv_isyes("gdk_embedded")) {
GDKembedded = 1;
}
if (GDKgetenv_isyes("monet_daemon"))
monet_daemon = 1;
if (GDKgetenv_isyes("monet_embedded")) {
monet_daemon = 1;
GDKembedded = 1;
}
return monet_init();
}
static opt *embedded_set = NULL;
static int embedded_len = 0;
static void *
start_sql_server(void *arg)
{
static int initialized = 0;
stream *in, *out;
char buf[128];
if (!initialized) {
/* monet_singlethreaded = 1; */
if (embedded_set == NULL) {
int len = mo_builtin_settings(&embedded_set);
embedded_len = mo_system_config(&embedded_set, len);
}
Monet_init(embedded_set, embedded_len);
mo_free_options(embedded_set, embedded_len);
static_module_init();
THRnew(MT_getpid(), "Interpreter");
initialized = 1;
}
in = ((stream **) arg)[0];
out = ((stream **) arg)[1];
free(arg);
snprintf(buf, sizeof(buf), "client(Stream(\"" PTRFMT "\"), Stream(\""
PTRFMT "\"));", PTRFMTCAST in, PTRFMTCAST out);
monet_exec("module(sql_server);");
monet_exec(buf);
return NULL;
}
Mapi
embedded_sql(opt *set, int len)
{
Mapi mid;
pthread_t sqlthread;
stream **server;
if (set) {
embedded_set = set;
embedded_len = len;
}
server = mapi_embedded_init(&mid,"sql");
pthread_create(&sqlthread, NULL, start_sql_server, (void *) server);
mapi_start_talking(mid);
return mid;
}
Mapi
monetdb_sql(char *dbfarm, char *dbname)
{
Mapi mid;
pthread_t sqlthread;
stream **server;
int len = mo_builtin_settings(&embedded_set);
embedded_len = mo_system_config(&embedded_set, len);
embedded_len = mo_add_option(&embedded_set, embedded_len, opt_cmdline,
"gdk_dbfarm", dbfarm);
embedded_len = mo_add_option(&embedded_set, embedded_len, opt_cmdline,
"gdk_dbname", dbname);
server = mapi_embedded_init(&mid,"sql");
pthread_create(&sqlthread, NULL, start_sql_server, (void *) server);
mapi_start_talking(mid);
return mid;
}
--- NEW FILE: Mserver.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.
@f Mserver
@a M.L. Kersten, P. Boncz, Niels Nes
@v 4.1
@* The Monet Server
@T
The {\tt Mserver} is the Monet server. The database administrator starts
and stops it. (S)he can type on the console, which is started on the
standard input/output.
@+ Manual Page
@T
The Mserver is a multi-threaded program. There is one system thread, and for
each user (system administrator included) there is one worker thread.
As a default, the Mserver also starts the network listener thread,
on the port number specified in the parameter file.
@- Usage
@T
\begin{verbatim}
Mserver { [ --dbname <db-name> ]
[ --dbfarm <dbfarm> ]
[ --dbinit <stmt> ]
[ -c|--config <config-file> ]
[ -d<value>|--debug=value ]
[ -s|--set [option=value] ] set option can be given multiple times
to override verious options
} [ <mil-script> ]
\end{verbatim}
Since the console has no command-line history nor file name completion,
you are {\bf recommended} to use the
@[<a href="../MapiClient/index.html">mclient</a>@ program for interactive
sessions
instead.
The options have the following meaning:
\begin{description}
\item[{\tt --dbname $<$db-name$>$ }]
open the database {\em db-name}.
\item[{\tt --config $<$config-file$>$ }]
where to find the environment settings
\end{description}
@{
@+ Implementation
@h
#ifndef _MONET_GLOBAL_H_
#define _MONET_GLOBAL_H_
#include "monet.h"
#include "yytree.h"
#endif /* _MONET_GLOBAL_H_ */
@c
#include "sql_config.h"
#include "Mserver.h"
#ifdef _CRTDBG_MAP_ALLOC
/* Windows only:
our definition of new and delete clashes with the one if
_CRTDBG_MAP_ALLOC is defined.
*/
#undef _CRTDBG_MAP_ALLOC
#endif
#include "monet_context.h"
#include "monet_interpreter.h"
#include "monet_parse.h"
#include "monet_queue.h"
#include "monet_client.h"
#include "monet_process.h"
#include "monet_options.h"
#include "initmodules.h"
#include <locale.h>
#ifdef NATIVE_WIN32
#define getcwd _getcwd
#endif
@-
The architecture is setup to handle multiple streams of requests.
The first thread started represents the server. It reads from standard input
and writes to standard input. This is also a way to recognize the server
actions.
To start the server in the background one should use the argument -background.
This closes standard input. Direct execution in the background may cause
the server to hang in stdio for input from the terminal.
@
@
The server thread started remains in existence until all other threads die.
The server is stopped by cntrl-D or the quit command.
@
@-
Brain-damaged Sun engineers decided to use malloc for allocating an enormous
buffer of 20 bytes in the sunos2.5.5.X thread library, making the tunable
malloc library totally unusable, since it requires you to do advice before any
use of malloc(). We hack around it, by using realloc(0,size) in
gdk/gdk_utils.mx and wrapping malloc in the below dummy function:
@c
#ifdef HAVE_MALLOPT
static int malloc_init = 1;
#endif
@c
static void
usage(char *prog, int debug, opt *set, int setlen)
{
fprintf(stderr, "Usage: %s [ options ] [ script+ ]
\n", prog);
fprintf(stderr, "Options are:
\n");
fprintf(stderr, " -c <config_file> | --config=<config_file>
\n");
fprintf(stderr, " --dbname=<database_name>
\n");
fprintf(stderr, "
--dbfarm=<database_directory>\n");
fprintf(stderr, " --dbinit=<MIL_statement>
\n");
fprintf(stderr, " -d<debug_level> | --debug=<debug_level>
\n");
fprintf(stderr, " -s <option>=<value> | --set <option>=<value>
\n");
fprintf(stderr, " -? | --help
\n");
if (debug)
mo_print_options(set, setlen);
exit(-1);
}
static str
absolute_path(str s)
{
if (!MT_path_absolute(s)) {
str ret = (str) GDKmalloc(strlen(s) + strlen(monet_cwd) + 2);
sprintf(ret, "%s%c%s", monet_cwd, DIR_SEP, s);
return ret;
}
return GDKstrdup(s);
}
static Client
Monet_init(opt *set, int setlen)
{
char *p;
opt *n = (opt *) malloc(setlen * sizeof(opt));
int i, j, nlen = 0;
char *dbname = mo_find_option(set, setlen, "gdk_dbname");
char *dbfarm = mo_find_option(set, setlen, "gdk_dbfarm");
char *alloc_map = mo_find_option(set, setlen, "gdk_alloc_map");
if (!n || !dbname || !dbfarm || !alloc_map) {
if (n)
free(n);
return NULL;
}
dbfarm = mo_substitute(set, setlen, dbfarm);
if ((p = mo_find_option(set, setlen, "gdk_debug")))
GDKdebug = strtol(p, NULL, 10);
if ((p = mo_find_option(set, setlen, "gdk_mem_pagebits")))
GDK_mem_pagebits = strtol(p, NULL, 10);
if ((p = mo_find_option(set, setlen, "gdk_vmtrim")))
GDK_vm_trim = strcasecmp(p, "yes") == 0;
/* determine Monet's kernel settings. */
if (!GDKinit(dbname, dbfarm, strcasecmp(alloc_map, "yes") == 0)) {
free(dbfarm);
free(n);
return NULL;
}
free(dbfarm);
for (i = 0; i < setlen; i++) {
int done = 0;
for (j = 0; j < nlen; j++) {
if (strcmp(n[j].name, set[i].name) == 0) {
if (n[j].kind < set[i].kind) {
n[j] = set[i];
}
done = 1;
break;
}
}
if (!done) {
n[nlen] = set[i];
nlen++;
}
}
for (i = 0; i < nlen; i++) {
char *value;
value = mo_substitute(n, nlen, n[i].value);
GDKsetenv(n[i].name, value);
free(value);
}
free(n);
if ((p = GDKgetenv("gdk_mem_bigsize"))) {
/* when allocating >6% of all RAM; do so using vmalloc() iso
malloc() */
lng max_mem_bigsize = GDK_mem_maxsize/16;
/* sanity check to avoid memory fragmentation */
GDK_mem_bigsize = (size_t) MIN(max_mem_bigsize, strtol(p, NULL,
10));
}
if (GDKgetenv_isyes("gdk_embedded") || GDKgetenv_isyes("embedded")) {
GDKembedded = 1;
monet_daemon = 1;
}
if (GDKgetenv_isyes("monet_daemon") || GDKgetenv_isyes("daemon")) {
monet_daemon = 1;
#ifdef HAVE_SETSID
setsid();
#endif
}
return monet_init();
}
@c
int
main(int argc, char **av)
{
Client c;
char *prog = *av;
opt *set = NULL;
int idx = 0, debug = 0, setlen = 0, status = 1;
static struct option long_options[] = {
{"config", 1, 0, 'c'},
{"dbname", 1, 0, 0},
{"dbfarm", 1, 0, 0},
{"dbinit", 1, 0, 0},
{"debug", 2, 0, 'd'},
{"help", 0, 0, '?'},
{"nostalgic", 0, 0, 0},
{"set", 1, 0, 's'},
{"trace", 0, 0, 0},
{0, 0, 0, 0}
};
@-
We give malloc advice here. Main goal: prevent fragmentation.
We do this by declaring everything below 2K as 'small'. These
values will be drawn from a fixed pools of 400K.
A grain size of 128 bytes is used to keep overhead low.
We do this by declaring everything below 2K as 'small'. These
values will be drawn from a fixed pools of 400K.
A grain size of 128 bytes is used to keep overhead low.
Trivial remark: for dynamically linked executables the mallopt
capabilities depend on the malloc implementation used at run time.
@= mallopt
if (malloc_init) {
/* for (Red Hat) Linux (6.2) unused and ignored at least as of glibc-2.1.3-15 */
/* for (Red Hat) Linux (8) used at least as of glibc-2.2.93-5 */
if (mallopt(M_MXFAST, 192)) {
fprintf(stderr, "monet: mallopt(M_MXFAST,192) fails.\n");
}
#ifdef M_BLKSZ
if (mallopt(M_BLKSZ, 8*1024)) {
fprintf(stderr, "monet: mallopt(M_BLKSZ,8*1024) fails.\n");
}
#endif
}
malloc_init=0;
@
@c
if (setlocale(LC_CTYPE, "") == NULL) {
GDKfatal("cannot set locale\n");
}
#ifdef HAVE_MALLOPT
@:mallopt@
#endif
if (getcwd(monet_cwd, PATHLENGTH - 1) == NULL) {
perror("pwd");
GDKfatal("Monet_init: could not determine current directory\n");
}
if (!(setlen = mo_builtin_settings(&set)))
usage(prog, debug, set, setlen);
/* * MONETDBPREFIX & MONETDBCONFIG are not (yet?) available for sql;
* use "Mserver --config=`monetdb4-config --sysconfdir`/MonetDB.conf",
instead.
setlen = mo_add_option(&set, setlen, opt_config, "prefix",
MONETDBPREFIX);
setlen = mo_add_option(&set, setlen, opt_config, "config",
MONETDBCONFIG);
*/
for (;;) {
int option_index = 0;
int opt = getopt_long(argc, av, "c:d::?s:", long_options,
&option_index);
if (opt == -1)
break;
switch (opt) {
case 0:
if (strcmp(long_options[option_index].name, "dbname")
== 0) {
setlen = mo_add_option(&set, setlen,
opt_cmdline, "gdk_dbname", optarg);
break;
}
if (strcmp(long_options[option_index].name, "dbfarm")
== 0) {
setlen = mo_add_option(&set, setlen,
opt_cmdline, "gdk_dbfarm", optarg);
break;
}
if (strcmp(long_options[option_index].name, "dbinit")
== 0) {
if (monet_dbinit)
fprintf(stderr, "!ERROR: --dbinit set
twice," " last one takes precedence\n");
monet_dbinit = optarg;
break;
}
if (strcmp(long_options[option_index].name, "trace") ==
0) {
monet_listing = 1;
break;
}
if (strcmp(long_options[option_index].name,
"nostalgic") == 0) {
monet_nostalgic = 1;
break;
}
usage(prog, debug, set, setlen);
break;
case 'c':
setlen = mo_add_option(&set, setlen, opt_cmdline,
"config", optarg);
break;
case 'd':
if (optarg) {
setlen = mo_add_option(&set, setlen,
opt_cmdline, "gdk_debug", optarg);
} else {
debug = 1;
}
break;
case 's':{
/* should add option to a list */
char *tmp = strchr(optarg, '=');
if (tmp) {
*tmp = '\0';
setlen = mo_add_option(&set, setlen,
opt_cmdline, optarg, tmp + 1);
} else {
fprintf(stderr, "!ERROR: wrong format %s\n",
optarg);
}
}
break;
case '?':
usage(prog, debug, set, setlen);
default:
fprintf(stderr, "!ERROR: getopt returned character code
0%o ??\n", opt);
usage(prog, debug, set, setlen);
}
}
if (!(setlen = mo_system_config(&set, setlen)))
usage(prog,debug, set, setlen);
monet_script = (str *) GDKmalloc(sizeof(str) * (argc - optind + 5));
monet_script[idx] = NULL;
while (optind < argc) {
monet_script[idx] = absolute_path(av[optind]);
monet_script[idx + 1] = NULL;
optind++;
idx++;
}
if (debug)
mo_print_options(set, setlen);
setlen = mo_add_option(&set, setlen, opt_builtin, "monet_cwd",
monet_cwd);
c = Monet_init(set, setlen);
mo_free_options(set, setlen);
if (!c)
usage(prog,debug, set, setlen);
GDKsetenv("monet_version", (str)MonetDBversion());
monet_hello(NULL);
static_module_init();
@-
Execute scripts.
if (monet_script ) printf("#script:%s\n",monet_script);
@c
@-
thread management.
@c
THRnew(MT_getpid(), "Interpreter");
scheduleClient(c);
monetInterpreter((void *) &status);
@-
At the end of a multi-threaded session we should wait
for all processes to terminate properly.
@c
@-
Peter: for the time being avoid difficult things like dropping everything
@c
monet_exit(0);
MT_global_exit(0);
return 0;
} /* main */
@}
--- NEW FILE: monetdb.py.i ---
// The contents of this file are subject to the MonetDB Public License
// Version 1.1 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the MonetDB Database System.
//
// The Initial Developer of the Original Code is CWI.
// Portions created by CWI are Copyright (C) 1997-2007 CWI.
// All Rights Reserved.
%module monetdb
%include "python/typemaps.i"
%include "exception.i"
%{
#ifdef HAVE_FSTAT
#undef HAVE_FSTAT
#endif
#include "Mapi.h"
extern Mapi monetdb_sql(char *dbfarm, char *dbname);
%}
extern Mapi monetdb_sql(char *dbfarm, char *dbname);
%include "Mapi.h"
Index: Makefile.ag
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet4/Makefile.ag,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- Makefile.ag 12 Sep 2007 10:58:08 -0000 1.32
+++ Makefile.ag 12 Sep 2007 12:54:03 -0000 1.33
@@ -14,8 +14,50 @@
# Portions created by CWI are Copyright (C) 1997-2007 CWI.
# All Rights Reserved.
+MTSAFE
+
+SWIGFLAGS = $(MONETDB_INCS) $(CLIENTS_INCS)
+INCLUDES =
+
+# with gcc we could use these
+#X_CFLAGS = -Wno-unused-parameter -Wno-unused-function
+# but we certainly have to override the default X_CFLAGS:
+X_CFLAGS =
+
+GDK_LIBS = $(PTHREAD_LIBS) $(MALLOC_LIBS)
+EXTRA_LIBS = $(SOCKET_LIBS) $(DL_LIBS) $(GDK_LIBS)
+
+STATIC_MODS = $(MONETDB4_MODS) \
+ -l_builtin -l_arith -l_bat -l_algebra -l_sys -l_trans -l_str -l_constant
+
+smallTOC_SHARED_MODS = \
+ -l_mapi \
+ \
+ -l_aggr \
+ -l_aggrX3 \
+ -l_alarm \
+ -l_ascii_io \
+ -l_bat_arith \
+ -l_blob \
+ -l_enum \
+ -l_mkey \
+ -l_mmath \
+ -l_monettime \
+ -l_pcre \
+ -l_pqueue \
+ -l_streams \
+ -l_logger \
+ -l_unix \
+ -l_xtables \
+ \
+ -l_txtsim \
+ \
+ ../backends/monet4/lib_sql_server
+
+EXTRA_DIST = static_modules.mx mysqldump2bulkload.py
+
INCLUDES = ../../include ../../common ../../storage ../../server \
- $(MONETDB_INCS) $(MONETDB4_INCS)
+ $(CLIENTS_INCS) $(MONETDB_INCS) $(MONETDB4_INCS) $(PYTHON_INCS)
lib__sql_server = {
DIR = libdir/MonetDB4
@@ -37,4 +79,60 @@
SOURCES = sql_server.mx
}
+lib_initmodules = {
+ NOINST
+ SOURCES = initmodules.mx
+}
+
+bin_Mserver = {
+ COND = LINK_STATIC
+ SOURCES = Mserver.mx
+ LIBS = libinitmodules STATIC_MODS @SHARED_LIBS@ $(EXTRA_LIBS) \
+ $(MONETDB_LIBS) -lbat -lmutils -lstream $(MONETDB4_LIBS) -lmonet
+}
+
+lib_embeddedsql = {
+ SOURCES = embeddedclient.mx
+ LIBS = libinitmodules STATIC_MODS @SHARED_LIBS@ $(EXTRA_LIBS) \
+ $(MONETDB_LIBS) -lbat -lmutils -lstream $(MONETDB4_LIBS)
-lmonet $(CLIENTS_LIBS) -lMapi
+}
+
+bin_Mbeddedsql = {
+ SOURCES = prog.c
+ LIBS = libinitmodules STATIC_MODS @SHARED_LIBS@ $(EXTRA_LIBS) \
+ libembeddedsql \
+ $(MONETDB_LIBS) -lbat -lmutils -lstream $(MONETDB4_LIBS)
-lmonet $(CLIENTS_LIBS) -lMapi
+}
+
+bin_embeddedExample = {
+ SOURCES = embeddedExample.c
+ DIR = libdir/MonetDB4/Tests
+ LIBS = libinitmodules STATIC_MODS @SHARED_LIBS@ $(EXTRA_LIBS) \
+ libembeddedsql \
+ $(MONETDB_LIBS) -lbat -lmutils -lstream $(MONETDB4_LIBS)
-lmonet $(CLIENTS_LIBS) -lMapi
+}
+
+headers_h = {
+ HEADERS = h
+ DIR = includedir
+ SOURCES = embeddedclient.mx
+}
+
+lib_monetdb = {
+ COND = HAVE_PYTHON_SWIG
+ PREFIX =
+ NAME = _monetdb
+ SOURCES = monetdb.py.i
+ LIBS = libembeddedsql $(PYTHON_LIBS) $(MONETDB_LIBS) -lmutils -lstream
$(CLIENTS_LIBS) -lMapi
+ DIR = $(prefix)/$(PYTHON_LIBDIR)
+}
+
+headers_py = {
+ COND = HAVE_PYTHON_SWIG
+ HEADERS = py
+ SOURCES = monetdb.py.i
+ TARGETS = monetdb.py
+ DIR = $(prefix)/$(PYTHON_LIBDIR)
+}
+
EXTRA_DIST_DIR = Tests
--- NEW FILE: static_modules.mx ---
@' The contents of this file are subject to the MonetDB Public License
@' Version 1.1 (the "License"); you may not use this file except in
@' compliance with the License. You may obtain a copy of the License at
@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
@'
@' Software distributed under the License is distributed on an "AS IS"
@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
@' License for the specific language governing rights and limitations
@' under the License.
@'
@' The Original Code is the MonetDB Database System.
@'
@' The Initial Developer of the Original Code is CWI.
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.
/* core */
@:install_load_module(builtin)@
@:install_load_module(arith)@
@:install_load_module(str)@
@:install_load_module(constant)@
@:install_load_module(bat)@
@:install_load_module(algebra)@
@:install_load_module(sys)@
@:install_load_module(trans)@
#ifdef STATIC
@:install_module(streams)@
/* mapi */
@:install_module(mapi)@
/* plain */
@:install_module(aggrX3)@
@:install_module(alarm)@
@:install_module(bat_arith)@
@:install_module(blob)@
@:install_module(enum)@
@:install_module(xtables)@
@:install_module(mkey)@
@:install_module(mmath)@
@:install_module(monettime)@
@:install_module(pcre)@
@:install_module(pqueue)@
@:install_module(unix)@
@:install_module(ascii_io)@
/* contrib */
@:install_module(txtsim)@
/* SQL */
@:install_module(sql_server)@
#endif
--- NEW FILE: mysqldump2bulkload.py ---
#!/usr/bin/env python
# The contents of this file are subject to the MonetDB Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is the MonetDB Database System.
#
# The Initial Developer of the Original Code is CWI.
# Portions created by CWI are Copyright (C) 1997-2007 CWI.
# All Rights Reserved.
import re
import sys
import string
import fileinput
CREATE = 1
INSERT = 2
write = sys.stdout.write
part = -1
def copy_line( line, write = write ):
m = re.search('(INSERT INTO ([A-Za-z0-9_]*) .*VALUES \()', line)
if m is not None:
write("SELECT '%s';\n" % line[m.start(2):m.end(2)])
write("COPY INTO %s FROM STDIN USING DELIMITERS ',', '\\n';\n\n" %
line[m.start(2):m.end(2)])
return line[0:m.end(1)]
return ""
def create_line( line, write = write ):
status = CREATE
if re.search('\).*;', line) is not None:
write(');\n')
return 0
m = re.search('auto_increment', line)
if m is not None:
line = line[0:m.start(0)] + line[m.end(0):]
m = re.search('unsigned', line)
if m is not None:
line = line[0:m.start(0)] + line[m.end(0):]
m = re.search('KEY[\t ]+([A-Za-z0-9_]+)[\t ]+(\(.*)', line)
if m is not None:
write(" CONSTRAINT %s UNIQUE %s\n" %
(line[m.start(1) : m.end(1)], line[m.start(2) : m.end(2)]))
return status
write(line)
return status
def main(write = write):
status = 0
base = ""
l = 0
cnt = 0
for line in fileinput.input():
if status == INSERT:
if line[0:l] == base:
if part < 0 or cnt < part:
print line[l:line.rfind(')')]
cnt = cnt + 1
else:
print # empty line to end copy into
print "COMMIT;"
cnt = 0
status = 0
if status != INSERT and line[0] != '#' and line[0:1] != '--':
if status == CREATE:
status = create_line(line)
elif re.search('DROP TABLE', line) is not None:
write('--' + line)
elif re.search('CREATE TABLE', line) is not None:
status = CREATE
write(line)
elif re.search('INSERT INTO', line) is not None:
base = copy_line(line)
l = len(base)
status = INSERT
print line[l:line.rfind(')')]
else:
write(line)
main()
--- NEW FILE: embeddedExample.c ---
/*
* The contents of this file are subject to the MonetDB Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the MonetDB Database System.
*
* The Initial Developer of the Original Code is CWI.
* Portions created by CWI are Copyright (C) 1997-2007 CWI.
* All Rights Reserved.
*/
/*
This program is meant to illustrate an embedded SQL application
and provides a baseline for footprint comparisons.
*/
#include <sql_config.h>
#include <embeddedclient.h>
#define die(dbh,hdl) do { \
if (hdl) \
mapi_explain_result(hdl,stderr); \
else if (dbh) \
mapi_explain(dbh,stderr); \
else \
fprintf(stderr,"command failed\n"); \
exit(-1); \
} while (0)
#define close_handle(X,Y) if (mapi_close_handle(Y) != MOK) die(X, Y);
#define SQL1 "create table emp(name varchar(20),age int)"
#define SQL2 "insert into emp values('user%d', %d)"
#define SQL3 "select * from emp"
int
main()
{
Mapi dbh;
MapiHdl hdl = NULL;
int i;
dbh= embedded_sql(NULL, 0);
if (dbh == NULL || mapi_error(dbh))
die(dbh, hdl);
/* switch off autocommit */
if (mapi_setAutocommit(dbh, 0) != MOK || mapi_error(dbh))
die(dbh,NULL);
if ((hdl = mapi_query(dbh, SQL1)) == NULL || mapi_error(dbh))
die(dbh, hdl);
close_handle(dbh,hdl);
for(i=0; i< 1000; i++){
char query[100];
snprintf(query, 100, SQL2, i, i % 82);
if ((hdl = mapi_query(dbh, query)) == NULL || mapi_error(dbh))
die(dbh, hdl);
close_handle(dbh,hdl);
}
if ((hdl = mapi_query(dbh, SQL3)) == NULL || mapi_error(dbh))
die(dbh, hdl);
i=0;
while (mapi_fetch_row(hdl)) {
char *age = mapi_fetch_field(hdl, 1);
i= i+ atoi(age);
}
if (mapi_error(dbh))
die(dbh, hdl);
close_handle(dbh,hdl);
printf("The footprint is %d Mb \n",i);
mapi_disconnect(dbh);
return 0;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins