Patch nosanitize.diff form Nirgal

This commit is contained in:
Nirgal Vourgre 2011-08-28 18:56:03 -04:00 committed by Brian Bruns
parent b5cabb1834
commit 8ef50c444e
7 changed files with 20 additions and 90 deletions

View File

@ -1,7 +1,7 @@
NAME
mdb-export - Export data in an MDB database table to CSV format.
SYNOPSIS
mdb-export [-H] [-d <delimiter>] [-R <row delim>] [[-Q] || [-q <quote> [-X <escape>]]] [-I] [-D <format>] [-S] <database> <table>
mdb-export [-H] [-d <delimiter>] [-R <row delim>] [[-Q] || [-q <quote> [-X <escape>]]] [-I] [-D <format>] <database> <table>
DESCRIPTION
mdb-export is a utility program distributed with MDB Tools.
@ -15,7 +15,6 @@ OPTIONS
-R Specify a row delimiter
-I INSERT statements (instead of CSV). You must specify the SQL dialect.
-D Set the date format (see strftime(3) for details)
-S Sanitize names (replace spaces etc. with underscore)
-q Use to wrap text-like fields. Default is ".
-X Use to escape quoted characters within a field. Default is doubling.

View File

@ -22,8 +22,6 @@ OPTIONS
--no-indexes Don't export INDEXes.
--relations Export foreign keys constraints. This is the default.
--no-relations Don't export foreign keys constraints.
-S, --sanitize Replace non alphanumric characters by underscore.
--no-sanitize Don't replace non alphanumric characters by underscore. This is the default.
backend Specifies target DDL dialect. Supported values are access, sybase, oracle, postgres, and mysql. If not specified the generated DDL will be in access format.

View File

@ -161,8 +161,7 @@ enum {
MDB_SHEXP_COMMENTS = 1<<3, /* export comments on columns & tables */
MDB_SHEXP_DEFVALUES = 1<<4, /* export default values */
MDB_SHEXP_INDEXES = 1<<5, /* export indices */
MDB_SHEXP_RELATIONS = 1<<6, /* export relation (foreign keys) */
MDB_SHEXP_SANITIZE = 1<<7 /* clean up names */
MDB_SHEXP_RELATIONS = 1<<6 /* export relation (foreign keys) */
};
#define MDB_SHEXP_DEFAULT (MDB_SHEXP_CST_NOTNULL | MDB_SHEXP_COMMENTS | MDB_SHEXP_INDEXES | MDB_SHEXP_RELATIONS)
@ -483,7 +482,6 @@ extern int mdb_read_row(MdbTableDef *table, unsigned int row);
extern void buffer_dump(const void *buf, int start, size_t len);
/* backend.c */
extern char* sanitize_name(const char* name);
extern char* mdb_get_coltype_string(MdbBackend *backend, int col_type); /* obsolete */
extern int mdb_coltype_takes_length(MdbBackend *backend, int col_type); /* obsolete */
extern const MdbBackendType* mdb_get_colbacktype(const MdbColumn *col);

View File

