Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv30985

Modified Files:
        database.c database.h monetdb_set.c 
Log Message:
Reuse is good, factor out valid database name pattern check

U database.c
Index: database.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/database.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- database.c  20 Aug 2009 16:11:59 -0000      1.4
+++ database.c  9 Sep 2009 12:26:22 -0000       1.5
@@ -36,17 +36,11 @@
        'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
 
-char* db_create(char* dbname) {
-       sabdb *stats;
-       char* e;
+/* check if dbname matches [A-Za-z0-9-_]+ */
+char* db_validname(char *dbname) {
        size_t c;
-       char* dbfarm;
        char buf[8096];
-       char path[8096];
-       FILE *f;
-       unsigned int size;
 
-       /* check if dbname matches [A-Za-z0-9-_]+ */
        if (dbname[0] == '\0')
                return(strdup("database name should not be an empty string"));
        for (c = 0; dbname[c] != '\0'; c++) {
@@ -58,13 +52,29 @@
                                !(dbname[c] == '_')
                   )
                {
-                       snprintf(buf, sizeof(buf), "create: invalid character "
+                       snprintf(buf, sizeof(buf), "invalid character "
                                        "'%c' at " SZFMT " in database name 
'%s'",
                                        dbname[c], c, dbname);
                        return(strdup(buf));
                }
        }
 
+       return(NULL);
+}
+
+char* db_create(char* dbname) {
+       sabdb *stats;
+       size_t c;
+       char* e;
+       char* dbfarm;
+       char buf[8096];
+       char path[8096];
+       FILE *f;
+       unsigned int size;
+
+       if ((e = db_validname(dbname)) != NULL)
+               return(e);
+
        /* the argument is the database to create, see what Sabaoth can
         * tell us about it */
        if ((e = SABAOTHgetStatus(&stats, dbname)) != MAL_SUCCEED) {

U database.h
Index: database.h
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/database.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- database.h  20 Aug 2009 16:12:02 -0000      1.4
+++ database.h  9 Sep 2009 12:26:22 -0000       1.5
@@ -20,6 +20,7 @@
 #ifndef _SEEN_DATABASE_H
 #define _SEEN_DATABASE_H 1
 
+char* db_validname(char* dbname);
 char* db_create(char* dbname);
 char* db_destroy(char* dbname);
 

U monetdb_set.c
Index: monetdb_set.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb_set.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- monetdb_set.c       9 Sep 2009 12:11:41 -0000       1.5
+++ monetdb_set.c       9 Sep 2009 12:26:22 -0000       1.6
@@ -127,27 +127,18 @@
                                continue;
                        }
 
-                       /* check if dbname matches [A-Za-z0-9-_]+ */
-                       for (i = 0; value[i] != '\0'; i++) {
-                               if (
-                                               !(value[i] >= 'A' && value[i] 
<= 'Z') &&
-                                               !(value[i] >= 'a' && value[i] 
<= 'z') &&
-                                               !(value[i] >= '0' && value[i] 
<= '9') &&
-                                               !(value[i] == '-') &&
-                                               !(value[i] == '_')
-                                  )
-                               {
-                                       fprintf(stderr, "set: invalid character 
'%c' at %d "
-                                                       "in database name 
'%s'\n",
-                                                       value[i], i, value);
-                                       value[0] = '\0';
-                                       state |= 1;
-                                       break;
-                               }
-                       }
                        if (value[0] == '\0')
                                continue;
 
+                       /* check if dbname matches [A-Za-z0-9-_]+ */
+                       if ((p = db_validname(value)) != NULL) {
+                               fprintf(stderr, "set: %s\n", p);
+                               free(p);
+                               value[0] = '\0';
+                               state |= 1;
+                               break;
+                       }
+
                        /* construct path to new database */
                        snprintf(new, 512, "%s", stats->path);
                        p = strrchr(new, '/');


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to