mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-07-17 21:29:09 +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
|
||||
@ -525,15 +567,7 @@ 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user