Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv8616/src/server

Modified Files:
        sql_env.mx sql_parser.mx sql_psm.mx sql_qc.mx sql_schema.mx 
        sql_semantic.mx sql_sequence.mx sql_updates.mx 
Log Message:
replaced using local char arrays of size BUFSIZ, by a single function 
(sql_message). Reduces stack pressure, smaller code etc.

approved output for m5/sql


Index: sql_semantic.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_semantic.mx,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- sql_semantic.mx     29 Jun 2007 11:29:08 -0000      1.169
+++ sql_semantic.mx     21 Aug 2007 22:24:40 -0000      1.170
@@ -966,7 +966,6 @@
        return(dest);
 }
 
-
 char *dlist2string(mvc *sql, dlist *l)
 {
        char *b = NULL;

Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- sql_updates.mx      12 Jun 2007 17:25:44 -0000      1.124
+++ sql_updates.mx      21 Aug 2007 22:24:40 -0000      1.125
@@ -90,7 +90,7 @@
 /* pkey's cannot have NULLs, ukeys however can
    current implementation switches on 'NOT NULL' on primary key columns */
 
-       char buf[BUFSIZ];
+       char *msg = NULL;
        stmt *res;
 
        sql_subtype *it = sql_bind_localtype("int");
@@ -147,11 +147,11 @@
                }
 
                if (k->type == pkey) {
-                       snprintf(buf, BUFSIZ, "INSERT INTO: PRIMARY KEY 
constraint '%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "INSERT INTO: PRIMARY KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                } else {
-                       snprintf(buf, BUFSIZ, "INSERT INTO: UNIQUE constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "INSERT INTO: UNIQUE constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                }
-               res = stmt_exception(s, _strdup(buf), 00001);
+               res = stmt_exception(s, msg, 00001);
        } else {                /* single column key */
                sql_kc *c = k->columns->h->data;
                stmt *s, *h = inserts[c->c->colnr]->op2.stval;
@@ -193,11 +193,11 @@
                        s = stmt_binop(s, count_sum, or);
                }
                if (k->type == pkey) {
-                       snprintf(buf, BUFSIZ, "INSERT INTO: PRIMARY KEY 
constraint '%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "INSERT INTO: PRIMARY KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                } else {
-                       snprintf(buf, BUFSIZ, "INSERT INTO: UNIQUE constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "INSERT INTO: UNIQUE constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                }
-               res = stmt_exception(s, _strdup(buf), 00001);
+               res = stmt_exception(s, msg, 00001);
        }
        stmt_destroy(ts);
        return res;
@@ -206,7 +206,7 @@
 static stmt *
 insert_check_fkey(mvc *sql, stmt **inserts, sql_key *k, stmt *idx_inserts)
 {
-       char buf[BUFSIZ];
+       char *msg = NULL;
        stmt *s = inserts[0]->op2.stval;
        sql_subtype *it = sql_bind_localtype("int");
        sql_subaggr *cnt = sql_bind_aggr(sql->session->schema, "count", NULL);
@@ -225,8 +225,8 @@
        }
 
        /* s should be empty */
-       snprintf(buf, BUFSIZ, "INSERT INTO: FOREIGN KEY constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
-       return stmt_exception(s, _strdup(buf), 00001);
+       msg = sql_message( "INSERT INTO: FOREIGN KEY constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
+       return stmt_exception(s, msg, 00001);
 }
 
 static stmt *
@@ -518,7 +518,7 @@
 static stmt *
 update_check_ukey(mvc *sql, stmt **updates, sql_key *k, stmt *idx_updates, int 
updcol)
 {
-       char buf[BUFSIZ];
+       char *msg = NULL;
        stmt *res = NULL;
 
        sql_subtype *it = sql_bind_localtype("int");
@@ -591,11 +591,11 @@
                }
 
                if (k->type == pkey) {
-                       snprintf(buf, BUFSIZ, "UPDATE: PRIMARY KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "UPDATE: PRIMARY KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                } else {
-                       snprintf(buf, BUFSIZ, "UPDATE: UNIQUE constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "UPDATE: UNIQUE constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
                }
-               res = stmt_exception(s, _strdup(buf), 00001);
+               res = stmt_exception(s, msg, 00001);
        } else {                /* single column key */
                stmt *ts = stmt_basetable(k->t, k->t->base.name);
                sql_kc *c = k->columns->h->data;
@@ -627,11 +627,11 @@
                }
 
                if (k->type == pkey) {
-                       snprintf(buf, BUFSIZ, "UPDATE: PRIMARY KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "UPDATE: PRIMARY KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                } else {
-                       snprintf(buf, BUFSIZ, "UPDATE: UNIQUE constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
+                       msg = sql_message( "UPDATE: UNIQUE constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
                }
-               res = stmt_exception(s, _strdup(buf), 00001);
+               res = stmt_exception(s, msg, 00001);
        }
        return res;
 }
@@ -639,7 +639,7 @@
 static stmt *
 update_check_fkey(mvc *sql, stmt **updates, sql_key *k, stmt *idx_updates, int 
updcol)
 {
-       char buf[BUFSIZ];
+       char *msg = NULL;
        stmt *s;
        sql_subtype *it = sql_bind_localtype("int");
        sql_subaggr *cnt = sql_bind_aggr(sql->session->schema, "count", NULL);
@@ -655,14 +655,14 @@
        s = stmt_binop(stmt_aggr(stmt_dup(idx_updates), NULL, cnt, 1), 
stmt_aggr(cur, NULL, sql_dup_aggr(cnt), 1), ne);
 
        /* s should be empty */
-       snprintf(buf, BUFSIZ, "UPDATE: FOREIGN KEY constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
-       return stmt_exception(s, _strdup(buf), 00001);
+       msg = sql_message( "UPDATE: FOREIGN KEY constraint '%s.%s' violated", 
k->t->base.name, k->base.name);
+       return stmt_exception(s, msg, 00001);
 }
 
 static stmt *
 join_updated_pkey(mvc *sql, sql_key * k, stmt **updates, int updcol)
 {
-       char buf[BUFSIZ];
+       char *msg = NULL;
        int nulls = 0;
        node *m, *o;
        sql_idx *ri = ((sql_fkey*)k)->rkey->k.idx;
@@ -715,8 +715,8 @@
        s = stmt_binop(stmt_aggr(stmt_dup(s), NULL, cnt, 1), stmt_aggr(rows, 
NULL, sql_dup_aggr(cnt), 1), ne);
 
        /* s should be empty */
-       snprintf(buf, BUFSIZ, "UPDATE: FOREIGN KEY constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
-       return stmt_exception(s, _strdup(buf), 00001);
+       msg = sql_message( "UPDATE: FOREIGN KEY constraint '%s.%s' violated", 
k->t->base.name, k->base.name);
+       return stmt_exception(s, msg, 00001);
 }
 
 static stmt*
@@ -745,11 +745,9 @@
                if (action == ACT_SET_DEFAULT) {
                        if (fc->c->def) {
                                stmt *sq;
-                               char buf[BUFSIZ];
-                                                
-                               snprintf(buf, BUFSIZ, "select %s;", fc->c->def);
-                               sq = scope_sqlparse(sql, NULL, buf, sql->mode);
-                                                
+                               char *msg = sql_message( "select %s;", 
fc->c->def);
+                               sq = scope_sqlparse(sql, NULL, msg, sql->mode);
+                               _DELETE(msg);
                                if (!sq || sq->type != st_list || 
list_length(sq->op1.lval) != 1) {
                                        cleanup_stmts(new_updates, len);
                                        list_destroy(l);
@@ -826,11 +824,9 @@
                } else if (action == ACT_SET_DEFAULT) {
                        if (fc->c->def) {
                                stmt *sq;
-                               char buf[BUFSIZ];
-                                                      
-                               snprintf(buf, BUFSIZ, "select %s;", fc->c->def);
-                               sq = scope_sqlparse(sql, NULL, buf, sql->mode);
-                                                        
+                               char *msg = sql_message( "select %s;", 
fc->c->def);
+                               sq = scope_sqlparse(sql, NULL, msg, sql->mode);
+                               _DELETE(msg);
                                if (!sq || sq->type != st_list || 
list_length(sq->op1.lval) != 1) {
                                        cleanup_stmts(new_updates, len);
                                        list_destroy(l);
@@ -1135,7 +1131,6 @@
 stmt *
 sql_insert(mvc *sql, sql_table *t, stmt **inserts, int len, int output)
 {
-       char buf[BUFSIZ];
        int i;
        list *l = create_stmt_list();
        node *n;
@@ -1158,6 +1153,7 @@
                }
                if (!c->null) {
                        stmt *s = inserts[c->colnr]->op2.stval;
+                       char *msg = NULL;
 
                        if (!(s->key && s->nrcols == 0)) {
                                s = stmt_atom(atom_general(&c->type, NULL, 0));
@@ -1168,8 +1164,8 @@
 
                                s = 
stmt_unop(stmt_dup(inserts[c->colnr]->op2.stval), isnil);
                        }
-                       snprintf(buf, BUFSIZ, "INSERT INTO: NOT NULL constraint 
violated for column %s.%s", c->t->base.name, c->base.name);
-                       s = stmt_exception(s, _strdup(buf), 00001);
+                       msg = sql_message( "INSERT INTO: NOT NULL constraint 
violated for column %s.%s", c->t->base.name, c->base.name);
+                       s = stmt_exception(s, msg, 00001);
 
                        list_prepend(l, s);
                }
@@ -1367,10 +1363,9 @@
 
                                        if (c->def) {
                                                stmt *sq;
-                                               char buf[BUFSIZ];
-
-                                               snprintf(buf, BUFSIZ, "select 
%s;", c->def);
-                                               sq = scope_sqlparse(sql, NULL, 
buf, sql->mode);
+                                               char *msg = sql_message( 
"select %s;", c->def);
+                                               sq = scope_sqlparse(sql, NULL, 
msg, sql->mode);
+                                               _DELETE(msg);
                                                if (!sq || sq->type != st_list 
|| list_length(sq->op1.lval) != 1) {
                                                        cond_stmt_destroy(sq);
                                                        cleanup_stmts(inserts, 
len);
@@ -1504,8 +1499,8 @@
                sql_column *c = n->data;
 
                if (updates[c->colnr] && !c->null) {
-                       char buf[BUFSIZ];
                        stmt *s = updates[c->colnr]->op2.stval;
+                       char *msg = NULL;
 
                        if (!(s->key && s->nrcols == 0)) {
                                s = stmt_atom(atom_general(&c->type, NULL, 0));
@@ -1516,8 +1511,8 @@
 
                                s = 
stmt_unop(stmt_dup(updates[c->colnr]->op2.stval), isnil);
                        }
-                       snprintf(buf, BUFSIZ, "UPDATE: NOT NULL constraint 
violated for column '%s.%s'", c->t->base.name, c->base.name);
-                       s = stmt_exception(s, _strdup(buf), 00001);
+                       msg = sql_message( "UPDATE: NOT NULL constraint 
violated for column '%s.%s'", c->t->base.name, c->base.name);
+                       s = stmt_exception(s, msg, 00001);
 
                        list_prepend(l, s);
                }
@@ -1779,7 +1774,7 @@
                sql_subtype *bt = sql_bind_localtype("bit");
                node *n;
                for(n = uk->keys->h; n; n = n->next) {
-                       char buf[BUFSIZ];
+                       char *msg = NULL;
                        sql_subaggr *cnt = sql_bind_aggr(sql->session->schema, 
"count", NULL);
                        sql_subfunc *ne = 
sql_bind_func_result(sql->session->schema, "<>", it, it, bt);
                        sql_key *fk = n->data;
@@ -1803,8 +1798,8 @@
                                default:        /*RESTRICT*/
                                        /* The overlap between deleted 
primaries and foreign should be empty */
                                        s = stmt_binop(stmt_aggr(s, NULL, cnt, 
1), stmt_atom_int(0), ne);
-                                       snprintf(buf, BUFSIZ, "DELETE: FOREIGN 
KEY constraint '%s.%s' violated", k->t->base.name, k->base.name);
-                                       s = stmt_exception(s, _strdup(buf), 
00001);
+                                       msg = sql_message( "DELETE: FOREIGN KEY 
constraint '%s.%s' violated", k->t->base.name, k->base.name);
+                                       s = stmt_exception(s, msg, 00001);
                                        list_prepend(l, s);
                        }
                }

Index: sql_schema.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_schema.mx,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -d -r1.131 -r1.132
--- sql_schema.mx       12 Jun 2007 17:25:43 -0000      1.131
+++ sql_schema.mx       21 Aug 2007 22:24:39 -0000      1.132
@@ -617,7 +617,7 @@
        char *server, * db, *db_alias, *user, *lang, *passwd; 
        int *id = GDKmalloc(sizeof(int)), *port = GDKmalloc(sizeof(int));
        symbol *user_symb = qname->h->next->next->next->next->data.sym;
-       char default_dbalias[BUFSIZ], default_lang[BUFSIZ];
+       char *default_dbalias;
        *port = (int) qname->h->next->data.ival;
        *id = -1;
        server = GDKstrdup(qname->h->data.sval);
@@ -626,15 +626,14 @@
        passwd = GDKstrdup(user_symb->data.lval->h->next->data.sval);
 
        if (qname->h->next->next->next->data.sval == NULL){
-               snprintf(default_dbalias, BUFSIZ, "%s_%s_%s", server, db, user);
-               db_alias = GDKstrdup(default_dbalias);
+               default_dbalias = sql_message( "%s_%s_%s", server, db, user);
+               db_alias = default_dbalias;
        } else {
                db_alias = GDKstrdup(qname->h->next->next->next->data.sval);
        }
 
        if (qname->h->next->next->next->next->next->data.sval == NULL){
-               snprintf(default_lang, BUFSIZ, "sql");
-               lang = GDKstrdup(default_lang);
+               lang = GDKstrdup("sql");
        }
        else {
                lang = 
GDKstrdup(qname->h->next->next->next->next->next->data.sval);
@@ -1255,10 +1254,11 @@
                                        res = stmt_append(stmt_bat(cs, 
stmt_basetable(t, t->base.name), INS), 
stmt_const(stmt_bat(mvc_first_column(sql, t), stmt_basetable(t, t->base.name), 
RDONLY), stmt_atom(a)));
                        } else {
                                stmt *sq, *val;
-                               char buf[BUFSIZ];
+                               char *msg = NULL;
 
-                               snprintf(buf, BUFSIZ, "select %s;", cs->def);
-                               sq = scope_sqlparse(sql, NULL, buf, sql->mode);
+                               msg = sql_message("select %s;", cs->def);
+                               sq = scope_sqlparse(sql, NULL, msg, sql->mode);
+                               _DELETE(msg);
                                if (!sq || sq->type != st_list || 
list_length(sq->op1.lval) != 1) {
                                        cond_stmt_destroy(sq);
                                        return NULL;

Index: sql_qc.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_qc.mx,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- sql_qc.mx   3 Jul 2007 11:40:02 -0000       1.40
+++ sql_qc.mx   21 Aug 2007 22:24:38 -0000      1.41
@@ -242,8 +242,7 @@
 cq *
 qc_insert(qc *cache, sql_allocator *sa, symbol *s, atom **params, int 
paramlen, int key, int type, char *cmd)
 {
-       char name[BUFSIZ];
-       int i;
+       int i, namelen;
        cq *n = NEW(cq);
 
        n->id = cache->id ++;
@@ -267,8 +266,9 @@
        n->key = key;
        n->codestring = cmd;
        n->count = 1;
-       (void) snprintf(name, BUFSIZ, "s%d_%d", n->id, cache->clientid);
-       n->name = sa_strdup(sa, name);
+       namelen = 3 + ((n->id+7)>>3) + ((cache->clientid+7)>>3);
+       n->name = sa_alloc(sa, namelen);
+       (void) snprintf(n->name, namelen, "s%d_%d", n->id, cache->clientid);
        cache->q = n;
        return n;
 }

Index: sql_psm.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_psm.mx,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- sql_psm.mx  26 Jul 2007 11:21:41 -0000      1.44
+++ sql_psm.mx  21 Aug 2007 22:24:38 -0000      1.45
@@ -504,7 +504,6 @@
        
        for (n = params->h; n; n = n->next) {
                dnode *an = n;
-               /*char subtype_name[BUFSIZ];*/
 
                if (param) {
                        an = n->data.lval->h;
@@ -547,34 +546,31 @@
        
        if (!instantiate && sql_bind_func_(s, fname, type_list)) {
                if (params) {
-                       char args[BUFSIZ], *arg_list = NULL;
+                       char *arg_list = NULL;
                        node *n;
                        
-                       if (type_list->cnt > 0) {
-       
-                               for (n = type_list->h; n; n = n->next) {
+                       for (n = type_list->h; n; n = n->next) {
                                char *tpe =  subtype2string((sql_subtype *) 
n->data);
                                
-                               if (arg_list)   
-                                       snprintf(args, BUFSIZ, "%s, %s", 
arg_list, tpe);
-                               else
-                                       snprintf(args, BUFSIZ, "%s", tpe);
-                               arg_list = GDKstrdup(args);
-                               _DELETE(tpe);   
+                               if (arg_list) {
+                                       arg_list = sql_message("%s, %s", 
arg_list, tpe);
+                                       _DELETE(tpe);   
+                               } else {
+                                       arg_list = tpe;
                                }
-                               
-                               list_destroy(type_list);
-                               
-                               return sql_error(sql, 02, "CREATE FUNCTION: 
name '%s' (%s) already in use", fname, arg_list);
                        }
+                       list_destroy(type_list);
                                
-                       return sql_error(sql, 02, "DROP FUNCTION: no such 
function '%s' ()", fname);
-
-               } else
-                       return sql_error(sql, 02, "DROP FUNCTION: no such 
function '%s'", fname);
+                       (void)sql_error(sql, 02, "CREATE FUNCTION: name '%s' 
(%s) already in use", fname, arg_list);
+                       _DELETE(arg_list);
+                       return NULL;
+               } else {
+                       return sql_error(sql, 02, "CREATE FUNCTION: name '%s' 
already in use", fname);
+               }
        
        } else {
-               list_destroy(type_list);
+               if (type_list)
+                       list_destroy(type_list);
        
                if (!instantiate && !schema_privs(sql->role_id, s)) {
                        return sql_error(sql, 02, "CREATE FUNCTION: 
insufficient privileges for user '%s' in schema '%s'", stack_get_string(sql, 
"current_user"), s->base.name);
@@ -671,22 +667,21 @@
        
        if (!func) { 
                if (typelist) {
-                       char args[BUFSIZ], *arg_list = NULL;
+                       char *arg_list = NULL;
                        node *n;
                        
                        if (type_list->cnt > 0) {
-       
                                for (n = type_list->h; n; n = n->next) {
-                               char *tpe =  subtype2string((sql_subtype *) 
n->data);
+                                       char *args;
+                                       char *tpe =  
subtype2string((sql_subtype *) n->data);
                                
-                               if (arg_list)   
-                                       snprintf(args, BUFSIZ, "%s, %s", 
arg_list, tpe);
-                               else
-                                       snprintf(args, BUFSIZ, "%s", tpe);
-                               arg_list = GDKstrdup(args);
-                               _DELETE(tpe);   
+                                       if (arg_list)   
+                                               args = sql_message( "%s, %s", 
arg_list, tpe);
+                                       else
+                                               args = sql_message( "%s", tpe);
+                                       arg_list = args;
+                                       _DELETE(tpe);   
                                }
-                               
                                list_destroy(type_list);
                                
                                return sql_error(sql, 02, "DROP %s: no such %s 
'%s' (%s)", F, f, name, arg_list);

Index: sql_parser.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_parser.mx,v
retrieving revision 1.250
retrieving revision 1.251
diff -u -d -r1.250 -r1.251
--- sql_parser.mx       21 Aug 2007 12:51:57 -0000      1.250
+++ sql_parser.mx       21 Aug 2007 22:24:37 -0000      1.251
@@ -172,6 +172,7 @@
 extern void *sql_error(mvc *sql, int error_code, char *format, ...);
 extern int parse_error(mvc *sql, char *s);
 extern int sqlparse(void *);
+extern char *sql_message(const char *format, ...);
 
 #endif /*_SQL_PARSER_H_*/
 
@@ -3012,9 +3013,9 @@
  |  scalar_exp ESCAPE string
        { char *s = sql2str($3);
          if (_strlen(s) != 1) {
-               char buf[BUFSIZ];
-               snprintf(buf, BUFSIZ, "ESCAPE must be one character");
-               yyerror(buf);
+               char *msg = sql_message("ESCAPE must be one character");
+               yyerror(msg);
+               _DELETE(msg)
                $$ = NULL;
                YYABORT;
          } else {
@@ -3569,7 +3570,6 @@
                  $$ = _newAtomNode( _atom_string(&t, s)); }
 
  |  HEXADECIMAL { int len = _strlen($1), i = 2, err = 0;
-                 char buf[BUFSIZ];
                  char * hexa = $1;
                  sql_subtype t;
                  long res = 0;
@@ -3598,8 +3598,10 @@
                        err = 1;
                  
                  if (err) {
-                       snprintf(buf, BUFSIZ, "invalid hexadecimal number or 
hexadecimal too large (%s)", $1);
-                       yyerror(buf);
+                       char *msg = sql_message("invalid hexadecimal number or 
hexadecimal too large (%s)", $1);
+
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -3631,10 +3633,10 @@
                  }
 
                  if (err) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("integer value too large or not 
a number (%s)", $1);
 
-                       snprintf(buf, BUFSIZ, "integer value too large or not a 
number (%s)", $1);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -3676,10 +3678,10 @@
 
                  r = sql_find_subtype(&t, "date", 0, 0 );
                  if (!r || (a = atom_general(&t, $2, 0)) == NULL) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("incorrect date value (%s)", 
$2);
 
-                       snprintf(buf, BUFSIZ, "incorrect date value (%s)", $2);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -3692,10 +3694,10 @@
 
                  r = sql_find_subtype(&t, ($3)?"timetz":"time", $2, 0);
                  if (!r || (a = atom_general(&t, $4, 0)) == NULL) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("incorrect time value (%s)", 
$4);
 
-                       snprintf(buf, BUFSIZ, "incorrect time value (%s)", $4);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -3708,10 +3710,10 @@
 
                  r = sql_find_subtype(&t, ($3)?"timestamptz":"timestamp",$2,0);
                  if (!r || (a = atom_general(&t, $4, 0)) == NULL) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("incorrect timestamp value 
(%s)", $4);
 
-                       snprintf(buf, BUFSIZ, "incorrect timestamp value (%s)", 
$4);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = NULL;
                        YYABORT;
                  } else {
@@ -3728,10 +3730,10 @@
                  if (r && (a = atom_general(&t, $2, 0)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("incorrect blob %s", $2);
 
-                       snprintf(buf, BUFSIZ, "incorrect blob %s", $2);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        if (a)
                                atom_destroy(a);
                        YYABORT;
@@ -3747,10 +3749,10 @@
                  if (r && (a = atom_general(&t, $2, 0)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("incorrect %s %s", $1, $2);
 
-                       snprintf(buf, BUFSIZ, "incorrect %s %s", $1, $2);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        if (a)
                                atom_destroy(a);
                        YYABORT;
@@ -3766,10 +3768,10 @@
                  if (r && (a = atom_general(&t, $2, 0)) != NULL)
                        $$ = _newAtomNode(a);
                  if (!$$) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("incorrect %s %s", $1, $2);
 
-                       snprintf(buf, BUFSIZ, "incorrect %s %s", $1, $2);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        if (a)
                                atom_destroy(a);
                        YYABORT;
@@ -3789,10 +3791,10 @@
                                $$ = _newAtomNode(a);
                  }
                  if (!t || !$$) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("type (%s) unknown", $1);
 
-                       snprintf(buf, BUFSIZ, "type (%s) unknown", $1);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        YYABORT;
                  }
                }
@@ -4023,10 +4025,9 @@
  |  sqlDECIMAL         { sql_find_subtype(&$$, "decimal", 1, 0); }
  |  sqlDECIMAL '(' nonzero ')'
                        { if ($3 > 18) {
-                               char buf[BUFSIZ];
-
-                               snprintf(buf, BUFSIZ, "decimal of " LLFMT " 
digits are not supported", $3);
-                               yyerror(buf);
+                               char *msg = sql_message("decimal of " LLFMT " 
digits are not supported", $3);
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -4035,13 +4036,13 @@
                        }
  |  sqlDECIMAL '(' nonzero ',' posint ')'
                        { if ($5 >= $3 || $5 + $3 > 18) {
-                               char buf[BUFSIZ];
-
+                               char *msg = NULL;
                                if ($5 >= $3)
-                                       snprintf(buf, BUFSIZ, "scale (" LLFMT 
") should be less than precision (" LLFMT ")", $5, $3);
+                                       msg = sql_message("scale (" LLFMT ") 
should be less than precision (" LLFMT ")", $5, $3);
                                else
-                                       snprintf(buf, BUFSIZ, "decimal(" LLFMT 
","LLFMT") isn't supported because P="LLFMT" + S="LLFMT" > 18", $3, $5, $3, $5);
-                               yyerror(buf);
+                                       msg = sql_message("decimal(" LLFMT 
","LLFMT") isn't supported because P="LLFMT" + S="LLFMT" > 18", $3, $5, $3, $5);
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -4055,19 +4056,20 @@
                          } else if ($3 > 24 && $3 <= 53) {
                                sql_find_subtype(&$$, "double", $3, 0);
                          } else {
-                               char buf[BUFSIZ];
-                               snprintf(buf, BUFSIZ, "number of digits for 
FLOAT values should be between 1 and 53");
-                               yyerror(buf);
+                               char *msg = sql_message("number of digits for 
FLOAT values should be between 1 and 53");
+
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          }
                        }
  |  sqlFLOAT '(' intval ',' intval ')'
                        { if ($5 >= $3) {
-                               char buf[BUFSIZ];
+                               char *msg = sql_message("precision(" LLFMT ") 
should be less than number of digits(" LLFMT ")", $5, $3);
 
-                               snprintf(buf, BUFSIZ, "precision(" LLFMT ") 
should be less than number of digits(" LLFMT ")", $5, $3);
-                               yyerror(buf);
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          } else if ($3 > 0 && $3 <= 24) {
@@ -4075,9 +4077,9 @@
                          } else if ($3 > 24 && $3 <= 53) {
                                sql_find_subtype(&$$, "double", $3, $5);
                          } else {
-                               char buf[BUFSIZ];
-                               snprintf(buf, BUFSIZ, "number of digits for 
FLOAT values should be between 1 and 53");
-                               yyerror(buf);
+                               char *msg = sql_message("number of digits for 
FLOAT values should be between 1 and 53");
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          }
@@ -4095,10 +4097,10 @@
                        { sql_find_subtype(&$$, $1, $3, 0); }
  | type_alias '(' intval ',' intval ')'
                        { if ($5 >= $3) {
-                               char buf[BUFSIZ];
+                               char *msg = sql_message("precision(" LLFMT ") 
should be less than number of digits(" LLFMT ")", $5, $3);
 
-                               snprintf(buf, BUFSIZ, "precision(" LLFMT ") 
should be less than number of digits(" LLFMT ")", $5, $3);
-                               yyerror(buf);
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -4108,10 +4110,10 @@
  | IDENT               { mvc *m = (mvc*)parm;
                          sql_type *t = mvc_bind_type(m, $1);
                          if (!t) {
-                               char buf[BUFSIZ];
+                               char *msg = sql_message("type (%s) unknown", 
$1);
 
-                               snprintf(buf, BUFSIZ, "type (%s) unknown", $1);
-                               yyerror(buf);
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -4123,10 +4125,10 @@
                        { mvc *m = (mvc*)parm;
                          sql_type *t = mvc_bind_type(m, $1);
                          if (!t) {
-                               char buf[BUFSIZ];
+                               char *msg = sql_message("type (%s) unknown", 
$1);
 
-                               snprintf(buf, BUFSIZ, "type (%s) unknown", $1);
-                               yyerror(buf);
+                               yyerror(msg);
+                               _DELETE(msg);
                                $$.type = NULL;
                                YYABORT;
                          } else {
@@ -4140,10 +4142,10 @@
  ALIAS
        {       char *t = sql_bind_alias($1);
                if (!t) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("type (%s) unknown", $1);
 
-                       snprintf(buf, BUFSIZ, "type (%s) unknown", $1);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = NULL;
                        YYABORT;
                }
@@ -4240,10 +4242,10 @@
                  stmt *var;
 
                  if (!(var = stack_find_var(m, name))) {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("constant (%s) unknown", $1);
 
-                       snprintf(buf, BUFSIZ, "constant (%s) unknown", $1);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = 0;
                        YYABORT;
                  }
@@ -4254,10 +4256,10 @@
                      tpe->type->localtype == TYPE_bte ) {
                        $$ = stack_get_number(m, name);
                  } else {
-                       char buf[BUFSIZ];
+                       char *msg = sql_message("constant (%s) has wrong type 
(number expected)", $1);
 
-                       snprintf(buf, BUFSIZ, "constant (%s) has wrong type 
(number expected)", $1);
-                       yyerror(buf);
+                       yyerror(msg);
+                       _DELETE(msg);
                        $$ = 0;
                        YYABORT;
                  }
@@ -4465,3 +4467,15 @@
                 err, QUERY(c->scanner));
        return 1;
 }
+
+char *sql_message( const char *format, ... )
+{
+       char buf[BUFSIZ];
+       va_list ap;
+
+       va_start (ap,format);
+       (void) vsnprintf( buf, BUFSIZ, format, ap); 
+       va_end (ap);
+       return _strdup(buf);
+}
+

Index: sql_sequence.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_sequence.mx,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- sql_sequence.mx     17 Apr 2007 10:35:26 -0000      1.42
+++ sql_sequence.mx     21 Aug 2007 22:24:40 -0000      1.43
@@ -163,13 +163,12 @@
 char*
 sql_next_seq_name(mvc *m)
 {
-       char buf[BUFSIZ + 1];
-
-       snprintf(buf, BUFSIZ, "seq_%d", store_next_oid());
-       buf[BUFSIZ] = '\0';
+       oid id = store_next_oid();
+       int len = 5 + ((id+7)>>3);
+       char *msg = sa_alloc(m->sa, len);
 
-       /* waring: using sa_strdup here */
-       return(sa_strdup(m->sa, buf));
+       snprintf(msg, len, "seq_%d", store_next_oid());
+       return msg;
 }
 
 stmt *

Index: sql_env.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_env.mx,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- sql_env.mx  3 May 2007 23:36:48 -0000       1.64
+++ sql_env.mx  21 Aug 2007 22:24:36 -0000      1.65
@@ -90,23 +90,19 @@
 str
 sql_update_var(mvc *m, char *name)
 {
-       char buf[BUFSIZ];
-
        if (strcmp(name, "debug") == 0) {
                m->debug = stack_get_number(m, "debug");
        } else if (strcmp(name, "current_schema") == 0) {
                char *schema = stack_get_string(m, "current_schema");
 
                if (!mvc_set_schema(m, schema)) {
-                       snprintf(buf, BUFSIZ, "Schema (%s) missing\n", schema);
-                       return _strdup(buf);
+                       return sql_message( "Schema (%s) missing\n", schema);
                }
        } else if (strcmp(name, "current_role") == 0) {
                char *role = stack_get_string(m, "current_role");
 
                if (!mvc_set_role(m, role)) {
-                       snprintf(buf, BUFSIZ, "Role (%s) missing\n", role);
-                       return _strdup(buf);
+                       return sql_message( "Role (%s) missing\n", role);
                }
        } else if (strcmp(name, "current_timezone") == 0) {
                m->timezone = stack_get_number(m, "current_timezone") / 60;
@@ -122,8 +118,7 @@
                else if (strcmp(explain, "trace") == 0)
                        m->explain = m_trace;
                else {
-                       snprintf(buf, BUFSIZ, "Session variable explain can 
only be set to 'plan', 'profile' or to the empty string\n");
-                       return _strdup(buf);
+                       return sql_message( "Session variable explain can only 
be set to 'plan', 'profile' or to the empty string\n");
                }
                m->mode = m_explain;
        } else if (strcmp(name, "cache") == 0) {


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to