mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
Added option to choose how to export blobs
Supported modes are: - strip (don't export) - raw (compatibility) - octal (export as \ooo) Note that gmdb2 dialog where updated, but not the code. Many fixes to do there first :/
This commit is contained in:
parent
473d820239
commit
a66531c74a
@ -2,7 +2,7 @@ NAME
|
||||
mdb-export - Export data in an MDB database table to CSV format.
|
||||
|
||||
SYNOPSIS
|
||||
mdb-export [-H] [-d delimiter] [-R row_delim] [[-Q] | [-q quote [-X escape]]] [-I backend] [-D format] [-N namespace] database table
|
||||
mdb-export [-H] [-d delimiter] [-R row_delim] [[-Q] | [-q quote [-X escape]]] [-I backend] [-D format] [-N namespace] [-b strip|raw|octal] database table
|
||||
|
||||
DESCRIPTION
|
||||
mdb-export is a utility program distributed with MDB Tools.
|
||||
@ -10,15 +10,16 @@ DESCRIPTION
|
||||
It produces a CSV (comma separated value) output for the given table. Such output is suitable for importation into databases or spreadsheets.
|
||||
|
||||
OPTIONS
|
||||
-H Supress header row
|
||||
-Q Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters.
|
||||
-d Specify an alternative column delimiter If no delimiter is specified, table names will be delimited by a , (comma) character.
|
||||
-R Specify a row delimiter
|
||||
-I backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres and mysql.
|
||||
-D Set the date format (see strftime(3) for details)
|
||||
-q Use to wrap text-like fields. Default is ".
|
||||
-X Use to escape quoted characters within a field. Default is doubling.
|
||||
-N namespace Prefix identifiers with namespace.
|
||||
-H Supress header row
|
||||
-Q Don't wrap text-like fields (text, memo, date) in quotes. If not specified text fiels will be surrounded by " (double quote) characters.
|
||||
-d Specify an alternative column delimiter If no delimiter is specified, table names will be delimited by a , (comma) character.
|
||||
-R Specify a row delimiter
|
||||
-I backend INSERT statements (instead of CSV). You must specify which SQL backend dialect to use. Allowed values are: access, sybase, oracle, postgres and mysql.
|
||||
-D Set the date format (see strftime(3) for details)
|
||||
-q Use to wrap text-like fields. Default is ".
|
||||
-X Use to escape quoted characters within a field. Default is doubling.
|
||||
-N namespace Prefix identifiers with namespace.
|
||||
-b strip|raw|octal Binary export mode: strip binaries, export as-is, or output \ooo style octal data.
|
||||
|
||||
|
||||
NOTES
|
||||
|
@ -13,7 +13,7 @@
|
||||
<widget class="GtkTable" id="table1">
|
||||
<property name="visible">True</property>
|
||||
<property name="border_width">30</property>
|
||||
<property name="n_rows">6</property>
|
||||
<property name="n_rows">7</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="column_spacing">30</property>
|
||||
<property name="row_spacing">8</property>
|
||||
@ -93,8 +93,8 @@
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
@ -112,8 +112,8 @@
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
@ -176,6 +176,32 @@
|
||||
<property name="bottom_attach">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label8">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes"><b>Binaries:</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkComboBox" id="bin_combo">
|
||||
<property name="visible">True</property>
|
||||
<property name="items" translatable="yes"></property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
|
@ -88,6 +88,7 @@ void gmdb_export_get_delimiter(GladeXML *xml, gchar *delimiter, int max_buf);
|
||||
void gmdb_export_get_lineterm(GladeXML *xml, gchar *lineterm, int max_buf);
|
||||
int gmdb_export_get_quote(GladeXML *xml);
|
||||
char gmdb_export_get_quotechar(GladeXML *xml);
|
||||
int gmdb_export_get_binmode(GladeXML *xml);
|
||||
int gmdb_export_get_headers(GladeXML *xml);
|
||||
gchar *gmdb_export_get_filepath(GladeXML *xml);
|
||||
|
||||
|
@ -60,6 +60,7 @@ gmdb_sql_write_rslt_cb(GtkWidget *w, GladeXML *xml)
|
||||
int need_quote = 0;
|
||||
gchar delimiter[11];
|
||||
gchar quotechar;
|
||||
//TODO int binmode;
|
||||
gchar lineterm[5];
|
||||
gchar *str;
|
||||
int rows=0, n_columns;
|
||||
@ -78,6 +79,7 @@ gmdb_sql_write_rslt_cb(GtkWidget *w, GladeXML *xml)
|
||||
gmdb_export_get_lineterm(xml, lineterm, 5);
|
||||
need_quote = gmdb_export_get_quote(xml);
|
||||
quotechar = gmdb_export_get_quotechar(xml);
|
||||
//TODO binmode = gmdb_export_get_binmode(xml);
|
||||
need_headers = gmdb_export_get_headers(xml);
|
||||
file_path = gmdb_export_get_filepath(xml);
|
||||
|
||||
|
@ -42,6 +42,10 @@ MdbCatalogEntry *cat_entry;
|
||||
#define NEVER "Never"
|
||||
#define AUTOMAT "Automatic (where necessary)"
|
||||
|
||||
#define BIN_STRIP "Strip"
|
||||
#define BIN_RAW "Raw"
|
||||
#define BIN_OCTAL "Octal"
|
||||
|
||||
void
|
||||
gmdb_print_quote(FILE *outfile, int need_quote, char quotechar, char *colsep, char *str)
|
||||
{
|
||||
@ -116,6 +120,22 @@ gmdb_export_get_quotechar(GladeXML *xml)
|
||||
|
||||
return quotechar;
|
||||
}
|
||||
|
||||
int
|
||||
gmdb_export_get_binmode(GladeXML *xml)
|
||||
{
|
||||
GtkComboBox *combobox;
|
||||
gchar *str;
|
||||
|
||||
combobox = GTK_COMBO_BOX(glade_xml_get_widget(xml, "bin_combo"));
|
||||
str = gtk_combo_box_get_active_text (combobox);
|
||||
|
||||
if (!strcmp(str,BIN_STRIP)) return 1;
|
||||
else if (!strcmp(str,BIN_OCTAL)) return 2;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
gmdb_export_get_headers(GladeXML *xml)
|
||||
{
|
||||
@ -161,6 +181,7 @@ int need_quote = 0;
|
||||
gchar delimiter[11];
|
||||
gchar quotechar;
|
||||
gchar lineterm[5];
|
||||
int binmode = 1;
|
||||
int rows=0;
|
||||
|
||||
GtkWidget *exportwin, *dlg;
|
||||
@ -170,6 +191,7 @@ int rows=0;
|
||||
need_quote = gmdb_export_get_quote(exportwin_xml);
|
||||
quotechar = gmdb_export_get_quotechar(exportwin_xml);
|
||||
need_headers = gmdb_export_get_headers(exportwin_xml);
|
||||
binmode = gmdb_export_get_binmode(exportwin_xml);
|
||||
file_path = gmdb_export_get_filepath(exportwin_xml);
|
||||
|
||||
// printf("file path %s\n",file_path);
|
||||
@ -271,4 +293,10 @@ gmdb_table_export_populate_dialog(GladeXML *xml)
|
||||
gtk_combo_box_append_text(combobox, "'");
|
||||
gtk_combo_box_append_text(combobox, "`");
|
||||
gtk_combo_box_set_active(combobox, 0);
|
||||
|
||||
combobox = GTK_COMBO_BOX(glade_xml_get_widget(xml, "bin_combo"));
|
||||
gtk_combo_box_append_text(combobox, BIN_STRIP);
|
||||
gtk_combo_box_append_text(combobox, BIN_RAW);
|
||||
gtk_combo_box_append_text(combobox, BIN_OCTAL);
|
||||
gtk_combo_box_set_active(combobox, 1);
|
||||
}
|
||||
|
@ -28,11 +28,15 @@
|
||||
#define is_quote_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_DATETIME || x==MDB_BINARY || x==MDB_REPID)
|
||||
#define is_binary_type(x) (x==MDB_OLE || x==MDB_BINARY || x==MDB_REPID)
|
||||
|
||||
#define BIN_MODE_STRIP 0
|
||||
#define BIN_MODE_RAW 1
|
||||
#define BIN_MODE_OCTAL 2
|
||||
|
||||
static char *escapes(char *s);
|
||||
|
||||
//#define DONT_ESCAPE_ESCAPE
|
||||
static void
|
||||
print_col(gchar *col_val, int quote_text, int col_type, int bin_len, char *quote_char, char *escape_char)
|
||||
print_col(gchar *col_val, int quote_text, int col_type, int bin_len, char *quote_char, char *escape_char, int bin_mode)
|
||||
{
|
||||
size_t quote_len = strlen(quote_char); /* multibyte */
|
||||
|
||||
@ -46,6 +50,8 @@ print_col(gchar *col_val, int quote_text, int col_type, int bin_len, char *quote
|
||||
fputs(quote_char,stdout);
|
||||
while (1) {
|
||||
if (is_binary_type(col_type)) {
|
||||
if (bin_mode == BIN_MODE_STRIP)
|
||||
break;
|
||||
if (!bin_len--)
|
||||
break;
|
||||
} else /* use \0 sentry */
|
||||
@ -60,12 +66,14 @@ print_col(gchar *col_val, int quote_text, int col_type, int bin_len, char *quote
|
||||
fprintf(stdout, "%s%s", escape_char, escape_char);
|
||||
col_val += orig_escape_len;
|
||||
#endif
|
||||
} else
|
||||
} else if (is_binary_type(col_type) && *col_val < 0 && bin_mode == BIN_MODE_OCTAL)
|
||||
fprintf(stdout, "\\%03o", *(unsigned char*)col_val++);
|
||||
else
|
||||
putc(*col_val++, stdout);
|
||||
}
|
||||
fputs(quote_char,stdout);
|
||||
fputs(quote_char, stdout);
|
||||
} else
|
||||
fputs(col_val,stdout);
|
||||
fputs(col_val, stdout);
|
||||
}
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
@ -84,11 +92,12 @@ main(int argc, char **argv)
|
||||
char quote_text = 1;
|
||||
char *insert_dialect = NULL;
|
||||
char *namespace = NULL;
|
||||
int bin_mode = BIN_MODE_RAW;
|
||||
int opt;
|
||||
char *value;
|
||||
size_t length;
|
||||
|
||||
while ((opt=getopt(argc, argv, "HQq:X:d:D:R:I:N:"))!=-1) {
|
||||
while ((opt=getopt(argc, argv, "HQq:X:d:D:R:I:N:b:"))!=-1) {
|
||||
switch (opt) {
|
||||
case 'H':
|
||||
header_row = 0;
|
||||
@ -118,6 +127,18 @@ main(int argc, char **argv)
|
||||
case 'N':
|
||||
namespace = (char *) g_strdup(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
if (!strcmp(optarg, "strip"))
|
||||
bin_mode = BIN_MODE_STRIP;
|
||||
else if (!strcmp(optarg, "raw"))
|
||||
bin_mode = BIN_MODE_RAW;
|
||||
else if (!strcmp(optarg, "octal"))
|
||||
bin_mode = BIN_MODE_OCTAL;
|
||||
else {
|
||||
fprintf(stderr, "Invalid binary mode\n");
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -139,15 +160,16 @@ main(int argc, char **argv)
|
||||
if (argc-optind < 2) {
|
||||
fprintf(stderr,"Usage: %s [options] <file> <table>\n",argv[0]);
|
||||
fprintf(stderr,"where options are:\n");
|
||||
fprintf(stderr," -H supress header row\n");
|
||||
fprintf(stderr," -Q don't wrap text-like fields in quotes\n");
|
||||
fprintf(stderr," -d <delimiter> specify a column delimiter\n");
|
||||
fprintf(stderr," -R <delimiter> specify a row delimiter\n");
|
||||
fprintf(stderr," -I <backend> INSERT statements (instead of CSV)\n");
|
||||
fprintf(stderr," -D <format> set the date format (see strftime(3) for details)\n");
|
||||
fprintf(stderr," -q <char> Use <char> to wrap text-like fields. Default is \".\n");
|
||||
fprintf(stderr," -X <char> Use <char> to escape quoted characters within a field. Default is doubling.\n");
|
||||
fprintf(stderr," -N <namespace> Prefix identifiers with namespace\n");
|
||||
fprintf(stderr," -H supress header row\n");
|
||||
fprintf(stderr," -Q don't wrap text-like fields in quotes\n");
|
||||
fprintf(stderr," -d <delimiter> specify a column delimiter\n");
|
||||
fprintf(stderr," -R <delimiter> specify a row delimiter\n");
|
||||
fprintf(stderr," -I <backend> INSERT statements (instead of CSV)\n");
|
||||
fprintf(stderr," -D <format> set the date format (see strftime(3) for details)\n");
|
||||
fprintf(stderr," -q <char> Use <char> to wrap text-like fields. Default is \".\n");
|
||||
fprintf(stderr," -X <char> Use <char> to escape quoted characters within a field. Default is doubling.\n");
|
||||
fprintf(stderr," -N <namespace> Prefix identifiers with namespace\n");
|
||||
fprintf(stderr," -b strip|raw|octal Binary export mode.\n");
|
||||
g_free (delimiter);
|
||||
g_free (row_delimiter);
|
||||
g_free (quote_char);
|
||||
@ -231,7 +253,7 @@ main(int argc, char **argv)
|
||||
value = bound_values[j];
|
||||
length = bound_lens[j];
|
||||
}
|
||||
print_col(value, quote_text, col->col_type, length, quote_char, escape_char);
|
||||
print_col(value, quote_text, col->col_type, length, quote_char, escape_char, bin_mode);
|
||||
if (col->col_type == MDB_OLE)
|
||||
free(value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user