patch to not sanitize namespace consistently
Terry Brown <[email protected]> Wed, 14 Jul 2010 12:10:52 -0500
| Newsgroups | gmane.comp.db.mdb-tools.devel |
|---|---|
| Message-ID | <[email protected]> |
mdb-export does not sanitize the namespace supplied by the user, which is good, and namespace like 'gc.' acts as a schema in postgres. This patch makes mdb-schema behave like mdb-export, and not sanitize the namespace. Previously mdb-schema would turn 'gc.' into 'gc_', which is unhelpful. As the user supplies the namespace, I don't think the user can complain if it's unsanitary :-) Also, this patch changes the behavior of sanitize_name; when the name starts with a digit the digit is *preceded* by an '_', rather than *replaced* by the '_'. So "2003 2004 Inventory" becomes "_2003_2004_Inventory", and not "_003_2004_Inventory". Cheers -Terry ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ mdbtools-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
schema_namespace.patch
(text/x-patch, 1.6 KB)
diff --git a/src/libmdb/backend.c b/src/libmdb/backend.c
index 0820bd5..17cae96 100644
--- a/src/libmdb/backend.c
+++ b/src/libmdb/backend.c
@@ -151,8 +151,10 @@ char* sanitize_name(const char* str)
if (*str) {
*p = isalpha(*str) ? *str : '_';
p++;
+ if (!isalnum(*str)) /* if it was a digit, keep it */
str++;
}
+
while (*str) {
*p = isalnum(*str) ? *str : '_';
p++;
@@ -160,6 +162,7 @@ char* sanitize_name(const char* str)
}
*p = 0;
+
return result;
}
diff --git a/src/util/mdb-schema.c b/src/util/mdb-schema.c
index 8ec3f84..c06f0e9 100644
--- a/src/util/mdb-schema.c
+++ b/src/util/mdb-schema.c
@@ -132,19 +132,18 @@ generate_table_schema(MdbCatalogEntry *entry, char *namespace, int sanitize)
char* quoted_name;
char* sql_sequences;
+ if (sanitize)
+ quoted_table_name = sanitize_name(entry->object_name);
+ else
+ quoted_table_name = mdb->default_backend->quote_name(entry->object_name);
+
if (namespace) {
- table_name = malloc(strlen(namespace)+strlen(entry->object_name)+1);
+ table_name = malloc(strlen(namespace)+strlen(quoted_table_name)+1);
strcpy(table_name, namespace);
- strcat(table_name, entry->object_name);
- } else
- {
- table_name = strdup(entry->object_name);
+ strcat(table_name, quoted_table_name);
+ free(quoted_table_name);
+ quoted_table_name = table_name;
}
- if (sanitize)
- quoted_table_name = sanitize_name(table_name);
- else
- quoted_table_name = mdb->default_backend->quote_name(table_name);
- free(table_name);
/* drop the table if it exists */
fprintf (stdout, "DROP TABLE %s;\n", quoted_table_name);