mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-09-18 18:22:07 +08:00
Clean up for 0.6 release and some bug fixes
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
Wed Sep 7 08:28:28 EDT 2005 Brian Bruns <brian@bruns.com>
|
||||
* src/util/mdb-export.c: Add -q and -X flags. Make -R and -d handle escaped characters properly
|
||||
* doc/mdb-export.txt: Update for new flags
|
||||
* src/util/mdb-export.c: Bug 1219521. Print error when table not found.
|
||||
* src/util/Makefile.am: move debugging programs to noinst
|
||||
* doc/faq.html: Update version number on expected write support.
|
||||
* doc/install.sgml: Add info about MDBICONV and MDB_JET3_CHARSET
|
||||
* src/util/mdb-sql.c: Fix -o option
|
||||
|
||||
Tue Aug 30 21:24:46 EDT 2005 Brian Bruns <brian@bruns.com>
|
||||
* configure.in: add --disable-gmdb2 switch
|
||||
|
||||
|
2
HACKING
2
HACKING
@@ -563,7 +563,7 @@ Each entry is composed of a flag, the indexed column values and a page/row
|
||||
pointer to the data.
|
||||
|
||||
0x03 index pages make up the rest of the index tree and contain a flag, the
|
||||
indexed columns, the page/row contains this entry, and the leaf page or
|
||||
indexed columns, the page/row that contains this entry, and the leaf page or
|
||||
intermediate (another 0x03 page) page pointer for which this is the first
|
||||
entry on.
|
||||
|
||||
|
4
TODO
4
TODO
@@ -23,7 +23,7 @@ libmdb:
|
||||
. Add support for index scanning when using sargs (partial)
|
||||
. Use allocation maps to read tables, should be more efficient (done)
|
||||
. write support
|
||||
. iconv conversion to utf-8, et al.
|
||||
. iconv conversion to utf-8, et al. (done)
|
||||
. multipage work tables (done)
|
||||
|
||||
utils:
|
||||
@@ -31,7 +31,7 @@ utils:
|
||||
. need program to unpack VBA script to file (see prole)
|
||||
. Access forms to glade converter ?
|
||||
. need --version flag (done using -M flag on mdb-ver)
|
||||
. -o on mdb-sql not working
|
||||
. -o on mdb-sql not working (done)
|
||||
|
||||
SQL Engine:
|
||||
|
||||
|
@@ -102,7 +102,7 @@ We are currently looking for corrupted Access databases to help with developing
|
||||
I, like many free software others, enjoy getting postcards from where users live. If you're a happy MDB Tools user (or even a disgruntled one, doesn't really matter) and want to drop me a postcard with a picture of the place you live, email <a href="mailto:brian@nospam.bruns.com">me</a> for my snail-mail address. Come on, you know you want to!
|
||||
</dd></dl>
|
||||
<dl><a name="writing"></a><dt><b>1.11 When will MDB Tools support writing?</b></dt><dd>
|
||||
Writing to MDB files is a quite a bit more complicated than simply reading. Some preliminary support is available in the CVS version, this includes under-the-covers things like building rows, adding rows to tables, tracing the index chain to the row, and some work on index writes. These are the nuts and bolts of write support; the big thing left is the allocation of new pages and splitting full pages on inserts. When will this be done? I don't commit to timelines, but the next release (0.6) will have some usable, though not complete, write support.
|
||||
Writing to MDB files is a quite a bit more complicated than simply reading. Some preliminary support is available in the CVS version, this includes under-the-covers things like building rows, adding rows to tables, tracing the index chain to the row, and some work on index writes. These are the nuts and bolts of write support; the big thing left is the allocation of new pages and splitting full pages on inserts. When will this be done? I don't commit to timelines, but the next release (0.7) will have some usable, though not complete, write support.
|
||||
</dd></dl>
|
||||
|
||||
</body></html>
|
||||
|
@@ -2,8 +2,8 @@
|
||||
]>
|
||||
<book>
|
||||
<bookinfo>
|
||||
<date>$Date: 2005/01/15 05:02:10 $</date>
|
||||
<releaseinfo>$Revision: 1.6 $</releaseinfo>
|
||||
<date>$Date: 2005/09/07 23:27:43 $</date>
|
||||
<releaseinfo>$Revision: 1.7 $</releaseinfo>
|
||||
<title><productname>MDB Tools</productname> Installation Guide</title>
|
||||
<subtitle>A Guide to Installing and Configuring <productname>MDB Tools</productname></subtitle>
|
||||
<author>
|
||||
@@ -34,9 +34,9 @@ This guide is intended to provide help with installing and configuring the <prod
|
||||
<para>
|
||||
A few technical notes. This guide is written in SGML DocBook format, specifications for which are found in the <ulink url="http://www.docbook.org/tdg/en/html/docbook.html">DocBook book</ulink>. It was converted to HTML with <ulink url="http://openjade.sourceforge.net">OpenJade</ulink>.
|
||||
The document you are reading is version
|
||||
$Revision: 1.6 $
|
||||
$Revision: 1.7 $
|
||||
, dated
|
||||
$Date: 2005/01/15 05:02:10 $ (CVS control number $Id: install.sgml,v 1.6 2005/01/15 05:02:10 calvinrsmith Exp $). The most recent version can be found on the <productname>MDB Tools</productname>
|
||||
$Date: 2005/09/07 23:27:43 $ (CVS control number $Id: install.sgml,v 1.7 2005/09/07 23:27:43 brianb Exp $). The most recent version can be found on the <productname>MDB Tools</productname>
|
||||
<ulink url="http://mdbtools.sourceforge.net/userguide/">web site</ulink>.
|
||||
</para>
|
||||
</preface>
|
||||
@@ -348,6 +348,28 @@ This will cause <productname>MDB Tools</productname> to first attempt to open th
|
||||
</para>
|
||||
<para>
|
||||
The MDBPATH variable affects all utilities and any program calling mdb_open().
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="iconv">
|
||||
<title>Character set encoding</title>
|
||||
<para>
|
||||
Jet 4 databases are encoded using UCS2-LE (Unicode 2 byte little endian) encoding. MDB Tools will convert these values using the "iconv" standard to UTF-8 by default. If your terminal or other output uses an encoding other than UTF-8 you can override the default behaviour by setting the MDBICONV to the desired character set.
|
||||
</para>
|
||||
<para>
|
||||
For sh, ksh, or bash
|
||||
<screen>
|
||||
<prompt>$ </prompt><userinput>MDBICONV=ISO_8859-1 ; export MDBICONV</userinput>
|
||||
</screen>
|
||||
Or for csh or tcsh
|
||||
<screen>
|
||||
<prompt>$ </prompt><userinput>setenv MDBICONV ISO_8859-1</userinput>
|
||||
</screen>
|
||||
</para>
|
||||
<para>
|
||||
To view a list of possible character sets, you can run the <command>iconv --list</command> command on most Linux systems. Otherwise, consult your vendors documentation.
|
||||
</para>
|
||||
<para>
|
||||
Jet 3 databases use the character set of the machine on which they were created. For US-English systems this will be cp1252 which is assumed by MDB Tools as the default. To use a file generated with another version of Access, set the MDB_JET3_CHARSET environment variable.
|
||||
</para>
|
||||
</sect1>
|
||||
<sect1 id="odbcini">
|
||||
|
@@ -1,7 +1,7 @@
|
||||
NAME
|
||||
mdb-export - Export data in an MDB database table to CSV format.
|
||||
SYNOPSIS
|
||||
mdb-export [-H] [-Q] [-d <delimiter>] <database> <table>
|
||||
mdb-export [-H] [-d <delimiter>] [-R <row delim>] [[-Q] || [-q <quote> [-X <escape>]]] [-I] [-D <format>] [-S] <database> <table>
|
||||
|
||||
DESCRIPTION
|
||||
mdb-export is a utility program distributed with MDB Tools.
|
||||
@@ -12,6 +12,13 @@ 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 INSERT statements (instead of CSV)
|
||||
-D Set the date format (see strftime(3) for details)
|
||||
-S Sanitize names (replace spaces etc. with underscore)
|
||||
-q Use to wrap text-like fields. Default is ".
|
||||
-X Use to escape quoted characters within a field. Default is doubling.
|
||||
|
||||
|
||||
NOTES
|
||||
|
||||
|
@@ -97,6 +97,8 @@ gmdb_debug_select_cb(GtkTreeSelection *select, GladeXML *xml)
|
||||
GtkWidget *textview;
|
||||
gchar *fieldname;
|
||||
|
||||
fprintf(stderr, "select_cb fired\n");
|
||||
|
||||
textview = glade_xml_get_widget (xml, "debug_textview");
|
||||
gmdb_debug_text_off(textview);
|
||||
|
||||
@@ -291,6 +293,8 @@ gmdb_debug_display_cb(GtkWidget *w, gpointer data)
|
||||
gchar *s;
|
||||
GladeXML *xml;
|
||||
|
||||
fprintf(stderr, "display fired\n");
|
||||
|
||||
if (!mdb) return;
|
||||
|
||||
win = gtk_widget_get_toplevel(w);
|
||||
@@ -974,6 +978,7 @@ gmdb_debug_close_cb(GtkWidget *w, gpointer data)
|
||||
{
|
||||
GladeXML *xml;
|
||||
|
||||
fprintf(stderr, "close fired\n");
|
||||
xml = g_object_get_data(G_OBJECT(w), "debugwin_xml");
|
||||
debug_list = g_list_remove(debug_list, xml);
|
||||
gtk_widget_destroy(w);
|
||||
@@ -984,6 +989,7 @@ gmdb_debug_close_all()
|
||||
GladeXML *xml;
|
||||
GtkWidget *win;
|
||||
|
||||
fprintf(stderr, "close_all fired\n");
|
||||
while ((xml = g_list_nth_data(debug_list, 0))) {
|
||||
win = glade_xml_get_widget (xml, "debug_window");
|
||||
debug_list = g_list_remove(debug_list, xml);
|
||||
@@ -1006,6 +1012,7 @@ gmdb_debug_new_cb(GtkWidget *w, gpointer data)
|
||||
/* load the interface */
|
||||
debugwin_xml = glade_xml_new(GMDB_GLADEDIR "gmdb-debug.glade", NULL, NULL);
|
||||
/* connect the signals in the interface */
|
||||
fprintf(stderr, "autoconnect signals\n");
|
||||
glade_xml_signal_autoconnect(debugwin_xml);
|
||||
|
||||
debug_list = g_list_append(debug_list, debugwin_xml);
|
||||
|
@@ -15,6 +15,11 @@
|
||||
<property name="default_height">200</property>
|
||||
<property name="resizable">True</property>
|
||||
<property name="destroy_with_parent">False</property>
|
||||
<property name="decorated">True</property>
|
||||
<property name="skip_taskbar_hint">False</property>
|
||||
<property name="skip_pager_hint">False</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
|
||||
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
<property name="enable_layout_config">True</property>
|
||||
|
||||
<child internal-child="dock">
|
||||
@@ -175,25 +180,52 @@
|
||||
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
|
||||
<property name="toolbar_style">GTK_TOOLBAR_ICONS</property>
|
||||
<property name="tooltips">True</property>
|
||||
<property name="show_arrow">True</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkToolButton" id="button4">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Open a new window</property>
|
||||
<property name="stock-id">gtk-new</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
<property name="is_important">False</property>
|
||||
<signal name="clicked" handler="gmdb_debug_new_cb" last_modification_time="Fri, 03 Jan 2003 13:12:52 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkSeparatorToolItem" id="separatortoolitem1">
|
||||
<property name="visible">True</property>
|
||||
<property name="draw">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkToolButton" id="back_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Back</property>
|
||||
<property name="stock-id">gtk-go-back</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
<property name="is_important">False</property>
|
||||
<signal name="clicked" handler="gmdb_debug_back_cb" object="debug_window"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="new_group">True</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
@@ -201,29 +233,63 @@
|
||||
<widget class="GtkToolButton" id="forward_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Forward</property>
|
||||
<property name="stock-id">gtk-go-forward</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
<property name="is_important">False</property>
|
||||
<signal name="clicked" handler="gmdb_debug_forward_cb" object="debug_window"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkToolButton" id="jump_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Jump to</property>
|
||||
<property name="stock-id">gtk-jump-to</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
<property name="is_important">False</property>
|
||||
<signal name="clicked" handler="gmdb_debug_jump_cb" object="debug_window"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkSeparatorToolItem" id="separatortoolitem2">
|
||||
<property name="visible">True</property>
|
||||
<property name="draw">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkToolButton" id="close_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="tooltip" translatable="yes">Close window</property>
|
||||
<property name="stock-id">gtk-close</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="visible_horizontal">True</property>
|
||||
<property name="visible_vertical">True</property>
|
||||
<property name="is_important">False</property>
|
||||
<signal name="clicked" handler="gmdb_debug_close_cb" object="debug_window"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="new_group">True</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
@@ -326,7 +392,8 @@
|
||||
<property name="label" translatable="yes">_Display</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<signal name="clicked" handler="gmdb_debug_display_cb" object="debug_entry"/>
|
||||
<property name="focus_on_click">True</property>
|
||||
<signal name="clicked" handler="gtk_main_quit" object="debug_entry" last_modification_time="Tue, 23 Aug 2005 12:40:43 GMT"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
@@ -389,6 +456,8 @@
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">True</property>
|
||||
<property name="overwrite">False</property>
|
||||
<property name="accepts_tab">True</property>
|
||||
<property name="justification">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap_mode">GTK_WRAP_NONE</property>
|
||||
<property name="cursor_visible">True</property>
|
||||
|
@@ -183,7 +183,7 @@ void mdb_iconv_init(MdbHandle *mdb)
|
||||
const char *iconv_code;
|
||||
|
||||
/* check environment variable */
|
||||
if (!(iconv_code=getenv("MDB_ICONV"))) {
|
||||
if (!(iconv_code=getenv("MDBICONV"))) {
|
||||
iconv_code="UTF-8";
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver mdb-prop mdb-import prtable prcat prdata prkkd prdump prole updrow prindex
|
||||
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver mdb-prop
|
||||
noinst_PROGRAMS = mdb-import prtable prcat prdata prkkd prdump prole updrow prindex
|
||||
LIBS = $(GLIB_LIBS) @LIBS@ @LEXLIB@
|
||||
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||
|
@@ -29,19 +29,27 @@
|
||||
#define is_text_type(x) (x==MDB_TEXT || x==MDB_MEMO || x==MDB_SDATETIME)
|
||||
|
||||
static char *sanitize_name(char *str, int sanitize);
|
||||
static char *escapes(char *s);
|
||||
|
||||
void
|
||||
print_col(gchar *col_val, int quote_text, int col_type)
|
||||
print_col(gchar *col_val, int quote_text, int col_type, char *quote_char, char *escape_char)
|
||||
{
|
||||
gchar *s;
|
||||
|
||||
if (quote_text && is_text_type(col_type)) {
|
||||
fprintf(stdout,"\"");
|
||||
fprintf(stdout,quote_char);
|
||||
for (s=col_val;*s;s++) {
|
||||
if (*s=='"') fprintf(stdout,"\"\"");
|
||||
if (strlen(quote_char)==1 && *s==quote_char[0]) {
|
||||
/* double the char if no escape char passed */
|
||||
if (!escape_char) {
|
||||
fprintf(stdout,"%s%s",quote_char,quote_char);
|
||||
} else {
|
||||
fprintf(stdout,"%s%s",escape_char,quote_char);
|
||||
}
|
||||
}
|
||||
else fprintf(stdout,"%c",*s);
|
||||
}
|
||||
fprintf(stdout,"\"");
|
||||
fprintf(stdout,quote_char);
|
||||
} else {
|
||||
fprintf(stdout,"%s",col_val);
|
||||
}
|
||||
@@ -57,13 +65,15 @@ main(int argc, char **argv)
|
||||
int *bound_lens;
|
||||
char *delimiter = NULL;
|
||||
char *row_delimiter = NULL;
|
||||
char *quote_char = NULL;
|
||||
char *escape_char = NULL;
|
||||
char header_row = 1;
|
||||
char quote_text = 1;
|
||||
char insert_statements = 0;
|
||||
char sanitize = 0;
|
||||
int opt;
|
||||
|
||||
while ((opt=getopt(argc, argv, "HQd:D:R:IS"))!=-1) {
|
||||
while ((opt=getopt(argc, argv, "HQq:X:d:D:R:IS"))!=-1) {
|
||||
switch (opt) {
|
||||
case 'H':
|
||||
header_row = 0;
|
||||
@@ -71,11 +81,14 @@ main(int argc, char **argv)
|
||||
case 'Q':
|
||||
quote_text = 0;
|
||||
break;
|
||||
case 'q':
|
||||
quote_char = (char *) g_strdup(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
delimiter = (char *) g_strdup(optarg);
|
||||
delimiter = escapes(optarg);
|
||||
break;
|
||||
case 'R':
|
||||
row_delimiter = (char *) g_strdup(optarg);
|
||||
row_delimiter = escapes(optarg);
|
||||
break;
|
||||
case 'I':
|
||||
insert_statements = 1;
|
||||
@@ -87,10 +100,16 @@ main(int argc, char **argv)
|
||||
case 'D':
|
||||
mdb_set_date_fmt(optarg);
|
||||
break;
|
||||
case 'X':
|
||||
escape_char = (char *) g_strdup(optarg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!quote_char) {
|
||||
quote_char = (char *) g_strdup("\"");
|
||||
}
|
||||
if (!delimiter) {
|
||||
delimiter = (char *) g_strdup(",");
|
||||
}
|
||||
@@ -112,8 +131,12 @@ main(int argc, char **argv)
|
||||
fprintf(stderr," -I INSERT statements (instead of CSV)\n");
|
||||
fprintf(stderr," -D <format> set the date format (see strftime(3) for details)\n");
|
||||
fprintf(stderr," -S Sanitize names (replace spaces etc. with underscore)\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");
|
||||
g_free (delimiter);
|
||||
g_free (row_delimiter);
|
||||
g_free (quote_char);
|
||||
if (escape_char) g_free (escape_char);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -122,17 +145,22 @@ main(int argc, char **argv)
|
||||
if (!(mdb = mdb_open(argv[optind], MDB_NOFLAGS))) {
|
||||
g_free (delimiter);
|
||||
g_free (row_delimiter);
|
||||
g_free (quote_char);
|
||||
if (escape_char) g_free (escape_char);
|
||||
mdb_exit();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
table = mdb_read_table_by_name(mdb, argv[argc-1], MDB_TABLE);
|
||||
if (!table) {
|
||||
fprintf(stderr, "Error: Table %s does not exist in this database.\n", argv[argc-1]);
|
||||
g_free (delimiter);
|
||||
g_free (row_delimiter);
|
||||
g_free (quote_char);
|
||||
if (escape_char) g_free (escape_char);
|
||||
mdb_close(mdb);
|
||||
mdb_exit();
|
||||
exit(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mdb_read_columns(table);
|
||||
@@ -149,7 +177,8 @@ main(int argc, char **argv)
|
||||
fprintf(stdout,"%s",col->name);
|
||||
for (j=1;j<table->num_cols;j++) {
|
||||
col=g_ptr_array_index(table->columns,j);
|
||||
fprintf(stdout,"%s%s",delimiter,col->name);
|
||||
fprintf(stdout,delimiter);
|
||||
fprintf(stdout,"%s",col->name);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
}
|
||||
@@ -174,16 +203,16 @@ main(int argc, char **argv)
|
||||
mdb_ole_read(mdb, col, bound_values[j], MDB_BIND_SIZE);
|
||||
}
|
||||
if (j>0) {
|
||||
fprintf(stdout,"%s",delimiter);
|
||||
fprintf(stdout,delimiter);
|
||||
}
|
||||
if (insert_statements && !bound_lens[j]) {
|
||||
print_col("NULL",0,col->col_type);
|
||||
print_col("NULL",0,col->col_type, quote_char, escape_char);
|
||||
} else {
|
||||
print_col(bound_values[j], quote_text, col->col_type);
|
||||
print_col(bound_values[j], quote_text, col->col_type, quote_char, escape_char);
|
||||
}
|
||||
}
|
||||
if (insert_statements) fprintf(stdout,")");
|
||||
fprintf(stdout,"%s", row_delimiter);
|
||||
fprintf(stdout, row_delimiter);
|
||||
}
|
||||
for (j=0;j<table->num_cols;j++) {
|
||||
g_free(bound_values[j]);
|
||||
@@ -194,6 +223,8 @@ main(int argc, char **argv)
|
||||
|
||||
g_free (delimiter);
|
||||
g_free (row_delimiter);
|
||||
g_free (quote_char);
|
||||
if (escape_char) g_free (escape_char);
|
||||
mdb_close(mdb);
|
||||
mdb_exit();
|
||||
|
||||
@@ -219,3 +250,27 @@ static char *sanitize_name(char *str, int sanitize)
|
||||
return namebuf;
|
||||
}
|
||||
|
||||
static char *escapes(char *s)
|
||||
{
|
||||
char *d = (char *) g_strdup(s);
|
||||
char *t = d;
|
||||
unsigned char encode = 0;
|
||||
|
||||
for (;*s; s++) {
|
||||
if (encode) {
|
||||
switch (*s) {
|
||||
case 'n': *t++='\n'; break;
|
||||
case 't': *t++='\t'; break;
|
||||
case 'r': *t++='\r'; break;
|
||||
default: *t++='\\'; *t++=*s; break;
|
||||
}
|
||||
encode=0;
|
||||
} else if (*s=='\\') {
|
||||
encode=1;
|
||||
} else {
|
||||
*t++=*s;
|
||||
}
|
||||
}
|
||||
*t='\0';
|
||||
return d;
|
||||
}
|
||||
|
@@ -53,8 +53,8 @@ extern void clear_history ();
|
||||
#include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
void dump_results(MdbSQL *sql, char *delimiter);
|
||||
void dump_results_pp(MdbSQL *sql);
|
||||
void dump_results(FILE *out, MdbSQL *sql, char *delimiter);
|
||||
void dump_results_pp(FILE *out, MdbSQL *sql);
|
||||
int yyparse(void);
|
||||
|
||||
#if SQL
|
||||
@@ -200,7 +200,7 @@ read_file(char *s, int line, unsigned int *bufsz, char *mybuf)
|
||||
return lines;
|
||||
}
|
||||
void
|
||||
run_query(MdbSQL *sql, char *mybuf, char *delimiter)
|
||||
run_query(FILE *out, MdbSQL *sql, char *mybuf, char *delimiter)
|
||||
{
|
||||
MdbTableDef *table;
|
||||
|
||||
@@ -219,48 +219,48 @@ run_query(MdbSQL *sql, char *mybuf, char *delimiter)
|
||||
}
|
||||
mdb_sql_bind_all(sql);
|
||||
if (pretty_print)
|
||||
dump_results_pp(sql);
|
||||
dump_results_pp(out, sql);
|
||||
else
|
||||
dump_results(sql, delimiter);
|
||||
dump_results(out, sql, delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
void print_value(char *v, int sz, int first)
|
||||
void print_value(FILE *out, char *v, int sz, int first)
|
||||
{
|
||||
int i;
|
||||
int vlen;
|
||||
|
||||
if (first) {
|
||||
fprintf(stdout,"|");
|
||||
fprintf(out,"|");
|
||||
}
|
||||
vlen = strlen(v);
|
||||
for (i=0;i<sz;i++) {
|
||||
fprintf(stdout,"%c",i >= vlen ? ' ' : v[i]);
|
||||
fprintf(out,"%c",i >= vlen ? ' ' : v[i]);
|
||||
}
|
||||
fprintf(stdout,"|");
|
||||
fprintf(out,"|");
|
||||
}
|
||||
static void print_break(int sz, int first)
|
||||
static void print_break(FILE *out, int sz, int first)
|
||||
{
|
||||
int i;
|
||||
if (first) {
|
||||
fprintf(stdout,"+");
|
||||
fprintf(out,"+");
|
||||
}
|
||||
for (i=0;i<sz;i++) {
|
||||
fprintf(stdout,"-");
|
||||
fprintf(out,"-");
|
||||
}
|
||||
fprintf(stdout,"+");
|
||||
fprintf(out,"+");
|
||||
}
|
||||
void print_rows_retrieved(unsigned long row_count)
|
||||
void print_rows_retrieved(FILE *out, unsigned long row_count)
|
||||
{
|
||||
if (!row_count)
|
||||
fprintf(stdout, "No Rows retrieved\n");
|
||||
fprintf(out, "No Rows retrieved\n");
|
||||
else if (row_count==1)
|
||||
fprintf(stdout, "1 Row retrieved\n");
|
||||
fprintf(out, "1 Row retrieved\n");
|
||||
else
|
||||
fprintf(stdout, "%lu Rows retrieved\n", row_count);
|
||||
fprintf(out, "%lu Rows retrieved\n", row_count);
|
||||
}
|
||||
void
|
||||
dump_results(MdbSQL *sql, char *delimiter)
|
||||
dump_results(FILE *out, MdbSQL *sql, char *delimiter)
|
||||
{
|
||||
unsigned int j;
|
||||
MdbSQLColumn *sqlcol;
|
||||
@@ -269,33 +269,33 @@ dump_results(MdbSQL *sql, char *delimiter)
|
||||
if (headers) {
|
||||
for (j=0;j<sql->num_columns-1;j++) {
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
fprintf(stdout, "%s%s", sqlcol->name,
|
||||
fprintf(out, "%s%s", sqlcol->name,
|
||||
delimiter ? delimiter : "\t");
|
||||
}
|
||||
sqlcol = g_ptr_array_index(sql->columns,sql->num_columns-1);
|
||||
fprintf(stdout, "%s", sqlcol->name);
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out, "%s", sqlcol->name);
|
||||
fprintf(out,"\n");
|
||||
}
|
||||
while(mdb_fetch_row(sql->cur_table)) {
|
||||
row_count++;
|
||||
for (j=0;j<sql->num_columns-1;j++) {
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
fprintf(stdout, "%s%s", sql->bound_values[j],
|
||||
fprintf(out, "%s%s", sql->bound_values[j],
|
||||
delimiter ? delimiter : "\t");
|
||||
}
|
||||
sqlcol = g_ptr_array_index(sql->columns,sql->num_columns-1);
|
||||
fprintf(stdout, "%s", sql->bound_values[sql->num_columns-1]);
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out, "%s", sql->bound_values[sql->num_columns-1]);
|
||||
fprintf(out,"\n");
|
||||
}
|
||||
if (footers) {
|
||||
print_rows_retrieved(row_count);
|
||||
print_rows_retrieved(out, row_count);
|
||||
}
|
||||
|
||||
mdb_sql_reset(sql);
|
||||
}
|
||||
|
||||
void
|
||||
dump_results_pp(MdbSQL *sql)
|
||||
dump_results_pp(FILE *out, MdbSQL *sql)
|
||||
{
|
||||
unsigned int j;
|
||||
MdbSQLColumn *sqlcol;
|
||||
@@ -307,40 +307,40 @@ dump_results_pp(MdbSQL *sql)
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
if (strlen(sqlcol->name)>sqlcol->disp_size)
|
||||
sqlcol->disp_size = strlen(sqlcol->name);
|
||||
print_break(sqlcol->disp_size, !j);
|
||||
print_break(out, sqlcol->disp_size, !j);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out,"\n");
|
||||
for (j=0;j<sql->num_columns;j++) {
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
print_value(sqlcol->name,sqlcol->disp_size,!j);
|
||||
print_value(out, sqlcol->name,sqlcol->disp_size,!j);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out,"\n");
|
||||
}
|
||||
|
||||
for (j=0;j<sql->num_columns;j++) {
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
print_break(sqlcol->disp_size, !j);
|
||||
print_break(out, sqlcol->disp_size, !j);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out,"\n");
|
||||
|
||||
/* print each row */
|
||||
while(mdb_fetch_row(sql->cur_table)) {
|
||||
row_count++;
|
||||
for (j=0;j<sql->num_columns;j++) {
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
print_value(sql->bound_values[j],sqlcol->disp_size,!j);
|
||||
print_value(out, sql->bound_values[j],sqlcol->disp_size,!j);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out,"\n");
|
||||
}
|
||||
|
||||
/* footer */
|
||||
for (j=0;j<sql->num_columns;j++) {
|
||||
sqlcol = g_ptr_array_index(sql->columns,j);
|
||||
print_break(sqlcol->disp_size, !j);
|
||||
print_break(out, sqlcol->disp_size, !j);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(out,"\n");
|
||||
if (footers) {
|
||||
print_rows_retrieved(row_count);
|
||||
print_rows_retrieved(out, row_count);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
@@ -430,7 +430,7 @@ char *delimiter = NULL;
|
||||
if ((!s) || (!fgets(s, 256, in))) {
|
||||
/* if we have something in the buffer, run it */
|
||||
if (strlen(mybuf))
|
||||
run_query(sql, mybuf, delimiter);
|
||||
run_query(out, sql, mybuf, delimiter);
|
||||
break;
|
||||
}
|
||||
if (s[strlen(s)-1]=='\n')
|
||||
@@ -450,7 +450,7 @@ char *delimiter = NULL;
|
||||
line = 0;
|
||||
} else if (!strcmp(s,"go")) {
|
||||
line = 0;
|
||||
run_query(sql, mybuf, delimiter);
|
||||
run_query(out, sql, mybuf, delimiter);
|
||||
mybuf[0]='\0';
|
||||
} else if (!strcmp(s,"reset")) {
|
||||
line = 0;
|
||||
|
Reference in New Issue
Block a user