mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-11-25 17:59:54 +08:00
patch 'schema2' from Nirgal Vourgère
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
NAME
|
NAME
|
||||||
mdb-schema - Generate schema creation DDL
|
mdb-schema - Generate schema creation DDL
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
mdb-schema [-T <table>] <database> [<backend>]
|
mdb-schema [options] <database> [<backend>]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
mdb-schema is a utility program distributed with MDB Tools.
|
mdb-schema is a utility program distributed with MDB Tools.
|
||||||
@@ -9,8 +9,35 @@ DESCRIPTION
|
|||||||
It produces DDL (data definition language) output for the given database. This can be passed to another database to create a replica of the original access table format.
|
It produces DDL (data definition language) output for the given database. This can be passed to another database to create a replica of the original access table format.
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-T Single table option. Create schema for this table only.
|
-T <table>, --table <table> Single table option. Create schema for this table only. Default is to export all tables.
|
||||||
backend Specifies target DDL dialect. Supported values are access, sybase, oracle, and postgres. If not specified the generated DDL will be in access format.
|
--drop-table Issue DROP TABLE statement.
|
||||||
|
--no-drop-table Don't issue DROP TABLE statement. This is the default.
|
||||||
|
--not-null Issue NOT NULL constraints. This is the default.
|
||||||
|
--no-not-null Don't issue NOT NULL constraints.
|
||||||
|
--not-empty Issue CHECK <> '' constraints.
|
||||||
|
--no-not-empty Don't issue CHECK <> '' constraints. This is the default.
|
||||||
|
--indexes Export INDEXes. This is the default.
|
||||||
|
--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.
|
||||||
|
|
||||||
|
ENVIRONMENT
|
||||||
|
MDB_JET3_CHARSET Defines the charset of the input JET3 (access 97) file. Default is CP1252. See iconv(1).
|
||||||
|
MDBICONV Defines the output charset to use for the SQL file. Default is UTF-8. mdbtools must have been compiled with iconv.
|
||||||
|
MDBOPTS semi-column separated list of options:
|
||||||
|
* use_index
|
||||||
|
* no_memo
|
||||||
|
* debug_like
|
||||||
|
* debug_write
|
||||||
|
* debug_usage
|
||||||
|
* debug_ole
|
||||||
|
* debug_row
|
||||||
|
* debug_props
|
||||||
|
* debug_all is a shortcut for all debug_* options
|
||||||
|
|
||||||
NOTES
|
NOTES
|
||||||
|
|
||||||
@@ -18,7 +45,7 @@ HISTORY
|
|||||||
mdb-schema first appeared in MDB Tools 0\.1
|
mdb-schema first appeared in MDB Tools 0\.1
|
||||||
|
|
||||||
AUTHORS
|
AUTHORS
|
||||||
The mdb-schema utility was written by Brian Bruns
|
The mdb-schema utility was written by Brian Bruns and others.
|
||||||
|
|
||||||
BUGS
|
BUGS
|
||||||
Relationships and other features may not be supported by all databases.
|
Relationships and other features may not be supported by all databases.
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ enum {
|
|||||||
MDB_MONEY = 0x05,
|
MDB_MONEY = 0x05,
|
||||||
MDB_FLOAT = 0x06,
|
MDB_FLOAT = 0x06,
|
||||||
MDB_DOUBLE = 0x07,
|
MDB_DOUBLE = 0x07,
|
||||||
MDB_SDATETIME = 0x08,
|
MDB_DATETIME = 0x08,
|
||||||
MDB_BINARY = 0x09,
|
MDB_BINARY = 0x09,
|
||||||
MDB_TEXT = 0x0a,
|
MDB_TEXT = 0x0a,
|
||||||
MDB_OLE = 0x0b,
|
MDB_OLE = 0x0b,
|
||||||
@@ -155,12 +155,15 @@ enum {
|
|||||||
|
|
||||||
/* export schema options */
|
/* export schema options */
|
||||||
enum {
|
enum {
|
||||||
MDB_SHEXP_DROPTABLE = 0x01,
|
MDB_SHEXP_DROPTABLE = 1<<0, /* issue drop table during export */
|
||||||
MDB_SHEXP_INDEXES = 0x02,
|
MDB_SHEXP_CST_NOTNULL = 1<<1, /* generate NOT NULL constraints */
|
||||||
MDB_SHEXP_RELATIONS = 0x04,
|
MDB_SHEXP_CST_NOTEMPTY = 1<<2, /* <>'' constraints */
|
||||||
MDB_SHEXP_SANITIZE = 0x08
|
MDB_SHEXP_COMMENTS = 1<<3, /* export comments on columns & tables */
|
||||||
|
MDB_SHEXP_INDEXES = 1<<4, /* export indices */
|
||||||
|
MDB_SHEXP_RELATIONS = 1<<5, /* export relation (foreign keys) */
|
||||||
|
MDB_SHEXP_SANITIZE = 1<<6 /* clean up names */
|
||||||
};
|
};
|
||||||
#define MDB_SHEXP_DEFAULT (MDB_SHEXP_DROPTABLE | MDB_SHEXP_INDEXES | MDB_SHEXP_RELATIONS)
|
#define MDB_SHEXP_DEFAULT (MDB_SHEXP_CST_NOTNULL | MDB_SHEXP_COMMENTS | MDB_SHEXP_INDEXES | MDB_SHEXP_RELATIONS)
|
||||||
|
|
||||||
#define IS_JET4(mdb) (mdb->f->jet_version==MDB_VER_JET4)
|
#define IS_JET4(mdb) (mdb->f->jet_version==MDB_VER_JET4)
|
||||||
#define IS_JET3(mdb) (mdb->f->jet_version==MDB_VER_JET3)
|
#define IS_JET3(mdb) (mdb->f->jet_version==MDB_VER_JET3)
|
||||||
@@ -177,8 +180,16 @@ typedef struct {
|
|||||||
} MdbBackendType;
|
} MdbBackendType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MdbBackendType *types_table;
|
guint32 capabilities; /* see MDB_SHEXP_* */
|
||||||
char* (*quote_name)(const char*);
|
MdbBackendType *types_table;
|
||||||
|
MdbBackendType *type_shortdate;
|
||||||
|
MdbBackendType *type_autonum;
|
||||||
|
const char *charset_statement;
|
||||||
|
const char *drop_statement;
|
||||||
|
const char *constaint_not_empty_statement;
|
||||||
|
const char *column_comment_statement;
|
||||||
|
const char *table_comment_statement;
|
||||||
|
gchar* (*quote_schema_name)(const gchar*, const gchar*);
|
||||||
} MdbBackend;
|
} MdbBackend;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -266,7 +277,9 @@ typedef union {
|
|||||||
char s[256];
|
char s[256];
|
||||||
} MdbAny;
|
} MdbAny;
|
||||||
|
|
||||||
|
struct S_MdbTableDef; /* forward definition */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
struct S_MdbTableDef *table;
|
||||||
char name[MDB_MAX_OBJ_NAME+1];
|
char name[MDB_MAX_OBJ_NAME+1];
|
||||||
int col_type;
|
int col_type;
|
||||||
int col_size;
|
int col_size;
|
||||||
@@ -329,7 +342,7 @@ typedef struct {
|
|||||||
MdbIndexPage pages[MDB_MAX_INDEX_DEPTH];
|
MdbIndexPage pages[MDB_MAX_INDEX_DEPTH];
|
||||||
} MdbIndexChain;
|
} MdbIndexChain;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct S_MdbTableDef {
|
||||||
MdbCatalogEntry *entry;
|
MdbCatalogEntry *entry;
|
||||||
char name[MDB_MAX_OBJ_NAME+1];
|
char name[MDB_MAX_OBJ_NAME+1];
|
||||||
unsigned int num_cols;
|
unsigned int num_cols;
|
||||||
@@ -468,10 +481,13 @@ extern void buffer_dump(const void *buf, int start, size_t len);
|
|||||||
|
|
||||||
/* backend.c */
|
/* backend.c */
|
||||||
extern char* sanitize_name(const char* name);
|
extern char* sanitize_name(const char* name);
|
||||||
extern char *mdb_get_coltype_string(MdbBackend *backend, int col_type);
|
extern char* mdb_get_coltype_string(MdbBackend *backend, int col_type); /* obsolete */
|
||||||
extern int mdb_coltype_takes_length(MdbBackend *backend, int col_type);
|
extern int mdb_coltype_takes_length(MdbBackend *backend, int col_type); /* obsolete */
|
||||||
|
extern const MdbBackendType* mdb_get_colbacktype(const MdbColumn *col);
|
||||||
|
extern const char* mdb_get_colbacktype_string(const MdbColumn *col);
|
||||||
|
extern int mdb_colbacktype_takes_length(const MdbColumn *col);
|
||||||
extern void mdb_init_backends();
|
extern void mdb_init_backends();
|
||||||
extern void mdb_register_backend(MdbBackendType *backend, char* (*quote_name)(const char*), char *backend_name);
|
extern void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendType *backend_type, MdbBackendType *type_shortdate, MdbBackendType *type_autonum, const char *charset_statement, const char *drop_statement, const char *constaint_not_empty_statement, const char *column_comment_statement, const char *table_comment_statement, gchar* (*quote_schema_name)(const gchar*, const gchar*));
|
||||||
extern void mdb_remove_backends();
|
extern void mdb_remove_backends();
|
||||||
extern int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name);
|
extern int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name);
|
||||||
extern void mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *namespace, guint32 export_options);
|
extern void mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *namespace, guint32 export_options);
|
||||||
@@ -546,6 +562,7 @@ extern int mdb_unicode2ascii(MdbHandle *mdb, char *src, size_t slen, char *dest,
|
|||||||
extern int mdb_ascii2unicode(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dlen);
|
extern int mdb_ascii2unicode(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dlen);
|
||||||
extern void mdb_iconv_init(MdbHandle *mdb);
|
extern void mdb_iconv_init(MdbHandle *mdb);
|
||||||
extern void mdb_iconv_close(MdbHandle *mdb);
|
extern void mdb_iconv_close(MdbHandle *mdb);
|
||||||
|
extern const char* mdb_target_charset(MdbHandle *mdb);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,443 +1,433 @@
|
|||||||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
<?xml version="1.0"?>
|
||||||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
|
||||||
|
|
||||||
<glade-interface>
|
<glade-interface>
|
||||||
<requires lib="gnome"/>
|
<!-- interface-requires gtk+ 2.6 -->
|
||||||
|
<requires lib="gnome"/>
|
||||||
<widget class="GtkDialog" id="schema_dialog">
|
<!-- interface-requires gnome 2412.41848 -->
|
||||||
<property name="visible">True</property>
|
<!-- interface-naming-policy toplevel-contextual -->
|
||||||
<property name="title" translatable="yes">Export Schema</property>
|
<widget class="GtkDialog" id="schema_dialog">
|
||||||
<property name="type">GTK_WINDOW_TOPLEVEL</property>
|
<property name="visible">True</property>
|
||||||
<property name="window_position">GTK_WIN_POS_NONE</property>
|
<property name="title" translatable="yes">Export Schema</property>
|
||||||
<property name="modal">False</property>
|
<property name="type_hint">normal</property>
|
||||||
<property name="resizable">True</property>
|
<child internal-child="vbox">
|
||||||
<property name="destroy_with_parent">False</property>
|
<widget class="GtkVBox" id="dialog-vbox1">
|
||||||
<property name="has_separator">True</property>
|
<property name="visible">True</property>
|
||||||
|
<child>
|
||||||
<child internal-child="vbox">
|
<widget class="GtkTable" id="table1">
|
||||||
<widget class="GtkVBox" id="dialog-vbox1">
|
<property name="visible">True</property>
|
||||||
<property name="visible">True</property>
|
<property name="border_width">33</property>
|
||||||
<property name="homogeneous">False</property>
|
<property name="n_rows">9</property>
|
||||||
<property name="spacing">0</property>
|
<property name="n_columns">2</property>
|
||||||
|
<property name="column_spacing">30</property>
|
||||||
<child internal-child="action_area">
|
<property name="row_spacing">8</property>
|
||||||
<widget class="GtkHButtonBox" id="dialog-action_area1">
|
<child>
|
||||||
<property name="visible">True</property>
|
<widget class="GtkLabel" id="label2">
|
||||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
<child>
|
<property name="label" translatable="yes"><b>Table:</b></property>
|
||||||
<widget class="GtkButton" id="cancelbutton1">
|
<property name="use_markup">True</property>
|
||||||
<property name="visible">True</property>
|
<property name="justify">right</property>
|
||||||
<property name="can_default">True</property>
|
</widget>
|
||||||
<property name="can_focus">True</property>
|
<packing>
|
||||||
<property name="label">gtk-help</property>
|
<property name="top_attach">1</property>
|
||||||
<property name="use_stock">True</property>
|
<property name="bottom_attach">2</property>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<property name="x_options">GTK_FILL</property>
|
||||||
<property name="response_id">-11</property>
|
<property name="y_options"></property>
|
||||||
<signal name="clicked" handler="gmdb_schema_help_cb" last_modification_time="Tue, 14 Jan 2003 14:45:37 GMT"/>
|
</packing>
|
||||||
</widget>
|
</child>
|
||||||
</child>
|
<child>
|
||||||
|
<widget class="GtkLabel" id="label3">
|
||||||
<child>
|
<property name="visible">True</property>
|
||||||
<widget class="GtkButton" id="okbutton1">
|
<property name="xalign">0</property>
|
||||||
<property name="visible">True</property>
|
<property name="label" translatable="yes"><b>Schema Dialect:</b></property>
|
||||||
<property name="can_default">True</property>
|
<property name="use_markup">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="justify">right</property>
|
||||||
<property name="label">gtk-cancel</property>
|
</widget>
|
||||||
<property name="use_stock">True</property>
|
<packing>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<property name="top_attach">2</property>
|
||||||
<property name="response_id">-6</property>
|
<property name="bottom_attach">3</property>
|
||||||
<signal name="clicked" handler="gtk_widget_destroy" object="schema_dialog" last_modification_time="Mon, 12 Jan 2004 18:40:24 GMT"/>
|
<property name="x_options">GTK_FILL</property>
|
||||||
</widget>
|
<property name="y_options"></property>
|
||||||
</child>
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkButton" id="button1">
|
<widget class="GtkCombo" id="table_combo">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_default">True</property>
|
<property name="enable_arrows_always">False</property>
|
||||||
<property name="can_focus">True</property>
|
<child internal-child="entry">
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<widget class="GtkEntry" id="combo-entry1">
|
||||||
<property name="response_id">-5</property>
|
<property name="visible">True</property>
|
||||||
<signal name="clicked" handler="gmdb_schema_export_cb" last_modification_time="Tue, 14 Jan 2003 14:46:39 GMT"/>
|
<property name="can_focus">True</property>
|
||||||
|
<property name="text" translatable="yes">Access</property>
|
||||||
<child>
|
</widget>
|
||||||
<widget class="GtkAlignment" id="alignment2">
|
<packing>
|
||||||
<property name="visible">True</property>
|
<property name="position">0</property>
|
||||||
<property name="xalign">0.5</property>
|
</packing>
|
||||||
<property name="yalign">0.5</property>
|
</child>
|
||||||
<property name="xscale">0</property>
|
<child internal-child="list">
|
||||||
<property name="yscale">0</property>
|
<widget class="GtkList" id="combo-list1">
|
||||||
|
<property name="visible">True</property>
|
||||||
<child>
|
<property name="selection_mode">browse</property>
|
||||||
<widget class="GtkHBox" id="hbox2">
|
</widget>
|
||||||
<property name="visible">True</property>
|
</child>
|
||||||
<property name="homogeneous">False</property>
|
</widget>
|
||||||
<property name="spacing">2</property>
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
<child>
|
<property name="right_attach">2</property>
|
||||||
<widget class="GtkImage" id="image2">
|
<property name="top_attach">1</property>
|
||||||
<property name="visible">True</property>
|
<property name="bottom_attach">2</property>
|
||||||
<property name="stock">gtk-convert</property>
|
<property name="y_options"></property>
|
||||||
<property name="icon_size">4</property>
|
</packing>
|
||||||
<property name="xalign">0.5</property>
|
</child>
|
||||||
<property name="yalign">0.5</property>
|
<child>
|
||||||
<property name="xpad">0</property>
|
<widget class="GtkCombo" id="backend_combo">
|
||||||
<property name="ypad">0</property>
|
<property name="visible">True</property>
|
||||||
</widget>
|
<property name="enable_arrows_always">False</property>
|
||||||
<packing>
|
<property name="allow_empty">False</property>
|
||||||
<property name="padding">0</property>
|
<property name="value_in_list">True</property>
|
||||||
<property name="expand">False</property>
|
<child internal-child="entry">
|
||||||
<property name="fill">False</property>
|
<widget class="GtkEntry" id="entry">
|
||||||
</packing>
|
<property name="visible">True</property>
|
||||||
</child>
|
<property name="can_focus">True</property>
|
||||||
|
<property name="editable">False</property>
|
||||||
<child>
|
<property name="text" translatable="yes">Access</property>
|
||||||
<widget class="GtkLabel" id="label6">
|
</widget>
|
||||||
<property name="visible">True</property>
|
<packing>
|
||||||
<property name="label" translatable="yes">_Export</property>
|
<property name="position">0</property>
|
||||||
<property name="use_underline">True</property>
|
</packing>
|
||||||
<property name="use_markup">False</property>
|
</child>
|
||||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
<child internal-child="list">
|
||||||
<property name="wrap">False</property>
|
<widget class="GtkList" id="combo-list2">
|
||||||
<property name="selectable">False</property>
|
<property name="visible">True</property>
|
||||||
<property name="xalign">0.5</property>
|
<property name="selection_mode">browse</property>
|
||||||
<property name="yalign">0.5</property>
|
<child>
|
||||||
<property name="xpad">0</property>
|
<widget class="GtkListItem" id="listitem141">
|
||||||
<property name="ypad">0</property>
|
<property name="visible">True</property>
|
||||||
</widget>
|
<property name="can_focus">True</property>
|
||||||
<packing>
|
<property name="label" translatable="yes">Access</property>
|
||||||
<property name="padding">0</property>
|
</widget>
|
||||||
<property name="expand">False</property>
|
</child>
|
||||||
<property name="fill">False</property>
|
<child>
|
||||||
</packing>
|
<widget class="GtkListItem" id="listitem142">
|
||||||
</child>
|
<property name="visible">True</property>
|
||||||
</widget>
|
<property name="can_focus">True</property>
|
||||||
</child>
|
<property name="label" translatable="yes">Oracle</property>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
<child>
|
||||||
</child>
|
<widget class="GtkListItem" id="listitem143">
|
||||||
</widget>
|
<property name="visible">True</property>
|
||||||
<packing>
|
<property name="can_focus">True</property>
|
||||||
<property name="padding">0</property>
|
<property name="label" translatable="yes">Sybase</property>
|
||||||
<property name="expand">False</property>
|
</widget>
|
||||||
<property name="fill">True</property>
|
</child>
|
||||||
<property name="pack_type">GTK_PACK_END</property>
|
<child>
|
||||||
</packing>
|
<widget class="GtkListItem" id="listitem144">
|
||||||
</child>
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
<child>
|
<property name="label" translatable="yes">MS SQL Server</property>
|
||||||
<widget class="GtkTable" id="table1">
|
</widget>
|
||||||
<property name="border_width">33</property>
|
</child>
|
||||||
<property name="visible">True</property>
|
<child>
|
||||||
<property name="n_rows">5</property>
|
<widget class="GtkListItem" id="listitem145">
|
||||||
<property name="n_columns">2</property>
|
<property name="visible">True</property>
|
||||||
<property name="homogeneous">False</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="row_spacing">8</property>
|
<property name="label" translatable="yes">PostgreSQL</property>
|
||||||
<property name="column_spacing">30</property>
|
</widget>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkLabel" id="label2">
|
<widget class="GtkListItem" id="listitem146">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label" translatable="yes"><b>Table:</b></property>
|
<property name="can_focus">True</property>
|
||||||
<property name="use_underline">False</property>
|
<property name="label" translatable="yes">MySQL</property>
|
||||||
<property name="use_markup">True</property>
|
</widget>
|
||||||
<property name="justify">GTK_JUSTIFY_RIGHT</property>
|
</child>
|
||||||
<property name="wrap">False</property>
|
</widget>
|
||||||
<property name="selectable">False</property>
|
</child>
|
||||||
<property name="xalign">0</property>
|
</widget>
|
||||||
<property name="yalign">0.5</property>
|
<packing>
|
||||||
<property name="xpad">0</property>
|
<property name="left_attach">1</property>
|
||||||
<property name="ypad">0</property>
|
<property name="right_attach">2</property>
|
||||||
</widget>
|
<property name="top_attach">2</property>
|
||||||
<packing>
|
<property name="bottom_attach">3</property>
|
||||||
<property name="left_attach">0</property>
|
<property name="y_options"></property>
|
||||||
<property name="right_attach">1</property>
|
</packing>
|
||||||
<property name="top_attach">1</property>
|
</child>
|
||||||
<property name="bottom_attach">2</property>
|
<child>
|
||||||
<property name="x_options">fill</property>
|
<widget class="GtkLabel" id="label4">
|
||||||
<property name="y_options"></property>
|
<property name="visible">True</property>
|
||||||
</packing>
|
<property name="xalign">0</property>
|
||||||
</child>
|
<property name="label" translatable="yes"><b>Options:</b></property>
|
||||||
|
<property name="use_markup">True</property>
|
||||||
<child>
|
<property name="justify">right</property>
|
||||||
<widget class="GtkLabel" id="label3">
|
</widget>
|
||||||
<property name="visible">True</property>
|
<packing>
|
||||||
<property name="label" translatable="yes"><b>Schema Dialect:</b></property>
|
<property name="top_attach">3</property>
|
||||||
<property name="use_underline">False</property>
|
<property name="bottom_attach">4</property>
|
||||||
<property name="use_markup">True</property>
|
<property name="x_options">GTK_FILL</property>
|
||||||
<property name="justify">GTK_JUSTIFY_RIGHT</property>
|
<property name="y_options"></property>
|
||||||
<property name="wrap">False</property>
|
</packing>
|
||||||
<property name="selectable">False</property>
|
</child>
|
||||||
<property name="xalign">0</property>
|
<child>
|
||||||
<property name="yalign">0.5</property>
|
<widget class="GtkLabel" id="label5">
|
||||||
<property name="xpad">0</property>
|
<property name="visible">True</property>
|
||||||
<property name="ypad">0</property>
|
<property name="xalign">0</property>
|
||||||
</widget>
|
<property name="label" translatable="yes"><b>File Name:</b></property>
|
||||||
<packing>
|
<property name="use_markup">True</property>
|
||||||
<property name="left_attach">0</property>
|
</widget>
|
||||||
<property name="right_attach">1</property>
|
<packing>
|
||||||
<property name="top_attach">2</property>
|
<property name="x_options">GTK_FILL</property>
|
||||||
<property name="bottom_attach">3</property>
|
<property name="y_options"></property>
|
||||||
<property name="x_options">fill</property>
|
</packing>
|
||||||
<property name="y_options"></property>
|
</child>
|
||||||
</packing>
|
<child>
|
||||||
</child>
|
<widget class="GnomeFileEntry" id="fileentry1">
|
||||||
|
<property name="visible">True</property>
|
||||||
<child>
|
<property name="max_saved">10</property>
|
||||||
<widget class="GtkCombo" id="table_combo">
|
<child internal-child="entry">
|
||||||
<property name="visible">True</property>
|
<widget class="GtkEntry" id="filename_entry">
|
||||||
<property name="value_in_list">False</property>
|
<property name="visible">True</property>
|
||||||
<property name="allow_empty">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="case_sensitive">False</property>
|
</widget>
|
||||||
<property name="enable_arrow_keys">True</property>
|
</child>
|
||||||
<property name="enable_arrows_always">False</property>
|
</widget>
|
||||||
|
<packing>
|
||||||
<child internal-child="entry">
|
<property name="left_attach">1</property>
|
||||||
<widget class="GtkEntry" id="combo-entry1">
|
<property name="right_attach">2</property>
|
||||||
<property name="visible">True</property>
|
<property name="y_options"></property>
|
||||||
<property name="can_focus">True</property>
|
</packing>
|
||||||
<property name="editable">True</property>
|
</child>
|
||||||
<property name="visibility">True</property>
|
<child>
|
||||||
<property name="max_length">0</property>
|
<widget class="GtkCheckButton" id="drop_checkbox">
|
||||||
<property name="text" translatable="yes">Access</property>
|
<property name="label" translatable="yes">Include Drop Table commands</property>
|
||||||
<property name="has_frame">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="invisible_char" translatable="yes">*</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="activates_default">False</property>
|
<property name="receives_default">False</property>
|
||||||
</widget>
|
<property name="use_underline">True</property>
|
||||||
</child>
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
<child internal-child="list">
|
</widget>
|
||||||
<widget class="GtkList" id="combo-list1">
|
<packing>
|
||||||
<property name="visible">True</property>
|
<property name="left_attach">1</property>
|
||||||
<property name="selection_mode">GTK_SELECTION_BROWSE</property>
|
<property name="right_attach">2</property>
|
||||||
</widget>
|
<property name="top_attach">3</property>
|
||||||
</child>
|
<property name="bottom_attach">4</property>
|
||||||
</widget>
|
<property name="x_options">GTK_FILL</property>
|
||||||
<packing>
|
<property name="y_options"></property>
|
||||||
<property name="left_attach">1</property>
|
</packing>
|
||||||
<property name="right_attach">2</property>
|
</child>
|
||||||
<property name="top_attach">1</property>
|
<child>
|
||||||
<property name="bottom_attach">2</property>
|
<widget class="GtkCheckButton" id="cstnotnull_checkbox">
|
||||||
<property name="y_options"></property>
|
<property name="label" translatable="yes">Include Not Null constraints</property>
|
||||||
</packing>
|
<property name="visible">True</property>
|
||||||
</child>
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
<child>
|
<property name="use_underline">True</property>
|
||||||
<widget class="GtkCombo" id="backend_combo">
|
<property name="active">True</property>
|
||||||
<property name="visible">True</property>
|
<property name="draw_indicator">True</property>
|
||||||
<property name="value_in_list">True</property>
|
</widget>
|
||||||
<property name="allow_empty">False</property>
|
<packing>
|
||||||
<property name="case_sensitive">False</property>
|
<property name="left_attach">1</property>
|
||||||
<property name="enable_arrow_keys">True</property>
|
<property name="right_attach">2</property>
|
||||||
<property name="enable_arrows_always">False</property>
|
<property name="top_attach">4</property>
|
||||||
|
<property name="bottom_attach">5</property>
|
||||||
<child internal-child="entry">
|
<property name="x_options">GTK_FILL</property>
|
||||||
<widget class="GtkEntry" id="entry">
|
<property name="y_options"></property>
|
||||||
<property name="visible">True</property>
|
</packing>
|
||||||
<property name="can_focus">True</property>
|
</child>
|
||||||
<property name="editable">False</property>
|
<child>
|
||||||
<property name="visibility">True</property>
|
<widget class="GtkCheckButton" id="rel_checkbox">
|
||||||
<property name="max_length">0</property>
|
<property name="label" translatable="yes">Include Relationships</property>
|
||||||
<property name="text" translatable="yes">Access</property>
|
<property name="visible">True</property>
|
||||||
<property name="has_frame">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="invisible_char" translatable="yes">*</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="activates_default">False</property>
|
<property name="use_underline">True</property>
|
||||||
</widget>
|
<property name="active">True</property>
|
||||||
</child>
|
<property name="draw_indicator">True</property>
|
||||||
|
</widget>
|
||||||
<child internal-child="list">
|
<packing>
|
||||||
<widget class="GtkList" id="combo-list2">
|
<property name="left_attach">1</property>
|
||||||
<property name="visible">True</property>
|
<property name="right_attach">2</property>
|
||||||
<property name="selection_mode">GTK_SELECTION_BROWSE</property>
|
<property name="top_attach">8</property>
|
||||||
|
<property name="bottom_attach">9</property>
|
||||||
<child>
|
<property name="x_options">GTK_FILL</property>
|
||||||
<widget class="GtkListItem" id="listitem141">
|
<property name="y_options"></property>
|
||||||
<property name="visible">True</property>
|
</packing>
|
||||||
<property name="can_focus">True</property>
|
</child>
|
||||||
<property name="label" translatable="yes">Access</property>
|
<child>
|
||||||
</widget>
|
<widget class="GtkCheckButton" id="index_checkbox">
|
||||||
</child>
|
<property name="label" translatable="yes">Include indexes</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
<child>
|
<property name="can_focus">True</property>
|
||||||
<widget class="GtkListItem" id="listitem142">
|
<property name="receives_default">False</property>
|
||||||
<property name="visible">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="active">True</property>
|
||||||
<property name="label" translatable="yes">Oracle</property>
|
<property name="draw_indicator">True</property>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
<child>
|
<property name="right_attach">2</property>
|
||||||
<widget class="GtkListItem" id="listitem143">
|
<property name="top_attach">7</property>
|
||||||
<property name="visible">True</property>
|
<property name="bottom_attach">8</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="x_options">GTK_FILL</property>
|
||||||
<property name="label" translatable="yes">Sybase</property>
|
<property name="y_options"></property>
|
||||||
</widget>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
<child>
|
<widget class="GtkCheckButton" id="cstnotempty_checkbox">
|
||||||
<widget class="GtkListItem" id="listitem144">
|
<property name="label" translatable="yes">Include Not Empty constraints</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="label" translatable="yes">MS SQL Server</property>
|
<property name="receives_default">False</property>
|
||||||
</widget>
|
<property name="use_underline">True</property>
|
||||||
</child>
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
<child>
|
</widget>
|
||||||
<widget class="GtkListItem" id="listitem145">
|
<packing>
|
||||||
<property name="visible">True</property>
|
<property name="left_attach">1</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="right_attach">2</property>
|
||||||
<property name="label" translatable="yes">PostgreSQL</property>
|
<property name="top_attach">5</property>
|
||||||
</widget>
|
<property name="bottom_attach">6</property>
|
||||||
</child>
|
<property name="x_options">GTK_FILL</property>
|
||||||
|
<property name="y_options"></property>
|
||||||
<child>
|
</packing>
|
||||||
<widget class="GtkListItem" id="listitem146">
|
</child>
|
||||||
<property name="visible">True</property>
|
<child>
|
||||||
<property name="can_focus">True</property>
|
<widget class="GtkCheckButton" id="comments_checkbox">
|
||||||
<property name="label" translatable="yes">MySQL</property>
|
<property name="label" translatable="yes">Include description on tables and columns</property>
|
||||||
</widget>
|
<property name="visible">True</property>
|
||||||
</child>
|
<property name="can_focus">True</property>
|
||||||
</widget>
|
<property name="receives_default">False</property>
|
||||||
</child>
|
<property name="use_underline">True</property>
|
||||||
</widget>
|
<property name="active">True</property>
|
||||||
<packing>
|
<property name="draw_indicator">True</property>
|
||||||
<property name="left_attach">1</property>
|
</widget>
|
||||||
<property name="right_attach">2</property>
|
<packing>
|
||||||
<property name="top_attach">2</property>
|
<property name="left_attach">1</property>
|
||||||
<property name="bottom_attach">3</property>
|
<property name="right_attach">2</property>
|
||||||
<property name="y_options"></property>
|
<property name="top_attach">6</property>
|
||||||
</packing>
|
<property name="bottom_attach">7</property>
|
||||||
</child>
|
<property name="x_options">GTK_FILL</property>
|
||||||
|
<property name="y_options"></property>
|
||||||
<child>
|
</packing>
|
||||||
<widget class="GtkCheckButton" id="rel_checkbox">
|
</child>
|
||||||
<property name="visible">True</property>
|
<child>
|
||||||
<property name="can_focus">True</property>
|
<placeholder/>
|
||||||
<property name="label" translatable="yes">Include Relationships</property>
|
</child>
|
||||||
<property name="use_underline">True</property>
|
<child>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<placeholder/>
|
||||||
<property name="active">True</property>
|
</child>
|
||||||
<property name="inconsistent">False</property>
|
<child>
|
||||||
<property name="draw_indicator">True</property>
|
<placeholder/>
|
||||||
</widget>
|
</child>
|
||||||
<packing>
|
<child>
|
||||||
<property name="left_attach">1</property>
|
<placeholder/>
|
||||||
<property name="right_attach">2</property>
|
</child>
|
||||||
<property name="top_attach">3</property>
|
<child>
|
||||||
<property name="bottom_attach">4</property>
|
<placeholder/>
|
||||||
<property name="x_options">fill</property>
|
</child>
|
||||||
<property name="y_options"></property>
|
</widget>
|
||||||
</packing>
|
<packing>
|
||||||
</child>
|
<property name="fill">False</property>
|
||||||
|
<property name="position">2</property>
|
||||||
<child>
|
</packing>
|
||||||
<widget class="GtkLabel" id="label4">
|
</child>
|
||||||
<property name="visible">True</property>
|
<child internal-child="action_area">
|
||||||
<property name="label" translatable="yes"><b>Options:</b></property>
|
<widget class="GtkHButtonBox" id="dialog-action_area1">
|
||||||
<property name="use_underline">False</property>
|
<property name="visible">True</property>
|
||||||
<property name="use_markup">True</property>
|
<property name="layout_style">end</property>
|
||||||
<property name="justify">GTK_JUSTIFY_RIGHT</property>
|
<child>
|
||||||
<property name="wrap">False</property>
|
<widget class="GtkButton" id="cancelbutton1">
|
||||||
<property name="selectable">False</property>
|
<property name="label">gtk-help</property>
|
||||||
<property name="xalign">0</property>
|
<property name="response_id">-11</property>
|
||||||
<property name="yalign">0.5</property>
|
<property name="visible">True</property>
|
||||||
<property name="xpad">0</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="ypad">0</property>
|
<property name="can_default">True</property>
|
||||||
</widget>
|
<property name="receives_default">False</property>
|
||||||
<packing>
|
<property name="use_stock">True</property>
|
||||||
<property name="left_attach">0</property>
|
<signal name="clicked" handler="gmdb_schema_help_cb"/>
|
||||||
<property name="right_attach">1</property>
|
</widget>
|
||||||
<property name="top_attach">3</property>
|
<packing>
|
||||||
<property name="bottom_attach">4</property>
|
<property name="expand">False</property>
|
||||||
<property name="x_options">fill</property>
|
<property name="fill">False</property>
|
||||||
<property name="y_options"></property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
<child>
|
<widget class="GtkButton" id="okbutton1">
|
||||||
<widget class="GtkCheckButton" id="drop_checkbox">
|
<property name="label">gtk-cancel</property>
|
||||||
<property name="visible">True</property>
|
<property name="response_id">-6</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="label" translatable="yes">Include Drop Table commands</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="can_default">True</property>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<property name="receives_default">False</property>
|
||||||
<property name="active">True</property>
|
<property name="use_stock">True</property>
|
||||||
<property name="inconsistent">False</property>
|
<signal name="clicked" handler="gtk_widget_destroy" object="schema_dialog"/>
|
||||||
<property name="draw_indicator">True</property>
|
</widget>
|
||||||
</widget>
|
<packing>
|
||||||
<packing>
|
<property name="expand">False</property>
|
||||||
<property name="left_attach">1</property>
|
<property name="fill">False</property>
|
||||||
<property name="right_attach">2</property>
|
<property name="position">1</property>
|
||||||
<property name="top_attach">4</property>
|
</packing>
|
||||||
<property name="bottom_attach">5</property>
|
</child>
|
||||||
<property name="x_options">fill</property>
|
<child>
|
||||||
<property name="y_options"></property>
|
<widget class="GtkButton" id="button1">
|
||||||
</packing>
|
<property name="response_id">-5</property>
|
||||||
</child>
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
<child>
|
<property name="can_default">True</property>
|
||||||
<widget class="GtkLabel" id="label5">
|
<property name="receives_default">False</property>
|
||||||
<property name="visible">True</property>
|
<signal name="clicked" handler="gmdb_schema_export_cb"/>
|
||||||
<property name="label" translatable="yes"><b>File Name:</b></property>
|
<child>
|
||||||
<property name="use_underline">False</property>
|
<widget class="GtkAlignment" id="alignment2">
|
||||||
<property name="use_markup">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
<property name="xscale">0</property>
|
||||||
<property name="wrap">False</property>
|
<property name="yscale">0</property>
|
||||||
<property name="selectable">False</property>
|
<child>
|
||||||
<property name="xalign">0</property>
|
<widget class="GtkHBox" id="hbox2">
|
||||||
<property name="yalign">0.5</property>
|
<property name="visible">True</property>
|
||||||
<property name="xpad">0</property>
|
<property name="spacing">2</property>
|
||||||
<property name="ypad">0</property>
|
<child>
|
||||||
</widget>
|
<widget class="GtkImage" id="image2">
|
||||||
<packing>
|
<property name="visible">True</property>
|
||||||
<property name="left_attach">0</property>
|
<property name="stock">gtk-convert</property>
|
||||||
<property name="right_attach">1</property>
|
</widget>
|
||||||
<property name="top_attach">0</property>
|
<packing>
|
||||||
<property name="bottom_attach">1</property>
|
<property name="expand">False</property>
|
||||||
<property name="x_options">fill</property>
|
<property name="fill">False</property>
|
||||||
<property name="y_options"></property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
<child>
|
<widget class="GtkLabel" id="label6">
|
||||||
<widget class="GnomeFileEntry" id="fileentry1">
|
<property name="visible">True</property>
|
||||||
<property name="visible">True</property>
|
<property name="label" translatable="yes">_Export</property>
|
||||||
<property name="max_saved">10</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="directory_entry">False</property>
|
</widget>
|
||||||
<property name="modal">False</property>
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
<child internal-child="entry">
|
<property name="fill">False</property>
|
||||||
<widget class="GtkEntry" id="filename_entry">
|
<property name="position">1</property>
|
||||||
<property name="visible">True</property>
|
</packing>
|
||||||
<property name="can_focus">True</property>
|
</child>
|
||||||
<property name="editable">True</property>
|
</widget>
|
||||||
<property name="visibility">True</property>
|
</child>
|
||||||
<property name="max_length">0</property>
|
</widget>
|
||||||
<property name="text" translatable="yes"></property>
|
</child>
|
||||||
<property name="has_frame">True</property>
|
</widget>
|
||||||
<property name="invisible_char" translatable="yes">*</property>
|
<packing>
|
||||||
<property name="activates_default">False</property>
|
<property name="expand">False</property>
|
||||||
</widget>
|
<property name="fill">False</property>
|
||||||
</child>
|
<property name="position">2</property>
|
||||||
</widget>
|
</packing>
|
||||||
<packing>
|
</child>
|
||||||
<property name="left_attach">1</property>
|
</widget>
|
||||||
<property name="right_attach">2</property>
|
<packing>
|
||||||
<property name="top_attach">0</property>
|
<property name="expand">False</property>
|
||||||
<property name="bottom_attach">1</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="y_options"></property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
</child>
|
||||||
<property name="padding">0</property>
|
</widget>
|
||||||
<property name="expand">True</property>
|
|
||||||
<property name="fill">False</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
</widget>
|
|
||||||
</child>
|
|
||||||
</widget>
|
|
||||||
|
|
||||||
</glade-interface>
|
</glade-interface>
|
||||||
|
|||||||
@@ -28,12 +28,23 @@ GladeXML *schemawin_xml;
|
|||||||
static gchar backend[100];
|
static gchar backend[100];
|
||||||
static gchar tabname[MDB_MAX_OBJ_NAME+1];
|
static gchar tabname[MDB_MAX_OBJ_NAME+1];
|
||||||
static gchar file_path[PATH_MAX+1];
|
static gchar file_path[PATH_MAX+1];
|
||||||
static gchar relation;
|
|
||||||
static gchar drops;
|
|
||||||
static guint32 export_options;
|
static guint32 export_options;
|
||||||
|
|
||||||
#define ALL_TABLES "(All Tables)"
|
#define ALL_TABLES "(All Tables)"
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
const char *option_name;
|
||||||
|
guint32 option_value;
|
||||||
|
} capabilities_xlt[] = {
|
||||||
|
{ "drop_checkbox", MDB_SHEXP_DROPTABLE },
|
||||||
|
{ "cstnotnull_checkbox", MDB_SHEXP_CST_NOTNULL },
|
||||||
|
{ "cstnotempty_checkbox", MDB_SHEXP_CST_NOTEMPTY},
|
||||||
|
{ "comments_checkbox", MDB_SHEXP_COMMENTS},
|
||||||
|
{ "index_checkbox", MDB_SHEXP_INDEXES},
|
||||||
|
{ "rel_checkbox", MDB_SHEXP_RELATIONS}
|
||||||
|
};
|
||||||
|
#define n_capabilities (sizeof(capabilities_xlt)/sizeof(capabilities_xlt[0]))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gmdb_schema_export()
|
gmdb_schema_export()
|
||||||
{
|
{
|
||||||
@@ -65,6 +76,7 @@ void
|
|||||||
gmdb_schema_export_cb(GtkWidget *w, gpointer data)
|
gmdb_schema_export_cb(GtkWidget *w, gpointer data)
|
||||||
{
|
{
|
||||||
GtkWidget *schemawin, *combo, *checkbox, *entry;
|
GtkWidget *schemawin, *combo, *checkbox, *entry;
|
||||||
|
int i;
|
||||||
|
|
||||||
schemawin = glade_xml_get_widget (schemawin_xml, "schema_dialog");
|
schemawin = glade_xml_get_widget (schemawin_xml, "schema_dialog");
|
||||||
|
|
||||||
@@ -85,19 +97,66 @@ GtkWidget *schemawin, *combo, *checkbox, *entry;
|
|||||||
else if (!strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)),"MySQL")) strcpy(backend,"mysql");
|
else if (!strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry)),"MySQL")) strcpy(backend,"mysql");
|
||||||
else strcpy(backend,"access");
|
else strcpy(backend,"access");
|
||||||
|
|
||||||
export_options = MDB_SHEXP_DEFAULT & ~ (MDB_SHEXP_RELATIONS|MDB_SHEXP_DROPTABLE);
|
/* make sure unknown default options are enabled */
|
||||||
checkbox = glade_xml_get_widget (schemawin_xml, "rel_checkbox");
|
export_options = MDB_SHEXP_DEFAULT;
|
||||||
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox)))
|
for (i=0; i<n_capabilities; ++i)
|
||||||
export_options |= MDB_SHEXP_RELATIONS;
|
export_options &= ~capabilities_xlt[i].option_value;
|
||||||
checkbox = glade_xml_get_widget (schemawin_xml, "drop_checkbox");
|
|
||||||
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox)))
|
/* fill the bit field from the checkboxes */
|
||||||
export_options |= MDB_SHEXP_DROPTABLE;
|
for (i=0; i<n_capabilities; ++i) {
|
||||||
// TODO add support for other options
|
checkbox = glade_xml_get_widget (schemawin_xml, capabilities_xlt[i].option_name);
|
||||||
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbox)))
|
||||||
|
export_options |= capabilities_xlt[i].option_value;
|
||||||
|
}
|
||||||
//printf("%s %s %02X\n",tabname,backend,export_options);
|
//printf("%s %s %02X\n",tabname,backend,export_options);
|
||||||
|
|
||||||
gtk_widget_destroy(schemawin);
|
gtk_widget_destroy(schemawin);
|
||||||
gmdb_schema_export();
|
gmdb_schema_export();
|
||||||
}
|
}
|
||||||
|
static void
|
||||||
|
check_default_options() {
|
||||||
|
int i;
|
||||||
|
GtkToggleButton *checkbox;
|
||||||
|
for (i=0; i<n_capabilities; ++i) {
|
||||||
|
checkbox = GTK_TOGGLE_BUTTON(glade_xml_get_widget (schemawin_xml, capabilities_xlt[i].option_name));
|
||||||
|
gtk_toggle_button_set_active(checkbox, (MDB_SHEXP_DEFAULT & capabilities_xlt[i].option_value) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void
|
||||||
|
refresh_available_options() {
|
||||||
|
GtkWidget *combo, *checkbox;
|
||||||
|
guint32 capabilities;
|
||||||
|
extern GHashTable *mdb_backends; /* FIXME */
|
||||||
|
MdbBackend *backend_obj;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
combo = glade_xml_get_widget (schemawin_xml, "backend_combo");
|
||||||
|
if (!combo) return; /* window is beeing destroyed */
|
||||||
|
|
||||||
|
const gchar *backend_name = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
|
||||||
|
if (!strcmp(backend_name,"Oracle")) strcpy(backend,"oracle");
|
||||||
|
else if (!strcmp(backend_name,"Sybase")) strcpy(backend,"sybase");
|
||||||
|
else if (!strcmp(backend_name,"MS SQL Server")) strcpy(backend,"sybase");
|
||||||
|
else if (!strcmp(backend_name,"PostgreSQL")) strcpy(backend,"postgres");
|
||||||
|
else if (!strcmp(backend_name,"MySQL")) strcpy(backend,"mysql");
|
||||||
|
else strcpy(backend,"access");
|
||||||
|
|
||||||
|
backend_obj = (MdbBackend *) g_hash_table_lookup(mdb_backends, backend);
|
||||||
|
//printf("backend_obj: %p\n", backend_obj);
|
||||||
|
|
||||||
|
capabilities = backend_obj->capabilities;
|
||||||
|
//printf("backend capabilities: 0x%04x\n", capabilities);
|
||||||
|
for (i=0; i<n_capabilities; ++i) {
|
||||||
|
checkbox = glade_xml_get_widget (schemawin_xml, capabilities_xlt[i].option_name);
|
||||||
|
gtk_widget_set_sensitive(checkbox, (capabilities & capabilities_xlt[i].option_value) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gmdb_schema_capabilities_cb(GtkList *list) {
|
||||||
|
refresh_available_options();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gmdb_schema_help_cb(GtkWidget *w, gpointer data)
|
gmdb_schema_help_cb(GtkWidget *w, gpointer data)
|
||||||
{
|
{
|
||||||
@@ -122,6 +181,10 @@ gmdb_schema_new_cb(GtkWidget *w, gpointer data)
|
|||||||
schemawin_xml = glade_xml_new(GMDB_GLADEDIR "gmdb-schema.glade", NULL, NULL);
|
schemawin_xml = glade_xml_new(GMDB_GLADEDIR "gmdb-schema.glade", NULL, NULL);
|
||||||
/* connect the signals in the interface */
|
/* connect the signals in the interface */
|
||||||
glade_xml_signal_autoconnect(schemawin_xml);
|
glade_xml_signal_autoconnect(schemawin_xml);
|
||||||
|
/* set up capabilities call back. TODO: autoconnect should do that */
|
||||||
|
combo = glade_xml_get_widget(schemawin_xml, "combo-list2");
|
||||||
|
g_signal_connect( G_OBJECT (combo), "selection_changed",
|
||||||
|
G_CALLBACK(gmdb_schema_capabilities_cb), schemawin_xml);
|
||||||
|
|
||||||
/* set signals with user data, anyone know how to do this in glade? */
|
/* set signals with user data, anyone know how to do this in glade? */
|
||||||
combo = glade_xml_get_widget (schemawin_xml, "table_combo");
|
combo = glade_xml_get_widget (schemawin_xml, "table_combo");
|
||||||
@@ -136,4 +199,7 @@ gmdb_schema_new_cb(GtkWidget *w, gpointer data)
|
|||||||
} /* for */
|
} /* for */
|
||||||
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
|
gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
|
||||||
g_list_free(glist);
|
g_list_free(glist);
|
||||||
|
|
||||||
|
check_default_options();
|
||||||
|
refresh_available_options();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ GtkStyle *style;
|
|||||||
strcpy(row[0],"");
|
strcpy(row[0],"");
|
||||||
sprintf(row[1],"%d", col->col_num+1);
|
sprintf(row[1],"%d", col->col_num+1);
|
||||||
strcpy(row[2],col->name);
|
strcpy(row[2],col->name);
|
||||||
strcpy(row[3], mdb_get_coltype_string(mdb->default_backend, col->col_type));
|
strcpy(row[3], mdb_get_colbacktype_string(col));
|
||||||
sprintf(row[4],"%d",col->col_size);
|
sprintf(row[4],"%d",col->col_size);
|
||||||
if (col->is_fixed) {
|
if (col->is_fixed) {
|
||||||
strcpy(row[5],"No");
|
strcpy(row[5],"No");
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
static int is_init;
|
static int is_init;
|
||||||
GHashTable *mdb_backends;
|
GHashTable *mdb_backends;
|
||||||
|
|
||||||
/* Access data types */
|
/* Access data types */
|
||||||
static MdbBackendType mdb_access_types[] = {
|
static MdbBackendType mdb_access_types[] = {
|
||||||
MdbBackendType_STRUCT_ELEMENT("Unknown 0x00", 0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Unknown 0x00", 0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Boolean", 0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Boolean", 0,0,0),
|
||||||
@@ -47,7 +47,7 @@ static MdbBackendType mdb_access_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("Currency", 0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Currency", 0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Single", 0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Single", 0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Double", 0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Double", 0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("DateTime (Short)", 0,0,1),
|
MdbBackendType_STRUCT_ELEMENT("DateTime", 0,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Binary", 0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Binary", 0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Text", 1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("Text", 1,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("OLE", 1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("OLE", 1,0,1),
|
||||||
@@ -68,8 +68,8 @@ static MdbBackendType mdb_oracle_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("NUMBER",1,0,0),
|
MdbBackendType_STRUCT_ELEMENT("NUMBER",1,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("FLOAT",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("FLOAT",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("FLOAT",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("FLOAT",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("DATE",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("TIMESTAMP",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Oracle_Unknown 0x09",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("BINARY",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("VARCHAR2",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("VARCHAR2",1,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("BLOB",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("BLOB",1,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("CLOB",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("CLOB",1,0,1),
|
||||||
@@ -78,6 +78,8 @@ static MdbBackendType mdb_oracle_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("NUMBER",1,0,0),
|
MdbBackendType_STRUCT_ELEMENT("NUMBER",1,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("NUMBER",1,0,0),
|
MdbBackendType_STRUCT_ELEMENT("NUMBER",1,0,0),
|
||||||
};
|
};
|
||||||
|
static MdbBackendType mdb_oracle_shortdate_type =
|
||||||
|
MdbBackendType_STRUCT_ELEMENT("DATE",0,0,0);
|
||||||
|
|
||||||
/* Sybase/MSSQL data types */
|
/* Sybase/MSSQL data types */
|
||||||
static MdbBackendType mdb_sybase_types[] = {
|
static MdbBackendType mdb_sybase_types[] = {
|
||||||
@@ -99,6 +101,8 @@ static MdbBackendType mdb_sybase_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("Sybase_Replication ID",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Sybase_Replication ID",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("numeric",1,1,0),
|
MdbBackendType_STRUCT_ELEMENT("numeric",1,1,0),
|
||||||
};
|
};
|
||||||
|
static MdbBackendType mdb_sybase_shortdate_type =
|
||||||
|
MdbBackendType_STRUCT_ELEMENT("DATE",0,0,0);
|
||||||
|
|
||||||
/* Postgres data types */
|
/* Postgres data types */
|
||||||
static MdbBackendType mdb_postgres_types[] = {
|
static MdbBackendType mdb_postgres_types[] = {
|
||||||
@@ -113,13 +117,18 @@ static MdbBackendType mdb_postgres_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("TIMESTAMP WITHOUT TIME ZONE",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("TIMESTAMP WITHOUT TIME ZONE",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("BYTEA",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("BYTEA",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("VARCHAR",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("VARCHAR",1,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x0b",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("BYTEA",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("TEXT",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("TEXT",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x0d",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x0d",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x0e",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x0e",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("UUID",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("UUID",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x10",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("Postgres_Unknown 0x10",0,0,0),
|
||||||
};
|
};
|
||||||
|
static MdbBackendType mdb_postgres_shortdate_type =
|
||||||
|
MdbBackendType_STRUCT_ELEMENT("DATE",0,0,0);
|
||||||
|
static MdbBackendType mdb_postgres_serial_type =
|
||||||
|
MdbBackendType_STRUCT_ELEMENT("SERIAL",0,0,0);
|
||||||
|
|
||||||
/* MySQL data types */
|
/* MySQL data types */
|
||||||
static MdbBackendType mdb_mysql_types[] = {
|
static MdbBackendType mdb_mysql_types[] = {
|
||||||
MdbBackendType_STRUCT_ELEMENT("Text",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("Text",1,0,1),
|
||||||
@@ -130,7 +139,7 @@ static MdbBackendType mdb_mysql_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("float",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("float",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("float",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("float",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("float",0,0,0),
|
MdbBackendType_STRUCT_ELEMENT("float",0,0,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("date",0,0,1),
|
MdbBackendType_STRUCT_ELEMENT("datetime",0,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("varchar",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("varchar",1,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("varchar",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("varchar",1,0,1),
|
||||||
MdbBackendType_STRUCT_ELEMENT("varchar",1,0,1),
|
MdbBackendType_STRUCT_ELEMENT("varchar",1,0,1),
|
||||||
@@ -140,6 +149,8 @@ static MdbBackendType mdb_mysql_types[] = {
|
|||||||
MdbBackendType_STRUCT_ELEMENT("numeric",1,1,0),
|
MdbBackendType_STRUCT_ELEMENT("numeric",1,1,0),
|
||||||
MdbBackendType_STRUCT_ELEMENT("numeric",1,1,0),
|
MdbBackendType_STRUCT_ELEMENT("numeric",1,1,0),
|
||||||
};
|
};
|
||||||
|
static MdbBackendType mdb_mysql_shortdate_type =
|
||||||
|
MdbBackendType_STRUCT_ELEMENT("date",0,0,0);
|
||||||
#ifndef JAVA
|
#ifndef JAVA
|
||||||
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data);
|
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data);
|
||||||
|
|
||||||
@@ -166,52 +177,155 @@ char* sanitize_name(const char* str)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* quote_name_with_brackets(const char* name)
|
static gchar*
|
||||||
{
|
quote_generic(const gchar *value, gchar quote_char, gchar escape_char) {
|
||||||
char *result = malloc(strlen(name)+3);
|
gchar *result, *pr;
|
||||||
sprintf(result, "[%s]", name);
|
unsigned char c;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char* quote_name_with_dquotes(const char* name)
|
pr = result = g_malloc(1+4*strlen(value)+2); // worst case scenario
|
||||||
{
|
|
||||||
char *result = malloc(2*strlen(name)+3);
|
*pr++ = quote_char;
|
||||||
char *p = result;
|
while ((c=*(unsigned char*)value++)) {
|
||||||
*p++ = '"';
|
if (c<32) {
|
||||||
while (*name) {
|
sprintf(pr, "\\%03o", c);
|
||||||
*p++ = *name;
|
pr+=4;
|
||||||
if (*name == '"')
|
continue;
|
||||||
*p++ = *name; /* double it */
|
}
|
||||||
name ++;
|
else if (c == quote_char) {
|
||||||
|
*pr++ = escape_char;
|
||||||
|
}
|
||||||
|
*pr++ = c;
|
||||||
}
|
}
|
||||||
*p++ = '"';
|
*pr++ = quote_char;
|
||||||
*p++ = 0;
|
*pr++ = '\0';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
static gchar*
|
||||||
static char* quote_name_with_rquotes(const char* name)
|
quote_schema_name_bracket_merge(const gchar* schema, const gchar *name) {
|
||||||
{
|
if (schema)
|
||||||
return (char*)g_strconcat("`", name, "`", NULL);
|
return g_strconcat("[", schema, "_", name, "]", NULL);
|
||||||
|
else
|
||||||
|
return g_strconcat("[", name, "]", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
/*
|
||||||
|
* For backends that really does support schema
|
||||||
|
* returns "name" or "schema"."name"
|
||||||
|
*/
|
||||||
|
static gchar*
|
||||||
|
quote_schema_name_dquote(const gchar* schema, const gchar *name)
|
||||||
{
|
{
|
||||||
|
if (schema) {
|
||||||
|
gchar *frag1 = quote_generic(schema, '"', '"');
|
||||||
|
gchar *frag2 = quote_generic(name, '"', '"');
|
||||||
|
gchar *result = g_strconcat(frag1, ".", frag2, NULL);
|
||||||
|
g_free(frag1);
|
||||||
|
g_free(frag2);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return quote_generic(name, '"', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For backends that really do NOT support schema
|
||||||
|
* returns "name" or "schema_name"
|
||||||
|
*/
|
||||||
|
static gchar*
|
||||||
|
quote_schema_name_dquote_merge(const gchar* schema, const gchar *name)
|
||||||
|
{
|
||||||
|
if (schema) {
|
||||||
|
gchar *combined = g_strconcat(schema, "_", name, NULL);
|
||||||
|
gchar *result = quote_generic(combined, '"', '"');
|
||||||
|
g_free(combined);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return quote_generic(name, '"', '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
quote_schema_name_rquotes_merge(const gchar* schema, const gchar *name)
|
||||||
|
{
|
||||||
|
if (schema) {
|
||||||
|
gchar *combined = g_strconcat(schema, "_", name, NULL);
|
||||||
|
gchar *result = quote_generic(combined, '`', '`');
|
||||||
|
g_free(combined);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return quote_generic(name, '`', '`');
|
||||||
|
}
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
quote_with_squotes(gchar* value)
|
||||||
|
{
|
||||||
|
return quote_generic(value, '\'', '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* deprecated */ char *
|
||||||
|
mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
||||||
|
{
|
||||||
|
static int warn_deprecated = 0;
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
|
|
||||||
|
if (!warn_deprecated) {
|
||||||
|
warn_deprecated = 1;
|
||||||
|
fprintf(stderr, "mdb_get_coltype_string is deprecated. Use mdb_get_colbacktype_string.\n");
|
||||||
|
}
|
||||||
if (col_type > 0x10 ) {
|
if (col_type > 0x10 ) {
|
||||||
// return NULL;
|
// return NULL;
|
||||||
snprintf(buf,sizeof(buf), "type %04x", col_type);
|
snprintf(buf,sizeof(buf), "type %04x", col_type);
|
||||||
return buf;
|
return buf;
|
||||||
} else {
|
} else
|
||||||
return backend->types_table[col_type].name;
|
return backend->types_table[col_type].name;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mdb_coltype_takes_length(MdbBackend *backend, int col_type)
|
/* deprecated */ int
|
||||||
|
mdb_coltype_takes_length(MdbBackend *backend, int col_type)
|
||||||
{
|
{
|
||||||
|
static int warn_deprecated = 0;
|
||||||
|
if (!warn_deprecated) {
|
||||||
|
warn_deprecated = 1;
|
||||||
|
fprintf(stderr, "mdb_coltype_takes_length is deprecated. Use mdb_colbacktype_takes_length.\n");
|
||||||
|
}
|
||||||
return backend->types_table[col_type].needs_length;
|
return backend->types_table[col_type].needs_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const MdbBackendType*
|
||||||
|
mdb_get_colbacktype(const MdbColumn *col) {
|
||||||
|
MdbBackend *backend = col->table->entry->mdb->default_backend;
|
||||||
|
int col_type = col->col_type;
|
||||||
|
if (col_type > 0x10 )
|
||||||
|
return NULL;
|
||||||
|
if (col_type == MDB_LONGINT && col->is_long_auto && backend->type_autonum)
|
||||||
|
return backend->type_autonum;
|
||||||
|
if (col_type == MDB_DATETIME && backend->type_shortdate) {
|
||||||
|
const char *format = mdb_col_get_prop(col, "Format");
|
||||||
|
if (format && !strcmp(format, "Short Date"))
|
||||||
|
return backend->type_shortdate;
|
||||||
|
}
|
||||||
|
return &backend->types_table[col_type];
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
mdb_get_colbacktype_string(const MdbColumn *col)
|
||||||
|
{
|
||||||
|
const MdbBackendType *type = mdb_get_colbacktype(col);
|
||||||
|
if (!type) {
|
||||||
|
// return NULL;
|
||||||
|
static char buf[16];
|
||||||
|
snprintf(buf,sizeof(buf), "type %04x", col->col_type);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return type->name;
|
||||||
|
}
|
||||||
|
int
|
||||||
|
mdb_colbacktype_takes_length(const MdbColumn *col)
|
||||||
|
{
|
||||||
|
const MdbBackendType *type = mdb_get_colbacktype(col);
|
||||||
|
if (!type) return 0;
|
||||||
|
return type->needs_length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mdb_init_backends
|
* mdb_init_backends
|
||||||
*
|
*
|
||||||
@@ -222,17 +336,65 @@ void mdb_init_backends()
|
|||||||
{
|
{
|
||||||
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
|
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
mdb_register_backend(mdb_access_types, quote_name_with_brackets, "access");
|
mdb_register_backend("access",
|
||||||
mdb_register_backend(mdb_sybase_types, quote_name_with_dquotes, "sybase");
|
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_SANITIZE,
|
||||||
mdb_register_backend(mdb_oracle_types, quote_name_with_dquotes, "oracle");
|
mdb_access_types, NULL, NULL,
|
||||||
mdb_register_backend(mdb_postgres_types, quote_name_with_dquotes, "postgres");
|
"-- That file uses encoding %s\n",
|
||||||
mdb_register_backend(mdb_mysql_types, quote_name_with_rquotes, "mysql");
|
"DROP TABLE %s;\n",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
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_SANITIZE,
|
||||||
|
mdb_sybase_types, &mdb_sybase_shortdate_type, NULL,
|
||||||
|
"-- That file uses encoding %s\n",
|
||||||
|
"DROP TABLE %s;\n",
|
||||||
|
"ALTER TABLE %s ADD CHECK (%s <>'');\n",
|
||||||
|
"COMMENT ON COLUMN %s.%s IS %s;\n",
|
||||||
|
"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_SANITIZE,
|
||||||
|
mdb_oracle_types, &mdb_oracle_shortdate_type, NULL,
|
||||||
|
"-- That file uses encoding %s\n",
|
||||||
|
"DROP TABLE %s;\n",
|
||||||
|
NULL,
|
||||||
|
"COMMENT ON COLUMN %s.%s IS %s;\n",
|
||||||
|
"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_SANITIZE,
|
||||||
|
mdb_postgres_types, &mdb_postgres_shortdate_type, &mdb_postgres_serial_type,
|
||||||
|
"SET client_encoding = '%s';\n",
|
||||||
|
"DROP TABLE IF EXISTS %s;\n",
|
||||||
|
"ALTER TABLE %s ADD CHECK (%s <>'');\n",
|
||||||
|
"COMMENT ON COLUMN %s.%s IS %s;\n",
|
||||||
|
"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_SANITIZE,
|
||||||
|
mdb_mysql_types, &mdb_mysql_shortdate_type, NULL,
|
||||||
|
"-- That file uses encoding %s\n",
|
||||||
|
"DROP TABLE IF EXISTS %s;\n",
|
||||||
|
"ALTER TABLE %s ADD CHECK (%s <>'');\n",
|
||||||
|
"COMMENT ON COLUMN %s.%s IS %s;\n",
|
||||||
|
"COMMENT ON TABLE %s IS %s;\n",
|
||||||
|
quote_schema_name_rquotes_merge);
|
||||||
}
|
}
|
||||||
void mdb_register_backend(MdbBackendType *backend_type, char* (*quote_name)(const char*), char *backend_name)
|
void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendType *backend_type, MdbBackendType *type_shortdate, MdbBackendType *type_autonum, const char *charset_statement, const char *drop_statement, const char *constaint_not_empty_statement, const char *column_comment_statement, const char *table_comment_statement, gchar* (*quote_schema_name)(const gchar*, const gchar*))
|
||||||
{
|
{
|
||||||
MdbBackend *backend = (MdbBackend *) g_malloc0(sizeof(MdbBackend));
|
MdbBackend *backend = (MdbBackend *) g_malloc0(sizeof(MdbBackend));
|
||||||
|
backend->capabilities = capabilities;
|
||||||
backend->types_table = backend_type;
|
backend->types_table = backend_type;
|
||||||
backend->quote_name = quote_name;
|
backend->type_shortdate = type_shortdate;
|
||||||
|
backend->type_autonum = type_autonum;
|
||||||
|
backend->charset_statement = charset_statement;
|
||||||
|
backend->drop_statement = drop_statement;
|
||||||
|
backend->constaint_not_empty_statement = constaint_not_empty_statement;
|
||||||
|
backend->column_comment_statement = column_comment_statement;
|
||||||
|
backend->table_comment_statement = table_comment_statement;
|
||||||
|
backend->quote_schema_name = quote_schema_name;
|
||||||
g_hash_table_insert(mdb_backends, backend_name, backend);
|
g_hash_table_insert(mdb_backends, backend_name, backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,92 +439,6 @@ int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* mdb_get_sequences
|
|
||||||
* @entry: Handle to open MDB database file
|
|
||||||
* @namespace: Prefix for output names
|
|
||||||
* @sanitize: Remove weird characters if true
|
|
||||||
*
|
|
||||||
* Generates sequences and set default values
|
|
||||||
*
|
|
||||||
* Returns: a string stating that relationships are not supported for the
|
|
||||||
* selected backend, or a string containing SQL commands for setting up
|
|
||||||
* the sequences, tailored for the selected backend.
|
|
||||||
* Returns NULL on last iteration.
|
|
||||||
* The caller is responsible for freeing this string.
|
|
||||||
*/
|
|
||||||
static char *
|
|
||||||
mdb_get_sequences(MdbCatalogEntry *entry, char *namespace, int sanitize)
|
|
||||||
{
|
|
||||||
MdbTableDef *table;
|
|
||||||
MdbHandle *mdb = entry->mdb;
|
|
||||||
int i;
|
|
||||||
int backend = 0; /* Backends: 1=oracle, 2=postgres */
|
|
||||||
const char *quoted_table_name;
|
|
||||||
char *result = NULL;
|
|
||||||
char tmp[4*512+512]; /* maximum size is 4 quoted names + some constants */
|
|
||||||
|
|
||||||
|
|
||||||
if (is_init == 1) { /* the second time through */
|
|
||||||
is_init = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
is_init = 1;
|
|
||||||
/* the first time through */
|
|
||||||
|
|
||||||
if (!strcmp(mdb->backend_name, "postgres")) {
|
|
||||||
backend = 2;
|
|
||||||
} else {
|
|
||||||
return (char *) g_strconcat(
|
|
||||||
"-- sequences are not implemented for ",
|
|
||||||
mdb->backend_name, "\n", NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the columns */
|
|
||||||
table = mdb_read_table (entry);
|
|
||||||
|
|
||||||
/* get the columns */
|
|
||||||
mdb_read_columns (table);
|
|
||||||
|
|
||||||
if (sanitize)
|
|
||||||
quoted_table_name = sanitize_name(table->name);
|
|
||||||
else
|
|
||||||
quoted_table_name = mdb->default_backend->quote_name(table->name);
|
|
||||||
|
|
||||||
for (i = 0; i < table->num_cols; i++) {
|
|
||||||
MdbColumn *col;
|
|
||||||
col = g_ptr_array_index (table->columns, i);
|
|
||||||
if (col->is_long_auto) {
|
|
||||||
const char *quoted_column_name;
|
|
||||||
char sequence_name[256+1+256+4+1];
|
|
||||||
const char *quoted_sequence_name;
|
|
||||||
quoted_column_name = mdb->default_backend->quote_name(col->name);
|
|
||||||
sprintf(sequence_name, "%s_%s_seq", entry->object_name, col->name);
|
|
||||||
quoted_sequence_name = mdb->default_backend->quote_name(sequence_name);
|
|
||||||
sprintf (tmp, "CREATE SEQUENCE %s OWNED BY %s.%s;\n", quoted_sequence_name, quoted_table_name, quoted_column_name);
|
|
||||||
if (result) {
|
|
||||||
result = realloc(result, strlen(result) + strlen(tmp) + 1); /* sentry */
|
|
||||||
strcat(result, tmp);
|
|
||||||
} else
|
|
||||||
result = strdup(tmp);
|
|
||||||
/* after that point, result can't be NULL any more */
|
|
||||||
|
|
||||||
sprintf (tmp, "ALTER TABLE %s ALTER COLUMN %s SET DEFAULT pg_catalog.nextval('%s');\n\n",
|
|
||||||
quoted_table_name, quoted_column_name, quoted_sequence_name);
|
|
||||||
result = realloc(result, strlen(result) + strlen(tmp) + 1); /* sentry */
|
|
||||||
strcat(result, tmp);
|
|
||||||
|
|
||||||
free((void*)quoted_column_name);
|
|
||||||
free((void*)quoted_sequence_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
is_init = 0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mdb_print_indexes
|
* mdb_print_indexes
|
||||||
* @output: Where to print the sql
|
* @output: Where to print the sql
|
||||||
@@ -387,29 +463,31 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
|
|||||||
/* read indexes */
|
/* read indexes */
|
||||||
mdb_read_indices(table);
|
mdb_read_indices(table);
|
||||||
|
|
||||||
fprintf (outfile, "-- CREATE ANY INDEXES ...\n");
|
fprintf (outfile, "-- CREATE INDEXES ...\n");
|
||||||
|
|
||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_table_name = sanitize_name(table->name);
|
quoted_table_name = sanitize_name(table->name);
|
||||||
else
|
else
|
||||||
quoted_table_name = mdb->default_backend->quote_name(table->name);
|
quoted_table_name = mdb->default_backend->quote_schema_name(namespace, table->name);
|
||||||
|
|
||||||
for (i=0;i<table->num_idxs;i++) {
|
for (i=0;i<table->num_idxs;i++) {
|
||||||
idx = g_ptr_array_index (table->indices, i);
|
idx = g_ptr_array_index (table->indices, i);
|
||||||
if (idx->index_type==2)
|
if (idx->index_type==2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
index_name = malloc(strlen(table->name)+strlen(idx->name)+4+1);
|
index_name = malloc(strlen(table->name)+strlen(idx->name)+5+1);
|
||||||
strcpy(index_name, table->name);
|
strcpy(index_name, table->name);
|
||||||
strcat(index_name, idx->name);
|
|
||||||
if (idx->index_type==1)
|
if (idx->index_type==1)
|
||||||
strcat(index_name, "_pk");
|
strcat(index_name, "_pkey");
|
||||||
else
|
else {
|
||||||
|
strcat(index_name, "_");
|
||||||
|
strcat(index_name, idx->name);
|
||||||
strcat(index_name, "_idx");
|
strcat(index_name, "_idx");
|
||||||
|
}
|
||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_name = sanitize_name(index_name);
|
quoted_name = sanitize_name(index_name);
|
||||||
else
|
else
|
||||||
quoted_name = mdb->default_backend->quote_name(index_name);
|
quoted_name = mdb->default_backend->quote_schema_name(namespace, index_name);
|
||||||
if (idx->index_type==1) {
|
if (idx->index_type==1) {
|
||||||
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);
|
||||||
} else {
|
} else {
|
||||||
@@ -428,7 +506,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
|
|||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_name = sanitize_name(col->name);
|
quoted_name = sanitize_name(col->name);
|
||||||
else
|
else
|
||||||
quoted_name = mdb->default_backend->quote_name(col->name);
|
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||||
fprintf (outfile, "%s", quoted_name);
|
fprintf (outfile, "%s", quoted_name);
|
||||||
if (idx->index_type!=1 && idx->key_col_order[j])
|
if (idx->index_type!=1 && idx->key_col_order[j])
|
||||||
/* no DESC for primary keys */
|
/* no DESC for primary keys */
|
||||||
@@ -439,8 +517,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
|
|||||||
}
|
}
|
||||||
fprintf (outfile, ");\n");
|
fprintf (outfile, ");\n");
|
||||||
}
|
}
|
||||||
fprintf (outfile, "\n");
|
fputc ('\n', outfile);
|
||||||
fprintf (outfile, "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -462,7 +539,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *namespace, int saniti
|
|||||||
* The caller is responsible for freeing this string.
|
* The caller is responsible for freeing this string.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
mdb_get_relationships(MdbHandle *mdb, const char* tablename)
|
mdb_get_relationships(MdbHandle *mdb, const gchar *namespace, const char* tablename)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
gchar *text = NULL; /* String to be returned */
|
gchar *text = NULL; /* String to be returned */
|
||||||
@@ -533,13 +610,13 @@ mdb_get_relationships(MdbHandle *mdb, const char* tablename)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
quoted_table_1 = mdb->default_backend->quote_name(bound[1]);
|
quoted_table_1 = mdb->default_backend->quote_schema_name(namespace, bound[1]);
|
||||||
quoted_column_1 = mdb->default_backend->quote_name(bound[0]);
|
quoted_column_1 = mdb->default_backend->quote_schema_name(namespace, bound[0]);
|
||||||
quoted_table_2 = mdb->default_backend->quote_name(bound[3]);
|
quoted_table_2 = mdb->default_backend->quote_schema_name(namespace, bound[3]);
|
||||||
quoted_column_2 = mdb->default_backend->quote_name(bound[2]);
|
quoted_column_2 = mdb->default_backend->quote_schema_name(namespace, bound[2]);
|
||||||
grbit = atoi(bound[4]);
|
grbit = atoi(bound[4]);
|
||||||
constraint_name = g_strconcat(bound[1], "_", bound[0], "_fk", NULL);
|
constraint_name = g_strconcat(bound[1], "_", bound[0], "_fk", NULL);
|
||||||
quoted_constraint_name = mdb->default_backend->quote_name(constraint_name);
|
quoted_constraint_name = mdb->default_backend->quote_schema_name(namespace, constraint_name);
|
||||||
free(constraint_name);
|
free(constraint_name);
|
||||||
|
|
||||||
if (grbit & 0x00000002) {
|
if (grbit & 0x00000002) {
|
||||||
@@ -580,28 +657,20 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
|
|||||||
MdbHandle *mdb = entry->mdb;
|
MdbHandle *mdb = entry->mdb;
|
||||||
MdbColumn *col;
|
MdbColumn *col;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char* table_name;
|
|
||||||
char* quoted_table_name;
|
char* quoted_table_name;
|
||||||
char* quoted_name;
|
char* quoted_name;
|
||||||
char* sql_sequences;
|
|
||||||
int sanitize = export_options & MDB_SHEXP_SANITIZE;
|
int sanitize = export_options & MDB_SHEXP_SANITIZE;
|
||||||
|
MdbProperties *props;
|
||||||
|
char *prop_value;
|
||||||
|
|
||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_table_name = sanitize_name(entry->object_name);
|
quoted_table_name = sanitize_name(entry->object_name);
|
||||||
else
|
else
|
||||||
quoted_table_name = mdb->default_backend->quote_name(entry->object_name);
|
quoted_table_name = mdb->default_backend->quote_schema_name(namespace, entry->object_name);
|
||||||
|
|
||||||
if (namespace) {
|
|
||||||
table_name = malloc(strlen(namespace)+strlen(quoted_table_name)+1);
|
|
||||||
strcpy(table_name, namespace);
|
|
||||||
strcat(table_name, quoted_table_name);
|
|
||||||
free(quoted_table_name);
|
|
||||||
quoted_table_name = table_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* drop the table if it exists */
|
/* drop the table if it exists */
|
||||||
if (export_options & MDB_SHEXP_DROPTABLE)
|
if (export_options & MDB_SHEXP_DROPTABLE)
|
||||||
fprintf (outfile, "DROP TABLE %s;\n", quoted_table_name);
|
fprintf (outfile, mdb->default_backend->drop_statement, quoted_table_name);
|
||||||
|
|
||||||
/* create the table */
|
/* create the table */
|
||||||
fprintf (outfile, "CREATE TABLE %s\n", quoted_table_name);
|
fprintf (outfile, "CREATE TABLE %s\n", quoted_table_name);
|
||||||
@@ -613,20 +682,18 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
|
|||||||
mdb_read_columns (table);
|
mdb_read_columns (table);
|
||||||
|
|
||||||
/* loop over the columns, dumping the names and types */
|
/* loop over the columns, dumping the names and types */
|
||||||
|
|
||||||
for (i = 0; i < table->num_cols; i++) {
|
for (i = 0; i < table->num_cols; i++) {
|
||||||
col = g_ptr_array_index (table->columns, i);
|
col = g_ptr_array_index (table->columns, i);
|
||||||
|
|
||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_name = sanitize_name(col->name);
|
quoted_name = sanitize_name(col->name);
|
||||||
else
|
else
|
||||||
quoted_name = mdb->default_backend->quote_name(col->name);
|
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||||
fprintf (outfile, "\t%s\t\t\t%s", quoted_name,
|
fprintf (outfile, "\t%s\t\t\t%s", quoted_name,
|
||||||
mdb_get_coltype_string (mdb->default_backend, col->col_type));
|
mdb_get_colbacktype_string (col));
|
||||||
free(quoted_name);
|
free(quoted_name);
|
||||||
|
|
||||||
if (mdb_coltype_takes_length(mdb->default_backend,
|
if (mdb_colbacktype_takes_length(col)) {
|
||||||
col->col_type)) {
|
|
||||||
|
|
||||||
/* more portable version from DW patch */
|
/* more portable version from DW patch */
|
||||||
if (col->col_size == 0)
|
if (col->col_size == 0)
|
||||||
@@ -635,6 +702,16 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
|
|||||||
fprintf(outfile, " (%d)", col->col_size);
|
fprintf(outfile, " (%d)", col->col_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (export_options & MDB_SHEXP_CST_NOTNULL) {
|
||||||
|
if (col->col_type == MDB_BOOL) {
|
||||||
|
/* access booleans are never null */
|
||||||
|
fputs(" NOT NULL", outfile);
|
||||||
|
} else {
|
||||||
|
const gchar *not_null = mdb_col_get_prop(col, "Required");
|
||||||
|
if (not_null && not_null[0]=='y')
|
||||||
|
fputs(" NOT NULL", outfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (i < table->num_cols - 1)
|
if (i < table->num_cols - 1)
|
||||||
fputs(", \n", outfile);
|
fputs(", \n", outfile);
|
||||||
else
|
else
|
||||||
@@ -643,13 +720,56 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *namespace, gu
|
|||||||
|
|
||||||
fputs(");\n", outfile);
|
fputs(");\n", outfile);
|
||||||
|
|
||||||
fputs("-- CREATE SEQUENCES ...\n", outfile);
|
/* Add the constraints on columns */
|
||||||
fputs("\n", outfile);
|
for (i = 0; i < table->num_cols; i++) {
|
||||||
while ((sql_sequences = mdb_get_sequences(entry, namespace, sanitize))) {
|
const gchar *prop_value;
|
||||||
fputs(sql_sequences, outfile);
|
|
||||||
free(sql_sequences);
|
col = g_ptr_array_index (table->columns, i);
|
||||||
|
props = col->props;
|
||||||
|
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) {
|
||||||
|
prop_value = mdb_col_get_prop(col, "AllowZeroLength");
|
||||||
|
if (prop_value && prop_value[0]=='n')
|
||||||
|
fprintf(outfile,
|
||||||
|
mdb->default_backend->constaint_not_empty_statement,
|
||||||
|
quoted_table_name, quoted_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (export_options & MDB_SHEXP_COMMENTS) {
|
||||||
|
prop_value = mdb_col_get_prop(col, "Description");
|
||||||
|
if (prop_value) {
|
||||||
|
char *comment = quote_with_squotes(prop_value);
|
||||||
|
fprintf(outfile,
|
||||||
|
mdb->default_backend->column_comment_statement,
|
||||||
|
quoted_table_name, quoted_name, comment);
|
||||||
|
free(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(quoted_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add the constraints on table */
|
||||||
|
if (export_options & MDB_SHEXP_COMMENTS) {
|
||||||
|
prop_value = mdb_table_get_prop(table, "Description");
|
||||||
|
if (prop_value) {
|
||||||
|
char *comment = quote_with_squotes(prop_value);
|
||||||
|
fprintf(outfile,
|
||||||
|
mdb->default_backend->table_comment_statement,
|
||||||
|
quoted_table_name, comment);
|
||||||
|
free(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fputc('\n', outfile);
|
||||||
|
|
||||||
|
|
||||||
if (export_options & MDB_SHEXP_INDEXES)
|
if (export_options & MDB_SHEXP_INDEXES)
|
||||||
// prints all the indexes of that table
|
// prints all the indexes of that table
|
||||||
mdb_print_indexes(outfile, table, namespace, sanitize);
|
mdb_print_indexes(outfile, table, namespace, sanitize);
|
||||||
@@ -667,6 +787,9 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *namespace,
|
|||||||
char *the_relation;
|
char *the_relation;
|
||||||
MdbCatalogEntry *entry;
|
MdbCatalogEntry *entry;
|
||||||
|
|
||||||
|
/* clear unsupported options */
|
||||||
|
export_options &= mdb->default_backend->capabilities;
|
||||||
|
|
||||||
/* Print out a little message to show that this came from mdb-tools.
|
/* Print out a little message to show that this came from mdb-tools.
|
||||||
I like to know how something is generated. DW */
|
I like to know how something is generated. DW */
|
||||||
fputs("-------------------------------------------------------------\n"
|
fputs("-------------------------------------------------------------\n"
|
||||||
@@ -678,6 +801,12 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *namespace,
|
|||||||
"-------------------------------------------------------------\n\n",
|
"-------------------------------------------------------------\n\n",
|
||||||
outfile);
|
outfile);
|
||||||
|
|
||||||
|
const char *charset = mdb_target_charset(mdb);
|
||||||
|
if (charset) {
|
||||||
|
fprintf(outfile, mdb->default_backend->charset_statement, charset);
|
||||||
|
fputc('\n', outfile);
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i < mdb->num_catalog; i++) {
|
for (i=0; i < mdb->num_catalog; i++) {
|
||||||
entry = g_ptr_array_index (mdb->catalog, i);
|
entry = g_ptr_array_index (mdb->catalog, i);
|
||||||
if (entry->object_type == MDB_TABLE) {
|
if (entry->object_type == MDB_TABLE) {
|
||||||
@@ -691,7 +820,7 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *namespace,
|
|||||||
|
|
||||||
if (export_options & MDB_SHEXP_RELATIONS) {
|
if (export_options & MDB_SHEXP_RELATIONS) {
|
||||||
fputs ("-- CREATE Relationships ...\n", outfile);
|
fputs ("-- CREATE Relationships ...\n", outfile);
|
||||||
while ((the_relation=mdb_get_relationships(mdb, tabname)) != NULL) {
|
while ((the_relation=mdb_get_relationships(mdb, namespace, tabname)) != NULL) {
|
||||||
fputs(the_relation, outfile);
|
fputs(the_relation, outfile);
|
||||||
g_free(the_relation);
|
g_free(the_relation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -923,7 +923,7 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int
|
|||||||
size, text, MDB_BIND_SIZE);
|
size, text, MDB_BIND_SIZE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MDB_SDATETIME:
|
case MDB_DATETIME:
|
||||||
text = mdb_date_to_string(mdb, start);
|
text = mdb_date_to_string(mdb, start);
|
||||||
break;
|
break;
|
||||||
case MDB_MEMO:
|
case MDB_MEMO:
|
||||||
@@ -964,7 +964,7 @@ int mdb_col_disp_size(MdbColumn *col)
|
|||||||
case MDB_TEXT:
|
case MDB_TEXT:
|
||||||
return col->col_size;
|
return col->col_size;
|
||||||
break;
|
break;
|
||||||
case MDB_SDATETIME:
|
case MDB_DATETIME:
|
||||||
return 20;
|
return 20;
|
||||||
break;
|
break;
|
||||||
case MDB_MEMO:
|
case MDB_MEMO:
|
||||||
@@ -1000,7 +1000,7 @@ int mdb_col_fixed_size(MdbColumn *col)
|
|||||||
case MDB_TEXT:
|
case MDB_TEXT:
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case MDB_SDATETIME:
|
case MDB_DATETIME:
|
||||||
return 4;
|
return 4;
|
||||||
break;
|
break;
|
||||||
case MDB_BINARY:
|
case MDB_BINARY:
|
||||||
|
|||||||
@@ -181,6 +181,21 @@ mdb_ascii2unicode(MdbHandle *mdb, char *src, size_t slen, char *dest, size_t dle
|
|||||||
return dlen;
|
return dlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char*
|
||||||
|
mdb_target_charset(MdbHandle *mdb)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_ICONV
|
||||||
|
const char *iconv_code = getenv("MDBICONV");
|
||||||
|
if (!iconv_code)
|
||||||
|
iconv_code = "UTF-8";
|
||||||
|
return iconv_code;
|
||||||
|
#else
|
||||||
|
if (IS_JET4(mdb))
|
||||||
|
return "ISO-8859-1";
|
||||||
|
return NULL; // same as input: unknown
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void mdb_iconv_init(MdbHandle *mdb)
|
void mdb_iconv_init(MdbHandle *mdb)
|
||||||
{
|
{
|
||||||
const char *iconv_code;
|
const char *iconv_code;
|
||||||
@@ -191,11 +206,11 @@ void mdb_iconv_init(MdbHandle *mdb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
if (IS_JET4(mdb)) {
|
if (IS_JET4(mdb)) {
|
||||||
mdb->iconv_out = iconv_open("UCS-2LE", iconv_code);
|
mdb->iconv_out = iconv_open("UCS-2LE", iconv_code);
|
||||||
mdb->iconv_in = iconv_open(iconv_code, "UCS-2LE");
|
mdb->iconv_in = iconv_open(iconv_code, "UCS-2LE");
|
||||||
} else {
|
} else {
|
||||||
/* According to Microsoft Knowledge Base pages 289525 and */
|
/* According to Microsoft Knowledge Base pages 289525 and */
|
||||||
/* 202427, code page info is not contained in the database */
|
/* 202427, code page info is not contained in the database */
|
||||||
const char *jet3_iconv_code;
|
const char *jet3_iconv_code;
|
||||||
|
|
||||||
@@ -204,15 +219,17 @@ void mdb_iconv_init(MdbHandle *mdb)
|
|||||||
jet3_iconv_code="CP1252";
|
jet3_iconv_code="CP1252";
|
||||||
}
|
}
|
||||||
|
|
||||||
mdb->iconv_out = iconv_open(jet3_iconv_code, iconv_code);
|
mdb->iconv_out = iconv_open(jet3_iconv_code, iconv_code);
|
||||||
mdb->iconv_in = iconv_open(iconv_code, jet3_iconv_code);
|
mdb->iconv_in = iconv_open(iconv_code, jet3_iconv_code);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void mdb_iconv_close(MdbHandle *mdb)
|
void mdb_iconv_close(MdbHandle *mdb)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
if (mdb->iconv_out != (iconv_t)-1) iconv_close(mdb->iconv_out);
|
if (mdb->iconv_out != (iconv_t)-1) iconv_close(mdb->iconv_out);
|
||||||
if (mdb->iconv_in != (iconv_t)-1) iconv_close(mdb->iconv_in);
|
if (mdb->iconv_in != (iconv_t)-1) iconv_close(mdb->iconv_in);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -237,6 +237,8 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
|||||||
read_pg_if_n(mdb, col, &cur_pos, fmt->tab_col_entry_size);
|
read_pg_if_n(mdb, col, &cur_pos, fmt->tab_col_entry_size);
|
||||||
pcol = (MdbColumn *) g_malloc0(sizeof(MdbColumn));
|
pcol = (MdbColumn *) g_malloc0(sizeof(MdbColumn));
|
||||||
|
|
||||||
|
pcol->table = table;
|
||||||
|
|
||||||
pcol->col_type = col[0];
|
pcol->col_type = col[0];
|
||||||
|
|
||||||
// col_num_offset == 1 or 5
|
// col_num_offset == 1 or 5
|
||||||
@@ -328,7 +330,6 @@ MdbTableDef *table;
|
|||||||
MdbColumn *col;
|
MdbColumn *col;
|
||||||
int coln;
|
int coln;
|
||||||
MdbIndex *idx;
|
MdbIndex *idx;
|
||||||
MdbHandle *mdb = entry->mdb;
|
|
||||||
unsigned int i, bitn;
|
unsigned int i, bitn;
|
||||||
guint32 pgnum;
|
guint32 pgnum;
|
||||||
|
|
||||||
@@ -348,7 +349,7 @@ guint32 pgnum;
|
|||||||
|
|
||||||
fprintf(stdout,"column %d Name: %-20s Type: %s(%d)\n",
|
fprintf(stdout,"column %d Name: %-20s Type: %s(%d)\n",
|
||||||
i, col->name,
|
i, col->name,
|
||||||
mdb_get_coltype_string(mdb->default_backend, col->col_type),
|
mdb_get_colbacktype_string(col),
|
||||||
col->col_size);
|
col->col_size);
|
||||||
if (col->props)
|
if (col->props)
|
||||||
mdb_dump_props(col->props, stdout, 0);
|
mdb_dump_props(col->props, stdout, 0);
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ mdb_create_temp_table(MdbHandle *mdb, char *name)
|
|||||||
void
|
void
|
||||||
mdb_temp_table_add_col(MdbTableDef *table, MdbColumn *col)
|
mdb_temp_table_add_col(MdbTableDef *table, MdbColumn *col)
|
||||||
{
|
{
|
||||||
|
col->table = table,
|
||||||
col->col_num = table->num_cols;
|
col->col_num = table->num_cols;
|
||||||
if (!col->is_fixed)
|
if (!col->is_fixed)
|
||||||
col->var_col_num = table->num_var_cols++;
|
col->var_col_num = table->num_var_cols++;
|
||||||
|
|||||||
@@ -622,7 +622,7 @@ void mdb_sql_describe_table(MdbSQL *sql)
|
|||||||
tmpsiz = mdb_ascii2unicode(mdb, col->name, 0, col_name, 100);
|
tmpsiz = mdb_ascii2unicode(mdb, col->name, 0, col_name, 100);
|
||||||
mdb_fill_temp_field(&fields[0],col_name, tmpsiz, 0,0,0,0);
|
mdb_fill_temp_field(&fields[0],col_name, tmpsiz, 0,0,0,0);
|
||||||
|
|
||||||
strcpy(tmpstr, mdb_get_coltype_string(mdb->default_backend, col->col_type));
|
strcpy(tmpstr, mdb_get_colbacktype_string(col));
|
||||||
tmpsiz = mdb_ascii2unicode(mdb, tmpstr, 0, col_type, 100);
|
tmpsiz = mdb_ascii2unicode(mdb, tmpstr, 0, col_type, 100);
|
||||||
mdb_fill_temp_field(&fields[1],col_type, tmpsiz, 0,0,0,1);
|
mdb_fill_temp_field(&fields[1],col_type, tmpsiz, 0,0,0,1);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#undef MDB_BIND_SIZE
|
#undef MDB_BIND_SIZE
|
||||||
#define MDB_BIND_SIZE 200000
|
#define MDB_BIND_SIZE 200000
|
||||||
|
|
||||||
#define is_text_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_SDATETIME || x==MDB_BINARY)
|
#define is_text_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_DATETIME || x==MDB_BINARY)
|
||||||
|
|
||||||
static char *escapes(char *s);
|
static char *escapes(char *s);
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ main(int argc, char **argv)
|
|||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_name = sanitize_name(argv[optind + 1]);
|
quoted_name = sanitize_name(argv[optind + 1]);
|
||||||
else
|
else
|
||||||
quoted_name = mdb->default_backend->quote_name(argv[optind + 1]);
|
quoted_name = mdb->default_backend->quote_schema_name(NULL, argv[optind + 1]);
|
||||||
fprintf(stdout, "INSERT INTO %s%s (", namespace, quoted_name);
|
fprintf(stdout, "INSERT INTO %s%s (", namespace, quoted_name);
|
||||||
free(quoted_name);
|
free(quoted_name);
|
||||||
for (j=0;j<table->num_cols;j++) {
|
for (j=0;j<table->num_cols;j++) {
|
||||||
@@ -223,7 +223,7 @@ main(int argc, char **argv)
|
|||||||
if (sanitize)
|
if (sanitize)
|
||||||
quoted_name = sanitize_name(col->name);
|
quoted_name = sanitize_name(col->name);
|
||||||
else
|
else
|
||||||
quoted_name = mdb->default_backend->quote_name(col->name);
|
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||||
fprintf(stdout,"%s", quoted_name);
|
fprintf(stdout,"%s", quoted_name);
|
||||||
free(quoted_name);
|
free(quoted_name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
/* this utility dumps the schema for an existing database */
|
/* this utility dumps the schema for an existing database */
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "mdbtools.h"
|
#include "mdbtools.h"
|
||||||
|
|
||||||
#ifdef DMALLOC
|
#ifdef DMALLOC
|
||||||
@@ -42,16 +43,104 @@ main (int argc, char **argv)
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((opt=getopt(argc, argv, "T:N:S"))!=-1) {
|
int digit_optind = 0;
|
||||||
|
while (1) {
|
||||||
|
int this_option_optind = optind ? optind : 1;
|
||||||
|
int option_index = 0;
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"table", 1, NULL, 'T'},
|
||||||
|
{"namespace", 1, NULL, 'N'},
|
||||||
|
{"drop-table", 0, NULL, 0},
|
||||||
|
{"no-drop-table", 0, NULL, 0},
|
||||||
|
{"not-null", 0, NULL, 0},
|
||||||
|
{"no-not-null", 0, NULL, 0},
|
||||||
|
{"not-empty", 0, NULL, 0},
|
||||||
|
{"no-not-empty", 0, NULL, 0},
|
||||||
|
{"description", 0, NULL, 0},
|
||||||
|
{"no-description", 0, NULL, 0},
|
||||||
|
{"indexes", 0, NULL, 0},
|
||||||
|
{"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);
|
||||||
|
if (opt == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'T':
|
case 0:
|
||||||
tabname = (char *) g_strdup(optarg);
|
if (!strcmp(long_options[option_index].name, "drop-table")) {
|
||||||
|
export_options |= MDB_SHEXP_DROPTABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "no-drop-table")) {
|
||||||
|
export_options &= ~MDB_SHEXP_DROPTABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "not-null")) {
|
||||||
|
export_options |= MDB_SHEXP_CST_NOTNULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "no-not-null")) {
|
||||||
|
export_options &= ~MDB_SHEXP_CST_NOTNULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "not-empty")) {
|
||||||
|
export_options |= MDB_SHEXP_CST_NOTEMPTY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "no-not-empty")) {
|
||||||
|
export_options &= ~MDB_SHEXP_CST_NOTEMPTY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "description")) {
|
||||||
|
export_options |= MDB_SHEXP_COMMENTS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "no-description")) {
|
||||||
|
export_options &= ~MDB_SHEXP_COMMENTS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "indexes")) {
|
||||||
|
export_options |= MDB_SHEXP_INDEXES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "no-indexes")) {
|
||||||
|
export_options &= ~MDB_SHEXP_INDEXES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "relations")) {
|
||||||
|
export_options |= MDB_SHEXP_RELATIONS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!strcmp(long_options[option_index].name, "no-relations")) {
|
||||||
|
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);
|
||||||
|
fputc('\n', stderr);
|
||||||
|
exit(1);
|
||||||
break;
|
break;
|
||||||
case 'N':
|
|
||||||
namespace = (char *) g_strdup(optarg);
|
case 'T':
|
||||||
|
tabname = (char *) g_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'S':
|
|
||||||
export_options |= MDB_SHEXP_SANITIZE;
|
case 'N':
|
||||||
|
namespace = (char *) g_strdup(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
export_options |= MDB_SHEXP_SANITIZE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user