mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-09-20 11:07:53 +08:00
Add MySQL support to mdb_print_indexes()
This commit is contained in:
@@ -393,7 +393,7 @@ MDB_CONSTRUCTOR(_mdb_init_backends)
|
|||||||
"COMMENT ON TABLE %s IS %s;\n",
|
"COMMENT ON TABLE %s IS %s;\n",
|
||||||
quote_schema_name_dquote);
|
quote_schema_name_dquote);
|
||||||
mdb_register_backend("mysql",
|
mdb_register_backend("mysql",
|
||||||
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_DEFVALUES,
|
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_INDEXES|MDB_SHEXP_DEFVALUES,
|
||||||
mdb_mysql_types, &mdb_mysql_shortdate_type, NULL,
|
mdb_mysql_types, &mdb_mysql_shortdate_type, NULL,
|
||||||
"current_date", "now()",
|
"current_date", "now()",
|
||||||
"-- That file uses encoding %s\n",
|
"-- That file uses encoding %s\n",
|
||||||
@@ -496,11 +496,17 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
|||||||
char* quoted_table_name;
|
char* quoted_table_name;
|
||||||
char* index_name;
|
char* index_name;
|
||||||
char* quoted_name;
|
char* quoted_name;
|
||||||
|
int backend;
|
||||||
MdbHandle* mdb = table->entry->mdb;
|
MdbHandle* mdb = table->entry->mdb;
|
||||||
MdbIndex *idx;
|
MdbIndex *idx;
|
||||||
MdbColumn *col;
|
MdbColumn *col;
|
||||||
|
|
||||||
if (strcmp(mdb->backend_name, "postgres")) {
|
|
||||||
|
if (!strcmp(mdb->backend_name, "postgres")) {
|
||||||
|
backend = MDB_BACKEND_POSTGRES;
|
||||||
|
} else if (!strcmp(mdb->backend_name, "mysql")) {
|
||||||
|
backend = MDB_BACKEND_MYSQL;
|
||||||
|
} else {
|
||||||
fprintf(outfile, "-- Indexes are not implemented for %s\n\n", mdb->backend_name);
|
fprintf(outfile, "-- Indexes are not implemented for %s\n\n", mdb->backend_name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -528,12 +534,29 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
|||||||
}
|
}
|
||||||
quoted_name = mdb->default_backend->quote_schema_name(dbnamespace, index_name);
|
quoted_name = mdb->default_backend->quote_schema_name(dbnamespace, index_name);
|
||||||
if (idx->index_type==1) {
|
if (idx->index_type==1) {
|
||||||
|
switch (backend) {
|
||||||
|
case MDB_BACKEND_POSTGRES:
|
||||||
fprintf (outfile, "ALTER TABLE %s ADD CONSTRAINT %s PRIMARY KEY (", quoted_table_name, quoted_name);
|
fprintf (outfile, "ALTER TABLE %s ADD CONSTRAINT %s PRIMARY KEY (", quoted_table_name, quoted_name);
|
||||||
|
break;
|
||||||
|
case MDB_BACKEND_MYSQL:
|
||||||
|
fprintf (outfile, "ALTER TABLE %s ADD PRIMARY KEY (", quoted_table_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
switch (backend) {
|
||||||
|
case MDB_BACKEND_POSTGRES:
|
||||||
fprintf(outfile, "CREATE");
|
fprintf(outfile, "CREATE");
|
||||||
if (idx->flags & MDB_IDX_UNIQUE)
|
if (idx->flags & MDB_IDX_UNIQUE)
|
||||||
fprintf (outfile, " UNIQUE");
|
fprintf (outfile, " UNIQUE");
|
||||||
fprintf(outfile, " INDEX %s ON %s (", quoted_name, quoted_table_name);
|
fprintf(outfile, " INDEX %s ON %s (", quoted_name, quoted_table_name);
|
||||||
|
break;
|
||||||
|
case MDB_BACKEND_MYSQL:
|
||||||
|
fprintf(outfile, "ALTER TABLE %s ADD", quoted_table_name);
|
||||||
|
if (idx->flags & MDB_IDX_UNIQUE)
|
||||||
|
fprintf (outfile, " UNIQUE");
|
||||||
|
fprintf(outfile, " INDEX %s (", quoted_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g_free(quoted_name);
|
g_free(quoted_name);
|
||||||
free(index_name);
|
free(index_name);
|
||||||
|
Reference in New Issue
Block a user