Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv797
Modified Files:
database.c database.h monetdb_set.c
Log Message:
move rename functionality to db_rename() func
U database.c
Index: database.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/database.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- database.c 9 Sep 2009 12:26:22 -0000 1.5
+++ database.c 9 Sep 2009 12:55:34 -0000 1.6
@@ -244,29 +244,83 @@
return(strdup(buf));
}
- if (stats != NULL) {
- if (stats->state == SABdbRunning) {
- snprintf(buf, sizeof(buf), "database '%s' is still
running, "
- "please stop database first", dbname);
- SABAOTHfreeStatus(&stats);
- return(strdup(buf));
- }
+ if (stats == NULL) {
+ snprintf(buf, sizeof(buf), "no such database: %s", dbname);
+ return(strdup(buf));
+ }
- /* annoyingly we have to delete file by file, and
- * directories recursively... */
- if ((e = deletedir(stats->path)) != NULL) {
- snprintf(buf, sizeof(buf), "failed to destroy '%s': %s",
- dbname, e);
- GDKfree(e);
- SABAOTHfreeStatus(&stats);
- return(strdup(buf));
- }
+ if (stats->state == SABdbRunning) {
+ snprintf(buf, sizeof(buf), "database '%s' is still running, "
+ "please stop database first", dbname);
+ SABAOTHfreeStatus(&stats);
+ return(strdup(buf));
+ }
+
+ /* annoyingly we have to delete file by file, and
+ * directories recursively... */
+ if ((e = deletedir(stats->path)) != NULL) {
+ snprintf(buf, sizeof(buf), "failed to destroy '%s': %s",
+ dbname, e);
+ GDKfree(e);
SABAOTHfreeStatus(&stats);
- } else {
- snprintf(buf, sizeof(buf), "no such database: %s", dbname);
return(strdup(buf));
}
+ SABAOTHfreeStatus(&stats);
return(NULL);
}
+char* db_rename(char *olddb, char *newdb) {
+ char new[1024];
+ char buf[8096];
+ char *p;
+ sabdb* stats;
+
+ if (olddb[0] == '\0' || newdb[0] == '\0')
+ return(strdup("database name should not be an empty string"));
+
+ /* check if dbname matches [A-Za-z0-9-_]+ */
+ if ((p = db_validname(newdb)) != NULL)
+ return(p);
+
+ if ((p = SABAOTHgetStatus(&stats, olddb)) != MAL_SUCCEED) {
+ snprintf(buf, sizeof(buf), "internal error: %s", p);
+ GDKfree(p);
+ return(strdup(buf));
+ }
+
+ if (stats == NULL) {
+ snprintf(buf, sizeof(buf), "no such database: %s", olddb);
+ return(strdup(buf));
+ }
+
+ if (stats->state == SABdbRunning) {
+ snprintf(buf, sizeof(buf), "database '%s' is still running, "
+ "please stop database first", olddb);
+ SABAOTHfreeStatus(&stats);
+ return(strdup(buf));
+ }
+
+ /* construct path to new database */
+ snprintf(new, sizeof(new), "%s", stats->path);
+ p = strrchr(new, '/');
+ if (p == NULL) {
+ snprintf(buf, sizeof(buf), "non-absolute database path? '%s'",
+ stats->path);
+ SABAOTHfreeStatus(&stats);
+ return(strdup(buf));
+ }
+ snprintf(p + 1, sizeof(new) - (p + 1 - new), "%s", newdb);
+
+ /* Renaming is as simple as changing the directory name. Since the
+ * logdir is below it, we don't need to bother about that either. */
+ if (rename(stats->path, new) != 0) {
+ snprintf(buf, sizeof(buf), "failed to rename database from "
+ "'%s' to '%s': %s\n", stats->path, new,
strerror(errno));
+ SABAOTHfreeStatus(&stats);
+ return(strdup(buf));
+ }
+
+ SABAOTHfreeStatus(&stats);
+ return(NULL);
+}
U database.h
Index: database.h
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/database.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- database.h 9 Sep 2009 12:26:22 -0000 1.5
+++ database.h 9 Sep 2009 12:55:34 -0000 1.6
@@ -23,5 +23,6 @@
char* db_validname(char* dbname);
char* db_create(char* dbname);
char* db_destroy(char* dbname);
+char* db_rename(char *olddb, char *newdb);
#endif
U monetdb_set.c
Index: monetdb_set.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb_set.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- monetdb_set.c 9 Sep 2009 12:26:22 -0000 1.6
+++ monetdb_set.c 9 Sep 2009 12:55:34 -0000 1.7
@@ -118,8 +118,6 @@
for (stats = orig; stats != NULL; stats = stats->next) {
if (strcmp(property, "name") == 0) {
- char new[512];
-
/* special virtual case */
if (type == INHERIT) {
fprintf(stderr, "inherit: cannot default to a
database name\n");
@@ -130,35 +128,12 @@
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, '/');
- if (p == NULL) {
- fprintf(stderr, "set: non-absolute database
path? '%s'\n",
- stats->path);
+ if ((e = db_rename(stats->dbname, value)) != NULL) {
+ fprintf(stderr, "set: %s\n", e);
+ free(e);
state |= 1;
continue;
}
- snprintf(p + 1, 512 - (p + 1 - new), "%s", value);
-
- /* Renaming is as simple as changing the directory name.
- * Since the logdir is relative to it, we don't need to
- * bother about that either. */
- if (rename(stats->path, new) != 0) {
- fprintf(stderr, "%s: failed to rename database
from "
- "'%s' to '%s': %s\n", argv[0],
stats->path, new,
- strerror(errno));
- state |= 1;
- }
} else if (strcmp(property, "shared") == 0) {
char share[4069];
char *res;
------------------------------------------------------------------------------
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