mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-07-16 11:46:45 +08:00
do not include table name in MySQL indexes.
This commit is contained in:
parent
fd230f68f2
commit
dbc7e51e98
@ -483,6 +483,48 @@ int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates index name based on backend.
|
||||
*
|
||||
* You should free() the returned value once you are done with it.
|
||||
*
|
||||
* @param backend backend we are generating indexes for
|
||||
* @param table table being processed
|
||||
* @param idx index being processed
|
||||
* @return the index name
|
||||
*/
|
||||
static char *
|
||||
mdb_get_index_name(int backend, MdbTableDef *table, MdbIndex *idx)
|
||||
{
|
||||
char *index_name;
|
||||
|
||||
switch(backend){
|
||||
case MDB_BACKEND_MYSQL:
|
||||
// appending table name to index often makes it too long for mysql
|
||||
index_name = malloc(strlen(idx->name)+5+1);
|
||||
if (idx->index_type==1)
|
||||
// for mysql name of primary key is not used
|
||||
strcpy(index_name, "_pkey");
|
||||
else {
|
||||
strcpy(index_name, idx->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
index_name = malloc(strlen(table->name)+strlen(idx->name)+5+1);
|
||||
strcpy(index_name, table->name);
|
||||
if (idx->index_type==1)
|
||||
strcat(index_name, "_pkey");
|
||||
else {
|
||||
strcat(index_name, "_");
|
||||
strcat(index_name, idx->name);
|
||||
strcat(index_name, "_idx");
|
||||
}
|
||||
}
|
||||
|
||||
return index_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* mdb_print_indexes
|
||||
* @output: Where to print the sql
|
||||
@ -507,8 +549,8 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
||||
} else if (!strcmp(mdb->backend_name, "mysql")) {
|
||||
backend = MDB_BACKEND_MYSQL;
|
||||
} else if (!strcmp(mdb->backend_name, "oracle")) {
|
||||
backend = MDB_BACKEND_ORACLE;
|
||||
} else {
|
||||
backend = MDB_BACKEND_ORACLE;
|
||||
} else {
|
||||
fprintf(outfile, "-- Indexes are not implemented for %s\n\n", mdb->backend_name);
|
||||
return;
|
||||
}
|
||||
@ -525,19 +567,11 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
||||
if (idx->index_type==2)
|
||||
continue;
|
||||
|
||||
index_name = malloc(strlen(table->name)+strlen(idx->name)+5+1);
|
||||
strcpy(index_name, table->name);
|
||||
if (idx->index_type==1)
|
||||
strcat(index_name, "_pkey");
|
||||
else {
|
||||
strcat(index_name, "_");
|
||||
strcat(index_name, idx->name);
|
||||
strcat(index_name, "_idx");
|
||||
}
|
||||
index_name = mdb_get_index_name(backend, table, idx);
|
||||
quoted_name = mdb->default_backend->quote_schema_name(dbnamespace, index_name);
|
||||
if (idx->index_type==1) {
|
||||
switch (backend) {
|
||||
case MDB_BACKEND_ORACLE:
|
||||
case MDB_BACKEND_ORACLE:
|
||||
case MDB_BACKEND_POSTGRES:
|
||||
fprintf (outfile, "ALTER TABLE %s ADD CONSTRAINT %s PRIMARY KEY (", quoted_table_name, quoted_name);
|
||||
break;
|
||||
@ -547,7 +581,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
||||
}
|
||||
} else {
|
||||
switch (backend) {
|
||||
case MDB_BACKEND_ORACLE:
|
||||
case MDB_BACKEND_ORACLE:
|
||||
case MDB_BACKEND_POSTGRES:
|
||||
fprintf(outfile, "CREATE");
|
||||
if (idx->flags & MDB_IDX_UNIQUE)
|
||||
|
Loading…
Reference in New Issue
Block a user