Re: mdb-export extention
Michael Maassen <[email protected]> Fri, 13 Apr 2007 14:59:28 +0200 (CEST)
| Newsgroups | gmane.comp.db.mdb-tools.devel |
|---|---|
| Message-ID | <Pine.LNX.4.44.0704131458410.31549-200000@hefr31.physik.uni-freiburg.de> |
Hi, ok here it is as diff (sorry) Mic Dr. Michael Maaßen Uni Freiburg mailto:[email protected] Physikalisches Institut Abt. Prof. Herten Phone: + 49 - 761 - 203 - 5720 Hermann-Herder-Str. 3 Fax: + 49 - 761 - 203 - 5938 79104 Freiburg On Thu, 5 Apr 2007, Jeff Smith wrote: > I have not had a chance to review this yet. Please note that this would be easier for me and others to review if sent as a unified patch (diff -u oldfile newfile) against what is in CVS. -- Jeff Smith ----- Original Message ---- From: Michael Maassen <[email protected]> To: [email protected] Sent: Thursday, April 5, 2007 6:57:14 AM Subject: [mdb-dev] mdb-export extention Hi, appended is a version of mdb-export which 1) escapes non-printable chars if an escape char is given and no quoting is wanted: ex. -X '=' -Q 2) exports large OLE-columns, which requiers mdb_ole_read_next() (please have a look in ending the loop) You can insert the patch in your dist if you like. Regards, Mic Dr. Michael Maaßen Uni Freiburg mailto:[email protected] Physikalisches Institut Abt. Prof. Herten Phone: + 49 - 761 - 203 - 5720 Hermann-Herder-Str. 3 Fax: + 49 - 761 - 203 - 5938 79104 Freiburg ____________________________________________________________________________________ It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. http://tools.search.yahoo.com/toolbar/features/mail/ > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ mdbtools-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
mdb-cvs.diff
(text/plain, 5.5 KB)
--- mdb-cvs.c 2007-04-05 13:48:20.000000000 +0200 +++ /localscratch/mic/mdbtools.cvs/src/util/mdb-export.c 2007-03-06 02:16:54.000000000 +0100 @@ -16,10 +16,7 @@ * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. - * - * add binary escapes by Michael Maassen <[email protected]> */ - #include "mdbtools.h" #ifdef DMALLOC @@ -27,77 +24,36 @@ #endif #undef MDB_BIND_SIZE -#define MDB_BIND_SIZE 20000000 +#define MDB_BIND_SIZE 200000 -#define is_text_type(x) (x==MDB_TEXT || x==MDB_MEMO || x==MDB_SDATETIME || x==MDB_OLE) -//#define is_text_type(x) (x==MDB_TEXT || x==MDB_MEMO || x==MDB_SDATETIME) +#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); -char *delimiter = NULL; -char *row_delimiter = NULL; - void 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,quote_char); - for (s=col_val;*s;s++) { - 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,quote_char); - } else { - fprintf(stdout,"%s",col_val); - } -} + gchar *s; -void -nprint_col(gchar *col_val, int len, int quote_text, int col_type, char *quote_char, char *escape_char) -{ - gchar *s; - int i; - if (len == -1) len = strlen(col_val); - - if (quote_text && is_text_type(col_type)) { - fprintf(stdout,quote_char); - for (s=col_val;*s;s++) { - 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,quote_char); - } else if (!quote_text && escape_char) { // no quoting, only escape to Hex - for (i=0;i<len;i++) { - s = col_val + i; - if (!isprint(*s) || (*s == *escape_char) - || (*s == *delimiter) || (*s == *row_delimiter) ) { - fprintf(stdout,"%s%02x",escape_char,(unsigned char) *s); - } else { - fprintf(stdout,"%c",*s); + if (quote_text && is_text_type(col_type)) { + fprintf(stdout,quote_char); + for (s=col_val;*s;s++) { + 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); } - } else { - fprintf(stdout,"%s",col_val); - } + fprintf(stdout,quote_char); + } else { + fprintf(stdout,"%s",col_val); + } } - int main(int argc, char **argv) { @@ -107,6 +63,8 @@ MdbColumn *col; char **bound_values; int *bound_lens; + char *delimiter = NULL; + char *row_delimiter = NULL; char *quote_char = NULL; char *escape_char = NULL; char header_row = 1; @@ -242,25 +200,7 @@ col=g_ptr_array_index(table->columns,j); if ((col->col_type == MDB_OLE) && ((j==0) || (col->cur_value_len))) { - //int len; - // bound_lens[j]=mdb_ole_read(mdb, col, bound_values[j], MDB_BIND_SIZE); - gchar kkd_ptr[MDB_MEMO_OVERHEAD]; - void *kkd_pg = g_malloc(200000); - size_t len, pos; - - memcpy(kkd_ptr, bound_values[j], MDB_MEMO_OVERHEAD); - //col = g_ptr_array_index(table->columns, col_num - 1); - len = mdb_ole_read(mdb, col, kkd_ptr, MDB_BIND_SIZE); - memcpy(kkd_pg, bound_values[j], len); - bound_lens[j] = len; - while ((len = mdb_ole_read_next(mdb, col, kkd_ptr))) { - memcpy(kkd_pg + bound_lens[j], bound_values[j], len); - bound_lens[j] += len; - // FIXME: why 4076? how detect end? - if (len < 4076) break; - } - memcpy(bound_values[j],kkd_pg,bound_lens[j]); - g_free(kkd_pg); + mdb_ole_read(mdb, col, bound_values[j], MDB_BIND_SIZE); } if (j>0) { fprintf(stdout,delimiter); @@ -268,13 +208,7 @@ if (insert_statements && !bound_lens[j]) { print_col("NULL",0,col->col_type, quote_char, escape_char); } else { -#if 0 - print_col(bound_values[j], - quote_text, col->col_type, quote_char, escape_char); -#else - nprint_col(bound_values[j], bound_lens[j], - quote_text, col->col_type, quote_char, escape_char); -#endif + print_col(bound_values[j], quote_text, col->col_type, quote_char, escape_char); } } if (insert_statements) fprintf(stdout,")");