@ -154,29 +154,6 @@ static MdbBackendType mdb_mysql_shortdate_type =
#ifndef JAVA
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data);
char* sanitize_name(const char* str)
{
char *result = malloc(256);
char *p = result;
if (*str) {
*p = isalpha(*str) ? *str : '_';
p++;
if (!isdigit(*str)) /* if it was a digit, keep it */
str++;
}
while (*str) {
*p = isalnum(*str) ? *str : '_';
p++;
str++;
}
*p = 0;
return result;
}
static gchar*
quote_generic(const gchar *value, gchar quote_char, gchar escape_char) {
gchar *result, *pr;
@ -338,7 +315,7 @@ void mdb_init_backends()
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
mdb_register_backend("access",
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_DEFVALUES|MDB_SHEXP_SANITIZE,
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_DEFVALUES,
mdb_access_types, NULL, NULL,
"Date()", "Date()",
"-- That file uses encoding %s\n",
@ -348,7 +325,7 @@ void mdb_init_backends()
NULL,
quote_schema_name_bracket_merge);
mdb_register_backend("sybase",
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_DEFVALUES|MDB_SHEXP_SANITIZE,
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_DEFVALUES,
mdb_sybase_types, &mdb_sybase_shortdate_type, NULL,
"getdate()", "getdate()",
"-- That file uses encoding %s\n",
@ -358,7 +335,7 @@ void mdb_init_backends()
"COMMENT ON TABLE %s IS %s;\n",
quote_schema_name_dquote);
mdb_register_backend("oracle",
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_COMMENTS|MDB_SHEXP_INDEXES|MDB_SHEXP_RELATIONS|MDB_SHEXP_DEFVALUES|MDB_SHEXP_SANITIZE,
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_COMMENTS|MDB_SHEXP_INDEXES|MDB_SHEXP_RELATIONS|MDB_SHEXP_DEFVALUES,
mdb_oracle_types, &mdb_oracle_shortdate_type, NULL,
"current_date", "sysdate",
"-- That file uses encoding %s\n",
@ -368,7 +345,7 @@ void mdb_init_backends()
"COMMENT ON TABLE %s IS %s;\n",
quote_schema_name_dquote);
mdb_register_backend("postgres",
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_INDEXES|MDB_SHEXP_RELATIONS|MDB_SHEXP_DEFVALUES|MDB_SHEXP_SANITIZE,
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_INDEXES|MDB_SHEXP_RELATIONS|MDB_SHEXP_DEFVALUES,
mdb_postgres_types, &mdb_postgres_shortdate_type, &mdb_postgres_serial_type,
"current_date", "now()",
"SET client_encoding = '%s';\n",
@ -378,7 +355,7 @@ void mdb_init_backends()
"COMMENT ON TABLE %s IS %s;\n",
quote_schema_name_dquote);
mdb_register_backend("mysql",
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_DEFVALUES|MDB_SHEXP_SANITIZE,
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_DEFVALUES,
mdb_mysql_types, &mdb_mysql_shortdate_type, NULL,
"current_date", "now()",
"-- That file uses encoding %s\n",
@ -453,7 +430,7 @@ int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name)
* @table: Table to process
*/
static void
mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int sanitize)
mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace)
{
unsigned int i, j;
char* quoted_table_name;
@ -473,9 +450,6 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
fprintf (outfile, "-- CREATE INDEXES ...\n");
if (sanitize)
quoted_table_name = sanitize_name(table->name);
else
quoted_table_name = mdb->default_backend->quote_schema_name(namespace, table->name);
for (i=0;i<table->num_idxs;i++) {
@ -492,9 +466,6 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
strcat(index_name, idx->name);
strcat(index_name, "_idx");
}
if (sanitize)
quoted_name = sanitize_name(index_name);
else
quoted_name = mdb->default_backend->quote_schema_name(namespace, index_name);
if (idx->index_type==1) {
fprintf (outfile, "ALTER TABLE %s ADD CONSTRAINT %s PRIMARY KEY (", quoted_table_name, quoted_name);
@ -511,9 +482,6 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
if (j)
fprintf(outfile, ", ");
col=g_ptr_array_index(table->columns,idx->key_col_num[j]-1);
if (sanitize)
quoted_name = sanitize_name(col->name);
else
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
fprintf (outfile, "%s", quoted_name);
if (idx->index_type!=1 && idx->key_col_order[j])
@ -667,13 +635,9 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
unsigned int i;
char* quoted_table_name;
char* quoted_name;
int sanitize = export_options & MDB_SHEXP_SANITIZE;
MdbProperties *props;
const char *prop_value;
if (sanitize)
quoted_table_name = sanitize_name(entry->object_name);
else
quoted_table_name = mdb->default_backend->quote_schema_name(namespace, entry->object_name);
/* drop the table if it exists */
@ -693,9 +657,6 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
for (i = 0; i < table->num_cols; i++) {
col = g_ptr_array_index (table->columns, i);
if (sanitize)
quoted_name = sanitize_name(col->name);
else
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
fprintf (outfile, "\t%s\t\t\t%s", quoted_name,
mdb_get_colbacktype_string (col));
@ -773,9 +734,6 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
if (!props)
continue;
if (sanitize)
quoted_name = sanitize_name(col->name);
else
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
if (export_options & MDB_SHEXP_CST_NOTEMPTY) {
@ -816,7 +774,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
if (export_options & MDB_SHEXP_INDEXES)
// prints all the indexes of that table
mdb_print_indexes(outfile, table, namespace, sanitize);
mdb_print_indexes(outfile, table, namespace);
free(quoted_table_name);

View File

@ -5,7 +5,6 @@ LIBMDB_1.0 {
# LIBMDB_2.0 {
global:
mdb_*;
sanitize_name;
kkd_to_props;
_mdb_put_int16;
_mdb_put_int32;

View File

@ -84,13 +84,12 @@ main(int argc, char **argv)
char header_row = 1;
char quote_text = 1;
char *insert_dialect = NULL;
char sanitize = 0;
char *namespace = "";
int opt;
char *value;
size_t length;
while ((opt=getopt(argc, argv, "HQq:X:d:D:R:I:N:S"))!=-1) {
while ((opt=getopt(argc, argv, "HQq:X:d:D:R:I:N:"))!=-1) {
switch (opt) {
case 'H':
header_row = 0;
@ -111,9 +110,6 @@ main(int argc, char **argv)
insert_dialect = (char*) g_strdup(optarg);
header_row = 0;
break;
case 'S':
sanitize = 1;
break;
case 'D':
mdb_set_date_fmt(optarg);
break;
@ -150,7 +146,6 @@ main(int argc, char **argv)
fprintf(stderr," -R <delimiter> specify a row delimiter\n");
fprintf(stderr," -I <backend> INSERT statements (instead of CSV)\n");
fprintf(stderr," -D <format> set the date format (see strftime(3) for details)\n");
fprintf(stderr," -S Sanitize names (replace spaces etc. with underscore)\n");
fprintf(stderr," -q <char> Use <char> to wrap text-like fields. Default is \".\n");
fprintf(stderr," -X <char> Use <char> to escape quoted characters within a field. Default is doubling.\n");
fprintf(stderr," -N <namespace> Prefix identifiers with namespace\n");
@ -206,7 +201,7 @@ main(int argc, char **argv)
col=g_ptr_array_index(table->columns,j);
if (j)
fputs(delimiter, stdout);
fputs(sanitize ? sanitize_name(col->name) : col->name, stdout);
fputs(col->name, stdout);
}
fputs("\n", stdout);
}
@ -215,18 +210,12 @@ main(int argc, char **argv)
if (insert_dialect) {
char *quoted_name;
if (sanitize)
quoted_name = sanitize_name(argv[optind + 1]);
else
quoted_name = mdb->default_backend->quote_schema_name(NULL, argv[optind + 1]);
fprintf(stdout, "INSERT INTO %s%s (", namespace, quoted_name);
free(quoted_name);
for (j=0;j<table->num_cols;j++) {
if (j>0) fputs(", ", stdout);
col=g_ptr_array_index(table->columns,j);
if (sanitize)
quoted_name = sanitize_name(col->name);
else
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
fputs(quoted_name, stdout);
free(quoted_name);

View File

@ -39,7 +39,6 @@ main (int argc, char **argv)
fprintf (stderr, "where options are:\n");
fprintf (stderr, " -T <table> Only create schema for named table\n");
fprintf (stderr, " -N <namespace> Prefix identifiers with namespace\n");
fprintf (stderr, " -S Sanitize names (replace spaces etc. with underscore)\n");
exit (1);
}
@ -64,11 +63,9 @@ main (int argc, char **argv)
{"no-indexes", 0, NULL, 0},
{"relations", 0, NULL, 0},
{"no-relations", 0, NULL, 0},
{"sanitize", 0, NULL, 'S'},
{"no-sanitize", 0, NULL, 0},
{NULL, 0, NULL, 0},
};
opt = getopt_long(argc, argv, "T:N:S", long_options, &option_index);
opt = getopt_long(argc, argv, "T:N:", long_options, &option_index);
if (opt == -1)
break;
@ -130,10 +127,6 @@ main (int argc, char **argv)
export_options &= ~MDB_SHEXP_RELATIONS;
break;
}
if (!strcmp(long_options[option_index].name, "no-sanitize")) {
export_options &= ~MDB_SHEXP_SANITIZE;
break;
}
fprintf(stderr, "unimplemented option %s", long_options[option_index].name);
if (optarg)
fprintf(stderr, " with arg %s", optarg);
@ -148,10 +141,6 @@ main (int argc, char **argv)
case 'N':
namespace = (char *) g_strdup(optarg);
break;
case 'S':
export_options |= MDB_SHEXP_SANITIZE;
break;
}
}