mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-09-18 18:22:07 +08:00
resync...no idea what's in here, it's been sitting on the shelf for a while
This commit is contained in:
@@ -46,19 +46,20 @@ char *g_input_ptr;
|
||||
#undef YY_INPUT
|
||||
#define YY_INPUT(b, r, ms) (r = mdb_sql_yyinput(b, ms));
|
||||
|
||||
MdbSQL *mdb_sql_init();
|
||||
MdbSQLSarg *mdb_sql_alloc_sarg();
|
||||
MdbSQLColumn *mdb_sql_alloc_column();
|
||||
MdbSQLTable *mdb_sql_alloc_table();
|
||||
MdbHandle *mdb_sql_open(MdbSQL *sql, char *db_name);
|
||||
int mdb_sql_add_sarg(MdbSQL *sql, char *col_name, int op, char *constant);
|
||||
void mdb_sql_all_columns(MdbSQL *sql);
|
||||
int mdb_sql_add_column(MdbSQL *sql, char *column_name);
|
||||
int mdb_sql_add_table(MdbSQL *sql, char *table_name);
|
||||
void mdb_sql_dump(MdbSQL *sql);
|
||||
void mdb_sql_exit(MdbSQL *sql);
|
||||
void mdb_sql_reset(MdbSQL *sql);
|
||||
void mdb_sql_listtables(MdbSQL *sql);
|
||||
void mdb_sql_select(MdbSQL *sql);
|
||||
extern MdbSQL *mdb_sql_init();
|
||||
extern MdbSQLSarg *mdb_sql_alloc_sarg();
|
||||
extern MdbSQLColumn *mdb_sql_alloc_column();
|
||||
extern MdbSQLTable *mdb_sql_alloc_table();
|
||||
extern MdbHandle *mdb_sql_open(MdbSQL *sql, char *db_name);
|
||||
extern int mdb_sql_add_sarg(MdbSQL *sql, char *col_name, int op, char *constant);
|
||||
extern void mdb_sql_all_columns(MdbSQL *sql);
|
||||
extern int mdb_sql_add_column(MdbSQL *sql, char *column_name);
|
||||
extern int mdb_sql_add_table(MdbSQL *sql, char *table_name);
|
||||
extern void mdb_sql_dump(MdbSQL *sql);
|
||||
extern void mdb_sql_exit(MdbSQL *sql);
|
||||
extern void mdb_sql_reset(MdbSQL *sql);
|
||||
extern void mdb_sql_listtables(MdbSQL *sql);
|
||||
extern void mdb_sql_select(MdbSQL *sql);
|
||||
extern void mdbsql_bind_all(MdbSQL *sql);
|
||||
|
||||
#endif
|
||||
|
@@ -209,6 +209,11 @@ typedef struct {
|
||||
GArray *columns;
|
||||
} MdbCatalogEntry;
|
||||
|
||||
typedef struct {
|
||||
gchar *name;
|
||||
GHashTable *hash;
|
||||
} MdbProperties;
|
||||
|
||||
typedef union {
|
||||
int i;
|
||||
double d;
|
||||
@@ -230,9 +235,14 @@ typedef struct {
|
||||
int col_num;
|
||||
int cur_value_start;
|
||||
int cur_value_len;
|
||||
/* MEMO/OLE readers */
|
||||
guint32 cur_blob_pg;
|
||||
int cur_blob_row;
|
||||
int chunk_size;
|
||||
/* numerics only */
|
||||
int col_prec;
|
||||
int col_scale;
|
||||
MdbProperties *props;
|
||||
} MdbColumn;
|
||||
|
||||
typedef struct _mdbsargtree {
|
||||
@@ -291,6 +301,7 @@ typedef struct {
|
||||
MdbIndex *scan_idx;
|
||||
MdbHandle *mdbidx;
|
||||
MdbIndexChain *chain;
|
||||
MdbProperties *props;
|
||||
} MdbTableDef;
|
||||
|
||||
struct mdbindex {
|
||||
@@ -341,18 +352,25 @@ extern MdbStatistics *mdb_alloc_stats(MdbHandle *mdb);
|
||||
/* file.c */
|
||||
extern size_t mdb_read_pg(MdbHandle *mdb, unsigned long pg);
|
||||
extern size_t mdb_read_alt_pg(MdbHandle *mdb, unsigned long pg);
|
||||
extern unsigned char mdb_get_byte(MdbHandle *mdb, int offset);
|
||||
extern int mdb_get_int16(MdbHandle *mdb, int offset);
|
||||
extern gint32 mdb_get_int24(MdbHandle *mdb, int offset);
|
||||
extern long mdb_get_int32(MdbHandle *mdb, int offset);
|
||||
extern float mdb_get_single(MdbHandle *mdb, int offset);
|
||||
extern double mdb_get_double(MdbHandle *mdb, int offset);
|
||||
extern unsigned char mdb_get_byte(unsigned char *buf, int offset);
|
||||
extern int mdb_get_int16(unsigned char *buf, int offset);
|
||||
extern gint32 mdb_get_int24(unsigned char *buf, int offset);
|
||||
extern long mdb_get_int32(unsigned char *buf, int offset);
|
||||
extern float mdb_get_single(unsigned char *buf, int offset);
|
||||
extern double mdb_get_double(unsigned char *buf, int offset);
|
||||
extern unsigned char mdb_pg_get_byte(MdbHandle *mdb, int offset);
|
||||
extern int mdb_pg_get_int16(MdbHandle *mdb, int offset);
|
||||
extern gint32 mdb_pg_get_int24(MdbHandle *mdb, int offset);
|
||||
extern long mdb_pg_get_int32(MdbHandle *mdb, int offset);
|
||||
extern float mdb_pg_get_single(MdbHandle *mdb, int offset);
|
||||
extern double mdb_pg_get_double(MdbHandle *mdb, int offset);
|
||||
extern MdbHandle *mdb_open(char *filename);
|
||||
extern void mdb_close(MdbHandle *mdb);
|
||||
extern MdbHandle *mdb_clone_handle(MdbHandle *mdb);
|
||||
extern void mdb_swap_pgbuf(MdbHandle *mdb);
|
||||
extern long _mdb_get_int32(unsigned char *buf, int offset);
|
||||
extern gint32 mdb_get_int24_msb(MdbHandle *mdb, int offset);
|
||||
extern void mdb_free_tabledef(MdbTableDef *table);
|
||||
|
||||
/* catalog.c */
|
||||
GPtrArray *mdb_read_catalog(MdbHandle *mdb, int obj_type);
|
||||
@@ -368,17 +386,20 @@ extern GPtrArray *mdb_read_columns(MdbTableDef *table);
|
||||
extern void mdb_table_dump(MdbCatalogEntry *entry);
|
||||
|
||||
/* data.c */
|
||||
extern int mdb_bind_column_by_name(MdbTableDef *table, gchar *col_name, void *bind_ptr);
|
||||
extern void mdb_data_dump(MdbTableDef *table);
|
||||
extern void mdb_bind_column(MdbTableDef *table, int col_num, void *bind_ptr);
|
||||
extern int mdb_rewind_table(MdbTableDef *table);
|
||||
extern int mdb_fetch_row(MdbTableDef *table);
|
||||
extern int mdb_is_fixed_col(MdbColumn *col);
|
||||
extern char *mdb_col_to_string(MdbHandle *mdb, int start, int datatype, int size);
|
||||
extern char *mdb_col_to_string(MdbHandle *mdb, unsigned char *buf, int start, int datatype, int size);
|
||||
extern int mdb_find_end_of_row(MdbHandle *mdb, int row);
|
||||
extern int mdb_col_fixed_size(MdbColumn *col);
|
||||
extern int mdb_col_disp_size(MdbColumn *col);
|
||||
extern void mdb_bind_len(MdbTableDef *table, int col_num, int *len_ptr);
|
||||
extern int mdb_unicode2ascii(MdbHandle *mdb, unsigned char *buf, int offset, int len, char *dest);
|
||||
extern int mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr);
|
||||
extern int mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size);
|
||||
|
||||
/* dump.c */
|
||||
extern void buffer_dump(const unsigned char* buf, int start, int end);
|
||||
@@ -395,10 +416,14 @@ extern int mdb_test_sargs(MdbTableDef *table, MdbField *fields, int num_fields);
|
||||
extern int mdb_test_sarg(MdbHandle *mdb, MdbColumn *col, MdbSargNode *node, void *buf, int len);
|
||||
extern void mdb_sql_walk_tree(MdbSargNode *node, MdbSargTreeFunc func, gpointer data);
|
||||
extern int mdb_find_indexable_sargs(MdbSargNode *node, gpointer data);
|
||||
extern int mdb_add_sarg_by_name(MdbTableDef *table, char *colname, MdbSarg *in_sarg);
|
||||
|
||||
/* index.c */
|
||||
extern GPtrArray *mdb_read_indices(MdbTableDef *table);
|
||||
extern void mdb_index_dump(MdbTableDef *table, MdbIndex *idx);
|
||||
extern void mdb_index_scan_free(MdbTableDef *table);
|
||||
extern int mdb_index_find_next_on_page(MdbHandle *mdb, MdbIndexPage *ipg);
|
||||
extern int mdb_index_find_next(MdbHandle *mdb, MdbIndex *idx, MdbIndexChain *chain, guint32 *pg, guint16 *row);
|
||||
|
||||
/* stats.c */
|
||||
extern void mdb_stats_on(MdbHandle *mdb);
|
||||
@@ -408,4 +433,7 @@ extern void mdb_dump_stats(MdbHandle *mdb);
|
||||
/* like.c */
|
||||
extern int mdb_like_cmp(char *s, char *r);
|
||||
|
||||
/* write.c */
|
||||
extern int mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields);
|
||||
|
||||
#endif /* _mdbtools_h_ */
|
||||
|
@@ -49,7 +49,7 @@
|
||||
<widget class="GtkTable" id="table1">
|
||||
<property name="border_width">10</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="n_rows">5</property>
|
||||
<property name="n_rows">8</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="row_spacing">8</property>
|
||||
@@ -290,6 +290,150 @@
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label6">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>Title:</b></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label7">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>Author:</b></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label8">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>Company:</b></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">True</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="bottom_attach">8</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="props_title">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</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>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="props_author">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="props_company">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"></property>
|
||||
<property name="use_underline">False</property>
|
||||
<property name="use_markup">False</property>
|
||||
<property name="justify">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap">False</property>
|
||||
<property name="selectable">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="bottom_attach">8</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
lib_LTLIBRARIES = libmdb.la
|
||||
libmdb_la_SOURCES= catalog.c mem.c file.c kkd.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c stats.c map.c
|
||||
libmdb_la_SOURCES= catalog.c mem.c file.c kkd.c table.c data.c dump.c backend.c money.c sargs.c index.c like.c write.c stats.c map.c props.c
|
||||
INCLUDES = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||
LIBS = $(GLIB_LIBS)
|
||||
|
@@ -25,7 +25,7 @@
|
||||
#include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
#define MDB_DEBUG_OLE 1
|
||||
#define MDB_DEBUG_OLE 0
|
||||
|
||||
char *mdb_money_to_string(MdbHandle *mdb, int start, char *s);
|
||||
static int _mdb_attempt_bind(MdbHandle *mdb,
|
||||
@@ -80,12 +80,12 @@ mdb_find_end_of_row(MdbHandle *mdb, int row)
|
||||
if (row==0) {
|
||||
row_end = fmt->pg_size - 1;
|
||||
} else {
|
||||
row_end = (mdb_get_int16(mdb, ((fmt->row_count_offset + 2) + (row - 1) * 2)) & 0x0FFF) - 1;
|
||||
row_end = (mdb_pg_get_int16(mdb, ((fmt->row_count_offset + 2) + (row - 1) * 2)) & 0x0FFF) - 1;
|
||||
}
|
||||
return row_end;
|
||||
#else
|
||||
for (i = row - 1; i >= 0; i--) {
|
||||
row_start = mdb_get_int16(mdb, ((fmt->row_count_offset + 2) + i * 2));
|
||||
row_start = mdb_pg_get_int16(mdb, ((fmt->row_count_offset + 2) + i * 2));
|
||||
if (!(row_start & 0x8000)) {
|
||||
break;
|
||||
}
|
||||
@@ -133,10 +133,11 @@ int ret;
|
||||
col->cur_value_len = 0;
|
||||
}
|
||||
if (col->bind_ptr || col->len_ptr) {
|
||||
ret = mdb_copy_ole(mdb, col->bind_ptr, start, len);
|
||||
//ret = mdb_copy_ole(mdb, col->bind_ptr, start, len);
|
||||
memcpy(col->bind_ptr, &mdb->pg_buf[start], MDB_MEMO_OVERHEAD);
|
||||
}
|
||||
if (col->len_ptr) {
|
||||
*col->len_ptr = ret;
|
||||
*col->len_ptr = MDB_MEMO_OVERHEAD;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -161,7 +162,7 @@ int ret;
|
||||
mdb_num_to_string(mdb, start, col->col_type, col->col_prec, col->col_scale));
|
||||
} else {
|
||||
strcpy(col->bind_ptr,
|
||||
mdb_col_to_string(mdb, start, col->col_type, len));
|
||||
mdb_col_to_string(mdb, mdb->pg_buf, start, col->col_type, len));
|
||||
}
|
||||
} else {
|
||||
strcpy(col->bind_ptr, "");
|
||||
@@ -194,7 +195,7 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
MdbField fields[256];
|
||||
int num_fields;
|
||||
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (row*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (row*2));
|
||||
row_end = mdb_find_end_of_row(mdb, row);
|
||||
|
||||
delflag = lookupflag = 0;
|
||||
@@ -226,7 +227,7 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
|
||||
/* find out all the important stuff about the row */
|
||||
if (IS_JET4(mdb)) {
|
||||
num_cols = mdb_get_int16(mdb, row_start);
|
||||
num_cols = mdb_pg_get_int16(mdb, row_start);
|
||||
} else {
|
||||
num_cols = mdb->pg_buf[row_start];
|
||||
}
|
||||
@@ -241,7 +242,7 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
}
|
||||
bitmask_sz = (num_cols - 1) / 8 + 1;
|
||||
if (IS_JET4(mdb)) {
|
||||
eod = mdb_get_int16(mdb, row_end - 3 - var_cols*2 - bitmask_sz);
|
||||
eod = mdb_pg_get_int16(mdb, row_end - 3 - var_cols*2 - bitmask_sz);
|
||||
} else {
|
||||
eod = mdb->pg_buf[row_end-1-var_cols-bitmask_sz];
|
||||
}
|
||||
@@ -297,8 +298,8 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
}
|
||||
if (IS_JET4(mdb)) {
|
||||
col_ptr = row_end - 2 - bitmask_sz - 1;
|
||||
eod = mdb_get_int16(mdb, col_ptr - var_cols*2);
|
||||
col_start = mdb_get_int16(mdb, col_ptr);
|
||||
eod = mdb_pg_get_int16(mdb, col_ptr - var_cols*2);
|
||||
col_start = mdb_pg_get_int16(mdb, col_ptr);
|
||||
} else {
|
||||
col_ptr = row_end - bitmask_sz - num_of_jumps - 1;
|
||||
if (mdb->pg_buf[col_ptr]==0xFF) {
|
||||
@@ -336,7 +337,7 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
len=eod - col_start;
|
||||
} else {
|
||||
if (IS_JET4(mdb)) {
|
||||
//next_col = mdb_get_int16(mdb, row_end - bitmask_sz - var_cols_found * 2 - 2 - 1) ;
|
||||
//next_col = mdb_pg_get_int16(mdb, row_end - bitmask_sz - var_cols_found * 2 - 2 - 1) ;
|
||||
next_col = mdb->pg_buf[row_end - bitmask_sz - var_cols_found * 2 - 2] * 256 +
|
||||
mdb->pg_buf[row_end - bitmask_sz - var_cols_found * 2 - 2 - 1] ;
|
||||
len = next_col - col_start;
|
||||
@@ -382,10 +383,10 @@ static int _mdb_attempt_bind(MdbHandle *mdb,
|
||||
{
|
||||
if (col->col_type == MDB_BOOL) {
|
||||
mdb_xfer_bound_bool(mdb, col, isnull);
|
||||
} else if (col->col_type == MDB_OLE) {
|
||||
mdb_xfer_bound_ole(mdb, offset, col, len);
|
||||
} else if (isnull) {
|
||||
mdb_xfer_bound_data(mdb, 0, col, 0);
|
||||
} else if (col->col_type == MDB_OLE) {
|
||||
mdb_xfer_bound_ole(mdb, offset, col, len);
|
||||
} else {
|
||||
//if (!mdb_test_sargs(mdb, col, offset, len)) {
|
||||
//return 0;
|
||||
@@ -401,7 +402,7 @@ MdbCatalogEntry *entry = table->entry;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
int pgnum, i, bitn;
|
||||
|
||||
pgnum = _mdb_get_int32(table->usage_map,1);
|
||||
pgnum = mdb_get_int32(table->usage_map,1);
|
||||
/* the first 5 bytes of the usage map mean something */
|
||||
for (i=5;i<table->map_sz;i++) {
|
||||
for (bitn=0;bitn<8;bitn++) {
|
||||
@@ -429,7 +430,7 @@ guint32 pgnum, i, j, bitn, map_pg;
|
||||
pgnum = 0;
|
||||
//printf("map size %ld\n", table->map_sz);
|
||||
for (i=1;i<table->map_sz-1;i+=4) {
|
||||
map_pg = _mdb_get_int32(table->usage_map, i);
|
||||
map_pg = mdb_get_int32(table->usage_map, i);
|
||||
//printf("loop %d pg %ld %02x%02x%02x%02x\n",i, map_pg,table->usage_map[i],table->usage_map[i+1],table->usage_map[i+2],table->usage_map[i+3]);
|
||||
|
||||
if (!map_pg) continue;
|
||||
@@ -479,7 +480,7 @@ int map_type;
|
||||
do {
|
||||
if (!mdb_read_pg(mdb, table->cur_phys_pg++))
|
||||
return 0;
|
||||
} while (mdb->pg_buf[0]!=0x01 || mdb_get_int32(mdb, 4)!=entry->table_pg);
|
||||
} while (mdb->pg_buf[0]!=0x01 || mdb_pg_get_int32(mdb, 4)!=entry->table_pg);
|
||||
/* fprintf(stderr,"returning new page %ld\n", table->cur_phys_pg); */
|
||||
return table->cur_phys_pg;
|
||||
}
|
||||
@@ -519,7 +520,7 @@ guint32 pg;
|
||||
}
|
||||
mdb_read_pg(mdb, pg);
|
||||
} else {
|
||||
rows = mdb_get_int16(mdb,fmt->row_count_offset);
|
||||
rows = mdb_pg_get_int16(mdb,fmt->row_count_offset);
|
||||
|
||||
/* if at end of page, find a new page */
|
||||
if (table->cur_row >= rows) {
|
||||
@@ -575,6 +576,130 @@ int i;
|
||||
return text;
|
||||
}
|
||||
#endif
|
||||
int
|
||||
mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr)
|
||||
{
|
||||
guint16 ole_len;
|
||||
guint16 ole_flags;
|
||||
int row_stop, row_start;
|
||||
int len;
|
||||
|
||||
ole_len = mdb_get_int16(ole_ptr, 0);
|
||||
ole_flags = mdb_get_int16(ole_ptr, 2);
|
||||
|
||||
if (ole_flags == 0x8000) {
|
||||
/* inline fields don't have a next */
|
||||
return 0;
|
||||
} else if (ole_flags == 0x4000) {
|
||||
/* 0x4000 flagged ole's are contained on one page and thus
|
||||
* should be handled entirely with mdb_ole_read() */
|
||||
return 0;
|
||||
} else if (ole_flags == 0x0000) {
|
||||
if(mdb_read_alt_pg(mdb, col->cur_blob_pg) != mdb->fmt->pg_size) {
|
||||
/* Failed to read */
|
||||
return 0;
|
||||
}
|
||||
/* swap the alt and regular page buffers, so we can call get_int16 */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
row_stop = mdb_find_end_of_row(mdb, col->cur_blob_row);
|
||||
row_start = mdb_pg_get_int16(mdb, 10 + col->cur_blob_row * 2);
|
||||
len = row_stop - row_start;
|
||||
if (col->bind_ptr)
|
||||
memcpy(col->bind_ptr, &mdb->pg_buf[row_start], len);
|
||||
|
||||
col->cur_blob_row = mdb->pg_buf[row_start];
|
||||
col->cur_blob_pg = mdb_pg_get_int24(mdb, row_start+1);
|
||||
|
||||
/* make sure to swap page back */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
|
||||
return len;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
|
||||
{
|
||||
guint16 ole_len;
|
||||
guint16 ole_flags;
|
||||
int row_stop, row_start;
|
||||
int len;
|
||||
|
||||
ole_len = mdb_get_int16(ole_ptr, 0);
|
||||
ole_flags = mdb_get_int16(ole_ptr, 2);
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("ole len = %d ole flags = %08x\n", ole_len, ole_flags);
|
||||
#endif
|
||||
|
||||
col->chunk_size = chunk_size;
|
||||
|
||||
if (ole_flags == 0x8000) {
|
||||
/* inline ole field, if we can satisfy it, then do it */
|
||||
len = col->cur_value_len - MDB_MEMO_OVERHEAD;
|
||||
if (chunk_size >= len) {
|
||||
if (col->bind_ptr)
|
||||
memcpy(col->bind_ptr,
|
||||
&mdb->pg_buf[col->cur_value_start +
|
||||
MDB_MEMO_OVERHEAD],
|
||||
len);
|
||||
return len;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else if (ole_flags == 0x4000) {
|
||||
col->cur_blob_row = ((char *)ole_ptr)[4];
|
||||
col->cur_blob_pg = mdb_get_int24(ole_ptr, 5);
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("ole row = %d ole pg = %ld\n", col->cur_blob_row, col->cur_blob_pg);
|
||||
#endif
|
||||
if(mdb_read_alt_pg(mdb, col->cur_blob_pg) != mdb->fmt->pg_size) {
|
||||
/* Failed to read */
|
||||
return 0;
|
||||
}
|
||||
/* swap the alt and regular page buffers, so we can call get_int16 */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
row_stop = mdb_find_end_of_row(mdb, col->cur_blob_row);
|
||||
row_start = mdb_pg_get_int16(mdb, 10 + col->cur_blob_row * 2);
|
||||
len = row_stop - row_start + 1;
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("start %d stop %d len %d\n", row_start, row_stop, len);
|
||||
#endif
|
||||
if (col->bind_ptr) {
|
||||
memcpy(col->bind_ptr, &mdb->pg_buf[row_start], len);
|
||||
#if MDB_DEBUG_OLE
|
||||
buffer_dump(col->bind_ptr, 0, 16);
|
||||
#endif
|
||||
}
|
||||
/* make sure to swap page back */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
return len;
|
||||
} else if (ole_flags == 0x0000) {
|
||||
col->cur_blob_row = ((char *)ole_ptr)[4];
|
||||
col->cur_blob_pg = mdb_get_int24(ole_ptr, 5);
|
||||
if(mdb_read_alt_pg(mdb, col->cur_blob_pg) != mdb->fmt->pg_size) {
|
||||
/* Failed to read */
|
||||
return 0;
|
||||
}
|
||||
/* swap the alt and regular page buffers, so we can call get_int16 */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
row_stop = mdb_find_end_of_row(mdb, col->cur_blob_row);
|
||||
row_start = mdb_pg_get_int16(mdb, 10 + col->cur_blob_row * 2);
|
||||
len = row_stop - row_start;
|
||||
if (col->bind_ptr)
|
||||
memcpy(col->bind_ptr, &mdb->pg_buf[row_start], len);
|
||||
|
||||
col->cur_blob_row = mdb->pg_buf[row_start];
|
||||
col->cur_blob_pg = mdb_pg_get_int24(mdb, row_start+1);
|
||||
|
||||
/* make sure to swap page back */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
|
||||
return len;
|
||||
} else {
|
||||
fprintf(stderr,"Unhandled ole field flags = %04x\n", ole_flags);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int mdb_copy_ole(MdbHandle *mdb, char *dest, int start, int size)
|
||||
{
|
||||
guint16 ole_len;
|
||||
@@ -588,8 +713,8 @@ guint16 len, cur;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ole_len = mdb_get_int16(mdb, start);
|
||||
ole_flags = mdb_get_int16(mdb, start+2);
|
||||
ole_len = mdb_pg_get_int16(mdb, start);
|
||||
ole_flags = mdb_pg_get_int16(mdb, start+2);
|
||||
|
||||
if (ole_flags == 0x8000) {
|
||||
len = size - MDB_MEMO_OVERHEAD;
|
||||
@@ -603,7 +728,7 @@ guint16 len, cur;
|
||||
*/
|
||||
ole_row = mdb->pg_buf[start+4];
|
||||
|
||||
lval_pg = mdb_get_int24(mdb, start+5);
|
||||
lval_pg = mdb_pg_get_int24(mdb, start+5);
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("Reading LVAL page %06x\n", lval_pg);
|
||||
#endif
|
||||
@@ -614,11 +739,11 @@ guint16 len, cur;
|
||||
/* swap the alt and regular page buffers, so we can call get_int16 */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
if (ole_row) {
|
||||
row_stop = mdb_get_int16(mdb, 10 + (ole_row - 1) * 2) & 0x0FFF;
|
||||
row_stop = mdb_pg_get_int16(mdb, 10 + (ole_row - 1) * 2) & 0x0FFF;
|
||||
} else {
|
||||
row_stop = mdb->fmt->pg_size - 1;
|
||||
}
|
||||
row_start = mdb_get_int16(mdb, 10 + ole_row * 2);
|
||||
row_start = mdb_pg_get_int16(mdb, 10 + ole_row * 2);
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("row num %d row start %d row stop %d\n", ole_row, row_start, row_stop);
|
||||
#endif
|
||||
@@ -629,7 +754,7 @@ guint16 len, cur;
|
||||
return len;
|
||||
} else if (ole_flags == 0x0000) {
|
||||
ole_row = mdb->pg_buf[start+4];
|
||||
lval_pg = mdb_get_int24(mdb, start+5);
|
||||
lval_pg = mdb_pg_get_int24(mdb, start+5);
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("Reading LVAL page %06x\n", lval_pg);
|
||||
#endif
|
||||
@@ -642,11 +767,11 @@ guint16 len, cur;
|
||||
return 0;
|
||||
}
|
||||
if (ole_row) {
|
||||
row_stop = mdb_get_int16(mdb, 10 + (ole_row - 1) * 2) & 0x0FFF;
|
||||
row_stop = mdb_pg_get_int16(mdb, 10 + (ole_row - 1) * 2) & 0x0FFF;
|
||||
} else {
|
||||
row_stop = mdb->fmt->pg_size - 1;
|
||||
}
|
||||
row_start = mdb_get_int16(mdb, 10 + ole_row * 2);
|
||||
row_start = mdb_pg_get_int16(mdb, 10 + ole_row * 2);
|
||||
#if MDB_DEBUG_OLE
|
||||
printf("row num %d row start %d row stop %d\n", ole_row, row_start, row_stop);
|
||||
#endif
|
||||
@@ -658,7 +783,7 @@ guint16 len, cur;
|
||||
|
||||
/* find next lval page */
|
||||
ole_row = mdb->pg_buf[row_start];
|
||||
lval_pg = mdb_get_int24(mdb, row_start+1);
|
||||
lval_pg = mdb_pg_get_int24(mdb, row_start+1);
|
||||
} while (lval_pg);
|
||||
/* make sure to swap page back */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
@@ -687,8 +812,8 @@ guint16 len;
|
||||
buffer_dump(mdb->pg_buf, start, start + 12);
|
||||
#endif
|
||||
|
||||
memo_len = mdb_get_int16(mdb, start);
|
||||
memo_flags = mdb_get_int16(mdb, start+2);
|
||||
memo_len = mdb_pg_get_int16(mdb, start);
|
||||
memo_flags = mdb_pg_get_int16(mdb, start+2);
|
||||
|
||||
if (memo_flags & 0x8000) {
|
||||
/* inline memo field */
|
||||
@@ -702,7 +827,7 @@ guint16 len;
|
||||
*/
|
||||
memo_row = mdb->pg_buf[start+4];
|
||||
|
||||
lval_pg = mdb_get_int24(mdb, start+5);
|
||||
lval_pg = mdb_pg_get_int24(mdb, start+5);
|
||||
#if MDB_DEBUG
|
||||
printf("Reading LVAL page %06x\n", lval_pg);
|
||||
#endif
|
||||
@@ -713,11 +838,11 @@ guint16 len;
|
||||
/* swap the alt and regular page buffers, so we can call get_int16 */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
if (memo_row) {
|
||||
row_stop = mdb_get_int16(mdb, fmt->row_count_offset + 2 + (memo_row - 1) * 2) & 0x0FFF;
|
||||
row_stop = mdb_pg_get_int16(mdb, fmt->row_count_offset + 2 + (memo_row - 1) * 2) & 0x0FFF;
|
||||
} else {
|
||||
row_stop = fmt->pg_size - 1;
|
||||
}
|
||||
row_start = mdb_get_int16(mdb, fmt->row_count_offset + 2 + memo_row * 2);
|
||||
row_start = mdb_pg_get_int16(mdb, fmt->row_count_offset + 2 + memo_row * 2);
|
||||
#if MDB_DEBUG
|
||||
printf("row num %d row start %d row stop %d\n", memo_row, row_start, row_stop);
|
||||
buffer_dump(mdb->pg_buf,row_start, row_start + len);
|
||||
@@ -746,7 +871,7 @@ guint16 len;
|
||||
return text;
|
||||
} else { /* if (memo_flags == 0x0000) { */
|
||||
memo_row = mdb->pg_buf[start+4];
|
||||
lval_pg = mdb_get_int24(mdb, start+5);
|
||||
lval_pg = mdb_pg_get_int24(mdb, start+5);
|
||||
#if MDB_DEBUG
|
||||
printf("Reading LVAL page %06x\n", lval_pg);
|
||||
#endif
|
||||
@@ -759,11 +884,11 @@ guint16 len;
|
||||
return "";
|
||||
}
|
||||
if (memo_row) {
|
||||
row_stop = mdb_get_int16(mdb, 10 + (memo_row - 1) * 2) & 0x0FFF;
|
||||
row_stop = mdb_pg_get_int16(mdb, 10 + (memo_row - 1) * 2) & 0x0FFF;
|
||||
} else {
|
||||
row_stop = fmt->pg_size - 1;
|
||||
}
|
||||
row_start = mdb_get_int16(mdb, 10 + memo_row * 2);
|
||||
row_start = mdb_pg_get_int16(mdb, 10 + memo_row * 2);
|
||||
#if MDB_DEBUG
|
||||
printf("row num %d row start %d row stop %d\n", memo_row, row_start, row_stop);
|
||||
#endif
|
||||
@@ -775,7 +900,7 @@ guint16 len;
|
||||
|
||||
/* find next lval page */
|
||||
memo_row = mdb->pg_buf[row_start];
|
||||
lval_pg = mdb_get_int24(mdb, row_start+1);
|
||||
lval_pg = mdb_pg_get_int24(mdb, row_start+1);
|
||||
} while (lval_pg);
|
||||
/* make sure to swap page back */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
@@ -786,12 +911,6 @@ guint16 len;
|
||||
return "";
|
||||
*/
|
||||
}
|
||||
#if 0
|
||||
strncpy(text, &mdb->pg_buf[start + MDB_MEMO_OVERHEAD],
|
||||
size - MDB_MEMO_OVERHEAD);
|
||||
text[size - MDB_MEMO_OVERHEAD]='\0';
|
||||
return text;
|
||||
#endif
|
||||
}
|
||||
char *
|
||||
mdb_num_to_string(MdbHandle *mdb, int start, int datatype, int prec, int scale)
|
||||
@@ -821,7 +940,7 @@ gint32 l;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
char *mdb_col_to_string(MdbHandle *mdb, int start, int datatype, int size)
|
||||
char *mdb_col_to_string(MdbHandle *mdb, unsigned char *buf, int start, int datatype, int size)
|
||||
{
|
||||
/* FIX ME -- not thread safe */
|
||||
static char text[MDB_BIND_SIZE];
|
||||
@@ -834,23 +953,23 @@ int i;
|
||||
** by mdb_xfer_bound_bool() */
|
||||
break;
|
||||
case MDB_BYTE:
|
||||
sprintf(text,"%d",mdb_get_byte(mdb, start));
|
||||
sprintf(text,"%d",mdb_get_byte(buf, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_INT:
|
||||
sprintf(text,"%ld",(long)mdb_get_int16(mdb, start));
|
||||
sprintf(text,"%ld",(long)mdb_get_int16(buf, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_LONGINT:
|
||||
sprintf(text,"%ld",mdb_get_int32(mdb, start));
|
||||
sprintf(text,"%ld",mdb_get_int32(buf, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_FLOAT:
|
||||
sprintf(text,"%f",mdb_get_single(mdb, start));
|
||||
sprintf(text,"%f",mdb_get_single(buf, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_DOUBLE:
|
||||
sprintf(text,"%f",mdb_get_double(mdb, start));
|
||||
sprintf(text,"%f",mdb_get_double(buf, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_TEXT:
|
||||
@@ -875,13 +994,13 @@ int i;
|
||||
text[size/2]='\0';
|
||||
}
|
||||
} else {
|
||||
strncpy(text, &mdb->pg_buf[start], size);
|
||||
strncpy(text, &buf[start], size);
|
||||
text[size]='\0';
|
||||
}
|
||||
return text;
|
||||
break;
|
||||
case MDB_SDATETIME:
|
||||
t = (long int)((mdb_get_double(mdb, start) - 25569.0) * 86400.0);
|
||||
t = (long int)((mdb_get_double(buf, start) - 25569.0) * 86400.0);
|
||||
strftime(text, MDB_BIND_SIZE, "%x %X",
|
||||
(struct tm*)gmtime(&t));
|
||||
return text;
|
||||
|
@@ -74,8 +74,6 @@ int ret;
|
||||
MdbHandle *_mdb_open(char *filename, gboolean writable)
|
||||
{
|
||||
MdbHandle *mdb;
|
||||
int key[] = {0x86, 0xfb, 0xec, 0x37, 0x5d, 0x44, 0x9c, 0xfa, 0xc6, 0x5e, 0x28, 0xe6, 0x13, 0xb6};
|
||||
int j,pos;
|
||||
int bufsize;
|
||||
MdbFile *f;
|
||||
|
||||
@@ -113,28 +111,13 @@ MdbFile *f;
|
||||
fprintf(stderr,"Couldn't read first page.\n");
|
||||
return NULL;
|
||||
}
|
||||
f->jet_version = mdb_get_int32(mdb, 0x14);
|
||||
f->jet_version = mdb_pg_get_int32(mdb, 0x14);
|
||||
if (IS_JET4(mdb)) {
|
||||
mdb->fmt = &MdbJet4Constants;
|
||||
} else {
|
||||
mdb->fmt = &MdbJet3Constants;
|
||||
}
|
||||
|
||||
/* get the db encryption key and xor it back to clear text */
|
||||
f->db_key = mdb_get_int32(mdb, 0x3e);
|
||||
f->db_key ^= 0xe15e01b9;
|
||||
|
||||
|
||||
/* get the db password located at 0x42 bytes into the file */
|
||||
for (pos=0;pos<14;pos++) {
|
||||
j = mdb_get_int32(mdb,0x42+pos);
|
||||
j ^= key[pos];
|
||||
if ( j != 0)
|
||||
f->db_passwd[pos] = j;
|
||||
else
|
||||
f->db_passwd[pos] = '\0';
|
||||
}
|
||||
|
||||
return mdb;
|
||||
}
|
||||
MdbHandle *mdb_open(char *filename)
|
||||
@@ -231,7 +214,12 @@ char tmpbuf[MDB_PGSIZE];
|
||||
memcpy(mdb->pg_buf,mdb->alt_pg_buf, MDB_PGSIZE);
|
||||
memcpy(mdb->alt_pg_buf,tmpbuf,MDB_PGSIZE);
|
||||
}
|
||||
unsigned char mdb_get_byte(MdbHandle *mdb, int offset)
|
||||
/* really stupid, just here for consistancy */
|
||||
unsigned char mdb_get_byte(unsigned char *buf, int offset)
|
||||
{
|
||||
return buf[offset];
|
||||
}
|
||||
unsigned char mdb_pg_get_byte(MdbHandle *mdb, int offset)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
@@ -240,25 +228,25 @@ unsigned char c;
|
||||
return c;
|
||||
}
|
||||
int
|
||||
_mdb_get_int16(unsigned char *buf, int offset)
|
||||
mdb_get_int16(unsigned char *buf, int offset)
|
||||
{
|
||||
return buf[offset+1]*256+buf[offset];
|
||||
}
|
||||
int
|
||||
mdb_get_int16(MdbHandle *mdb, int offset)
|
||||
mdb_pg_get_int16(MdbHandle *mdb, int offset)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (offset < 0 || offset+2 > mdb->fmt->pg_size) return -1;
|
||||
|
||||
i = _mdb_get_int16(mdb->pg_buf, offset);
|
||||
i = mdb_get_int16(mdb->pg_buf, offset);
|
||||
|
||||
mdb->cur_pos+=2;
|
||||
return i;
|
||||
|
||||
}
|
||||
gint32
|
||||
mdb_get_int24_msb(MdbHandle *mdb, int offset)
|
||||
mdb_pg_get_int24_msb(MdbHandle *mdb, int offset)
|
||||
{
|
||||
gint32 l;
|
||||
unsigned char *c;
|
||||
@@ -272,21 +260,31 @@ unsigned char *c;
|
||||
mdb->cur_pos+=3;
|
||||
return l;
|
||||
}
|
||||
gint32 mdb_get_int24(MdbHandle *mdb, int offset)
|
||||
gint32
|
||||
mdb_get_int24(unsigned char *buf, int offset)
|
||||
{
|
||||
gint32 l;
|
||||
gint32 l = 0;
|
||||
unsigned char *c;
|
||||
|
||||
if (offset <0 || offset+3 > mdb->fmt->pg_size) return -1;
|
||||
c = &mdb->pg_buf[offset];
|
||||
c = &buf[offset];
|
||||
|
||||
l =c[2]; l<<=8;
|
||||
l+=c[1]; l<<=8;
|
||||
l+=c[0];
|
||||
|
||||
return l;
|
||||
}
|
||||
gint32 mdb_pg_get_int24(MdbHandle *mdb, int offset)
|
||||
{
|
||||
guint32 l;
|
||||
|
||||
if (offset <0 || offset+4 > mdb->fmt->pg_size) return -1;
|
||||
|
||||
l = mdb_get_int24(mdb->pg_buf, offset);
|
||||
mdb->cur_pos+=3;
|
||||
return l;
|
||||
}
|
||||
long _mdb_get_int32(unsigned char *buf, int offset)
|
||||
long mdb_get_int32(unsigned char *buf, int offset)
|
||||
{
|
||||
long l;
|
||||
unsigned char *c;
|
||||
@@ -299,18 +297,18 @@ unsigned char *c;
|
||||
|
||||
return l;
|
||||
}
|
||||
long mdb_get_int32(MdbHandle *mdb, int offset)
|
||||
long mdb_pg_get_int32(MdbHandle *mdb, int offset)
|
||||
{
|
||||
long l;
|
||||
|
||||
if (offset <0 || offset+4 > mdb->fmt->pg_size) return -1;
|
||||
|
||||
l = _mdb_get_int32(mdb->pg_buf, offset);
|
||||
l = mdb_get_int32(mdb->pg_buf, offset);
|
||||
mdb->cur_pos+=4;
|
||||
return l;
|
||||
}
|
||||
float
|
||||
mdb_get_single(MdbHandle *mdb, int offset)
|
||||
mdb_get_single(unsigned char *buf, int offset)
|
||||
{
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
float f2;
|
||||
@@ -319,9 +317,8 @@ mdb_get_single(MdbHandle *mdb, int offset)
|
||||
#endif
|
||||
float f;
|
||||
|
||||
if (offset <0 || offset+4 > mdb->fmt->pg_size) return -1;
|
||||
|
||||
memcpy(&f, &mdb->pg_buf[offset], 4);
|
||||
memcpy(&f, &buf[offset], 4);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
f2 = f;
|
||||
@@ -330,12 +327,19 @@ mdb_get_single(MdbHandle *mdb, int offset)
|
||||
*(((unsigned char *)&f2)+sizeof(f)-1-i);
|
||||
}
|
||||
#endif
|
||||
mdb->cur_pos+=4;
|
||||
return f;
|
||||
}
|
||||
float
|
||||
mdb_pg_get_single(MdbHandle *mdb, int offset)
|
||||
{
|
||||
if (offset <0 || offset+4 > mdb->fmt->pg_size) return -1;
|
||||
|
||||
mdb->cur_pos+=4;
|
||||
return mdb_get_single(mdb->pg_buf, offset);
|
||||
}
|
||||
|
||||
double
|
||||
mdb_get_double(MdbHandle *mdb, int offset)
|
||||
mdb_get_double(unsigned char *buf, int offset)
|
||||
{
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
double d2;
|
||||
@@ -344,9 +348,8 @@ mdb_get_double(MdbHandle *mdb, int offset)
|
||||
#endif
|
||||
double d;
|
||||
|
||||
if (offset <0 || offset+4 > mdb->fmt->pg_size) return -1;
|
||||
|
||||
memcpy(&d, &mdb->pg_buf[offset], 8);
|
||||
memcpy(&d, &buf, 8);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
d2 = d;
|
||||
@@ -355,10 +358,16 @@ mdb_get_double(MdbHandle *mdb, int offset)
|
||||
*(((unsigned char *)&d2)+sizeof(d)-1-i);
|
||||
}
|
||||
#endif
|
||||
mdb->cur_pos+=8;
|
||||
return d;
|
||||
|
||||
}
|
||||
double
|
||||
mdb_pg_get_double(MdbHandle *mdb, int offset)
|
||||
{
|
||||
if (offset <0 || offset+4 > mdb->fmt->pg_size) return -1;
|
||||
mdb->cur_pos+=8;
|
||||
return mdb_get_double(mdb->pg_buf, offset);
|
||||
}
|
||||
int
|
||||
mdb_set_pos(MdbHandle *mdb, int pos)
|
||||
{
|
||||
|
@@ -135,7 +135,7 @@ gchar *tmpbuf;
|
||||
continue;
|
||||
}
|
||||
|
||||
pidx->num_rows = _mdb_get_int32(mdb->alt_pg_buf,
|
||||
pidx->num_rows = mdb_get_int32(mdb->alt_pg_buf,
|
||||
fmt->tab_cols_start_offset +
|
||||
(i*fmt->tab_ridx_entry_size));
|
||||
|
||||
@@ -227,13 +227,13 @@ int lastchar;
|
||||
|
||||
switch (col->col_type) {
|
||||
case MDB_BYTE:
|
||||
return mdb_test_int(sarg, mdb_get_byte(mdb, offset));
|
||||
return mdb_test_int(sarg, mdb_pg_get_byte(mdb, offset));
|
||||
break;
|
||||
case MDB_INT:
|
||||
return mdb_test_int(sarg, mdb_get_int16(mdb, offset));
|
||||
return mdb_test_int(sarg, mdb_pg_get_int16(mdb, offset));
|
||||
break;
|
||||
case MDB_LONGINT:
|
||||
return mdb_test_int(sarg, mdb_get_int32(mdb, offset));
|
||||
return mdb_test_int(sarg, mdb_pg_get_int32(mdb, offset));
|
||||
break;
|
||||
case MDB_TEXT:
|
||||
strncpy(tmpbuf, &mdb->pg_buf[offset],255);
|
||||
@@ -359,7 +359,7 @@ mdb_find_next_leaf(MdbHandle *mdb, MdbIndexChain *chain)
|
||||
//printf("finding next on pg %lu\n", ipg->pg);
|
||||
if (!mdb_index_find_next_on_page(mdb, ipg))
|
||||
return 0;
|
||||
pg = mdb_get_int24_msb(mdb, ipg->offset + ipg->len - 3);
|
||||
pg = mdb_pg_get_int24_msb(mdb, ipg->offset + ipg->len - 3);
|
||||
//printf("Looking at pg %lu at %lu %d\n", pg, ipg->offset, ipg->len);
|
||||
ipg->offset += ipg->len;
|
||||
|
||||
@@ -444,7 +444,7 @@ mdb_index_find_next(MdbHandle *mdb, MdbIndex *idx, MdbIndexChain *chain, guint32
|
||||
return 0;
|
||||
}
|
||||
*row = mdb->pg_buf[ipg->offset + ipg->len - 1];
|
||||
*pg = mdb_get_int24_msb(mdb, ipg->offset + ipg->len - 4);
|
||||
*pg = mdb_pg_get_int24_msb(mdb, ipg->offset + ipg->len - 4);
|
||||
|
||||
passed = mdb_index_test_sargs(mdb, idx, ipg->offset, ipg->len);
|
||||
|
||||
|
@@ -37,10 +37,10 @@ MdbColumnProp prop;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
|
||||
entry->props = g_array_new(FALSE,FALSE,sizeof(MdbColumnProp));
|
||||
len = mdb_get_int16(mdb,start);
|
||||
len = mdb_pg_get_int16(mdb,start);
|
||||
pos = start + 6;
|
||||
while (pos < start+len) {
|
||||
tmp = mdb_get_int16(mdb,pos); /* length of string */
|
||||
tmp = mdb_pg_get_int16(mdb,pos); /* length of string */
|
||||
pos += 2;
|
||||
cplen = tmp > MDB_MAX_OBJ_NAME ? MDB_MAX_OBJ_NAME : tmp;
|
||||
g_memmove(prop.name,&mdb->pg_buf[pos],cplen);
|
||||
@@ -65,23 +65,23 @@ int end;
|
||||
|
||||
fprintf(stdout,"\n data\n");
|
||||
fprintf(stdout,"-------\n");
|
||||
len = mdb_get_int16(mdb,start);
|
||||
len = mdb_pg_get_int16(mdb,start);
|
||||
fprintf(stdout,"length = %3d\n",len);
|
||||
pos = start + 6;
|
||||
end = start + len;
|
||||
while (pos < end) {
|
||||
fprintf(stdout,"pos = %3d\n",pos);
|
||||
start = pos;
|
||||
tmp = mdb_get_int16(mdb,pos); /* length of field */
|
||||
tmp = mdb_pg_get_int16(mdb,pos); /* length of field */
|
||||
pos += 2;
|
||||
col_type = mdb_get_int16(mdb,pos); /* ??? */
|
||||
col_type = mdb_pg_get_int16(mdb,pos); /* ??? */
|
||||
pos += 2;
|
||||
col_num = 0;
|
||||
if (col_type) {
|
||||
col_num = mdb_get_int16(mdb,pos);
|
||||
col_num = mdb_pg_get_int16(mdb,pos);
|
||||
pos += 2;
|
||||
}
|
||||
val_len = mdb_get_int16(mdb,pos);
|
||||
val_len = mdb_pg_get_int16(mdb,pos);
|
||||
pos += 2;
|
||||
fprintf(stdout,"length = %3d %04x %2d %2d ",tmp, col_type, col_num, val_len);
|
||||
for (i=0;i<val_len;i++) {
|
||||
@@ -110,13 +110,13 @@ int rowid = entry->kkd_rowid;
|
||||
|
||||
|
||||
mdb_read_pg(mdb, entry->kkd_pg);
|
||||
rows = mdb_get_int16(mdb,8);
|
||||
rows = mdb_pg_get_int16(mdb,8);
|
||||
fprintf(stdout,"number of rows = %d\n",rows);
|
||||
kkd_start = mdb_get_int16(mdb,10+rowid*2);
|
||||
kkd_start = mdb_pg_get_int16(mdb,10+rowid*2);
|
||||
fprintf(stdout,"kkd start = %d %04x\n",kkd_start,kkd_start);
|
||||
kkd_end = mdb->fmt->pg_size;
|
||||
for (i=0;i<rows;i++) {
|
||||
tmp = mdb_get_int16(mdb, 10+i*2);
|
||||
tmp = mdb_pg_get_int16(mdb, 10+i*2);
|
||||
if (tmp < mdb->fmt->pg_size &&
|
||||
tmp > kkd_start &&
|
||||
tmp < kkd_end) {
|
||||
@@ -126,8 +126,8 @@ int rowid = entry->kkd_rowid;
|
||||
fprintf(stdout,"kkd end = %d %04x\n",kkd_end,kkd_end);
|
||||
pos = kkd_start + 4; /* 4 = K K D \0 */
|
||||
while (pos < kkd_end) {
|
||||
tmp = mdb_get_int16(mdb,pos);
|
||||
row_type = mdb_get_int16(mdb,pos+4);
|
||||
tmp = mdb_pg_get_int16(mdb,pos);
|
||||
row_type = mdb_pg_get_int16(mdb,pos+4);
|
||||
fprintf(stdout,"row size = %3d type = 0x%02x\n",tmp,row_type);
|
||||
if (row_type==0x80) {
|
||||
fprintf(stdout,"\nColumn Properties\n");
|
||||
|
@@ -28,7 +28,7 @@ mdb_map_find_next0(MdbHandle *mdb, unsigned char *map, int map_sz, guint32 start
|
||||
{
|
||||
int pgnum, i, bitn;
|
||||
|
||||
pgnum = _mdb_get_int32(map,1);
|
||||
pgnum = mdb_get_int32(map,1);
|
||||
/* the first 5 bytes of the usage map mean something */
|
||||
for (i=5;i<map_sz;i++) {
|
||||
for (bitn=0;bitn<8;bitn++) {
|
||||
@@ -49,7 +49,7 @@ mdb_map_find_next1(MdbHandle *mdb, unsigned char *map, int map_sz, guint32 start
|
||||
pgnum = 0;
|
||||
//printf("map size %ld\n", table->map_sz);
|
||||
for (i=1;i<map_sz-1;i+=4) {
|
||||
map_pg = _mdb_get_int32(map, i);
|
||||
map_pg = mdb_get_int32(map, i);
|
||||
//printf("loop %d pg %ld %02x%02x%02x%02x\n",i, map_pg,table->usage_map[i],table->usage_map[i+1],table->usage_map[i+2],table->usage_map[i+3]);
|
||||
|
||||
if (!map_pg) continue;
|
||||
|
@@ -127,10 +127,10 @@ int lastchar;
|
||||
return mdb_test_int(node, (int)((char *)buf)[0]);
|
||||
break;
|
||||
case MDB_INT:
|
||||
return mdb_test_int(node, _mdb_get_int16(buf, 0));
|
||||
return mdb_test_int(node, mdb_get_int16(buf, 0));
|
||||
break;
|
||||
case MDB_LONGINT:
|
||||
return mdb_test_int(node, _mdb_get_int32(buf, 0));
|
||||
return mdb_test_int(node, mdb_get_int32(buf, 0));
|
||||
break;
|
||||
case MDB_TEXT:
|
||||
if (IS_JET4(mdb)) {
|
||||
|
@@ -55,18 +55,18 @@ int rownum, row_start, row_end;
|
||||
table = mdb_alloc_tabledef(entry);
|
||||
|
||||
mdb_read_pg(mdb, entry->table_pg);
|
||||
len = mdb_get_int16(mdb,8);
|
||||
len = mdb_pg_get_int16(mdb,8);
|
||||
|
||||
table->num_rows = mdb_get_int32(mdb, fmt->tab_num_rows_offset);
|
||||
table->num_cols = mdb_get_int16(mdb, fmt->tab_num_cols_offset);
|
||||
table->num_idxs = mdb_get_int32(mdb, fmt->tab_num_idxs_offset);
|
||||
table->num_real_idxs = mdb_get_int32(mdb, fmt->tab_num_ridxs_offset);
|
||||
table->num_rows = mdb_pg_get_int32(mdb, fmt->tab_num_rows_offset);
|
||||
table->num_cols = mdb_pg_get_int16(mdb, fmt->tab_num_cols_offset);
|
||||
table->num_idxs = mdb_pg_get_int32(mdb, fmt->tab_num_idxs_offset);
|
||||
table->num_real_idxs = mdb_pg_get_int32(mdb, fmt->tab_num_ridxs_offset);
|
||||
|
||||
/* grab a copy of the usage map */
|
||||
rownum = mdb->pg_buf[fmt->tab_usage_map_offset];
|
||||
mdb_read_alt_pg(mdb, mdb_get_int24(mdb, fmt->tab_usage_map_offset + 1));
|
||||
mdb_read_alt_pg(mdb, mdb_pg_get_int24(mdb, fmt->tab_usage_map_offset + 1));
|
||||
mdb_swap_pgbuf(mdb);
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (rownum*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (rownum*2));
|
||||
row_end = mdb_find_end_of_row(mdb, rownum);
|
||||
table->map_sz = row_end - row_start + 1;
|
||||
table->usage_map = malloc(table->map_sz);
|
||||
@@ -77,22 +77,24 @@ int rownum, row_start, row_end;
|
||||
/* swap back */
|
||||
mdb_swap_pgbuf(mdb);
|
||||
#if MDB_DEBUG_USAGE
|
||||
printf ("usage map found on page %ld start %d end %d\n", mdb_get_int24(mdb, fmt->tab_usage_map_offset + 1), row_start, row_end);
|
||||
printf ("usage map found on page %ld start %d end %d\n", mdb_pg_get_int24(mdb, fmt->tab_usage_map_offset + 1), row_start, row_end);
|
||||
#endif
|
||||
|
||||
|
||||
/* now grab the free space page map */
|
||||
#if 0
|
||||
mdb_swap_pgbuf(mdb);
|
||||
rownum = mdb->pg_buf[fmt->tab_free_map_offset];
|
||||
mdb_read_alt_pg(mdb, mdb_get_int24(mdb, fmt->tab_free_map_offset + 1));
|
||||
mdb_read_alt_pg(mdb, mdb_pg_get_int24(mdb, fmt->tab_free_map_offset + 1));
|
||||
mdb_swap_pgbuf(mdb);
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (rownum*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (rownum*2));
|
||||
row_end = mdb_find_end_of_row(mdb, rownum);
|
||||
table->freemap_sz = row_end - row_start + 1;
|
||||
table->free_usage_map = malloc(table->freemap_sz);
|
||||
memcpy(table->free_usage_map, &mdb->pg_buf[row_start], table->freemap_sz);
|
||||
#endif
|
||||
|
||||
table->first_data_pg = mdb_get_int16(mdb, fmt->tab_first_dpg_offset);
|
||||
table->first_data_pg = mdb_pg_get_int16(mdb, fmt->tab_first_dpg_offset);
|
||||
|
||||
return table;
|
||||
}
|
||||
@@ -105,7 +107,7 @@ int
|
||||
read_pg_if(MdbHandle *mdb, int *cur_pos, int offset)
|
||||
{
|
||||
if (*cur_pos + offset >= mdb->fmt->pg_size) {
|
||||
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
|
||||
mdb_read_pg(mdb, mdb_pg_get_int32(mdb,4));
|
||||
*cur_pos = 8 - (mdb->fmt->pg_size - (*cur_pos));
|
||||
return 1;
|
||||
}
|
||||
@@ -121,7 +123,7 @@ read_pg_if_32(MdbHandle *mdb, int *cur_pos)
|
||||
rc += read_pg_if(mdb, cur_pos, i);
|
||||
c[i] = mdb->pg_buf[(*cur_pos) + i];
|
||||
}
|
||||
return _mdb_get_int32(c, 0);
|
||||
return mdb_get_int32(c, 0);
|
||||
}
|
||||
guint16
|
||||
read_pg_if_16(MdbHandle *mdb, int *cur_pos)
|
||||
@@ -147,7 +149,7 @@ read_pg_if_n(MdbHandle *mdb, unsigned char *buf, int *cur_pos, int len)
|
||||
}
|
||||
half = (mdb->fmt->pg_size - *cur_pos - 1);
|
||||
memcpy(buf, &mdb->pg_buf[*cur_pos], half);
|
||||
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
|
||||
mdb_read_pg(mdb, mdb_pg_get_int32(mdb,4));
|
||||
memcpy(buf, &mdb->pg_buf[8], len - half);
|
||||
*cur_pos = 8 - (mdb->fmt->pg_size - (*cur_pos));
|
||||
return 1;
|
||||
@@ -235,7 +237,7 @@ GSList *slist = NULL;
|
||||
/* name wrapped over page */
|
||||
if (len < name_sz) {
|
||||
/* read the next pg */
|
||||
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
|
||||
mdb_read_pg(mdb, mdb_pg_get_int32(mdb,4));
|
||||
cur_name = 8 - (fmt->pg_size - cur_name);
|
||||
if (len % 2) cur_name++;
|
||||
/* get the rest of the name */
|
||||
@@ -258,7 +260,7 @@ GSList *slist = NULL;
|
||||
/* name wrapped over page */
|
||||
if (len < name_sz) {
|
||||
/* read the next pg */
|
||||
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
|
||||
mdb_read_pg(mdb, mdb_pg_get_int32(mdb,4));
|
||||
cur_name = 8 - (fmt->pg_size - cur_name);
|
||||
/* get the rest of the name */
|
||||
memcpy(&pcol->name[len], &mdb->pg_buf[cur_name], name_sz - len);
|
||||
@@ -316,7 +318,7 @@ guint32 pgnum;
|
||||
}
|
||||
if (table->usage_map) {
|
||||
printf("pages reserved by this object\n");
|
||||
pgnum = _mdb_get_int32(table->usage_map,1);
|
||||
pgnum = mdb_get_int32(table->usage_map,1);
|
||||
/* the first 5 bytes of the usage map mean something */
|
||||
coln = 0;
|
||||
for (i=5;i<table->map_sz;i++) {
|
||||
|
@@ -101,7 +101,7 @@ int byte_num, bit_num;
|
||||
int eod, len; /* end of data */
|
||||
|
||||
if (IS_JET4(mdb)) {
|
||||
num_cols = mdb_get_int16(mdb, row_start);
|
||||
num_cols = mdb_pg_get_int16(mdb, row_start);
|
||||
} else {
|
||||
num_cols = mdb->pg_buf[row_start];
|
||||
}
|
||||
@@ -140,7 +140,7 @@ int eod, len; /* end of data */
|
||||
|
||||
/* find the end of data pointer */
|
||||
if (IS_JET4(mdb)) {
|
||||
eod = mdb_get_int16(mdb, row_end - 3 - var_cols*2 - bitmask_sz);
|
||||
eod = mdb_pg_get_int16(mdb, row_end - 3 - var_cols*2 - bitmask_sz);
|
||||
} else {
|
||||
eod = mdb->pg_buf[row_end-1-var_cols-bitmask_sz];
|
||||
}
|
||||
@@ -181,7 +181,7 @@ int eod, len; /* end of data */
|
||||
row_end -
|
||||
bitmask_sz -
|
||||
var_cols_found * 2 - 2 - 1;
|
||||
next_col = mdb_get_int16(mdb, var_entry_pos);
|
||||
next_col = mdb_pg_get_int16(mdb, var_entry_pos);
|
||||
len = next_col - col_start;
|
||||
} else {
|
||||
var_entry_pos =
|
||||
@@ -268,9 +268,9 @@ mdb_pg_get_freespace(MdbHandle *mdb)
|
||||
MdbFormatConstants *fmt = mdb->fmt;
|
||||
int rows, free_start, free_end;
|
||||
|
||||
rows = mdb_get_int16(mdb, fmt->row_count_offset);
|
||||
rows = mdb_pg_get_int16(mdb, fmt->row_count_offset);
|
||||
free_start = fmt->row_count_offset + 2 + (rows * 2);
|
||||
free_end = mdb_get_int16(mdb, (fmt->row_count_offset + rows * 2)) -1;
|
||||
free_end = mdb_pg_get_int16(mdb, (fmt->row_count_offset + rows * 2)) -1;
|
||||
#if MDB_DEBUG_WRITE
|
||||
printf("free space left on page = %d\n", free_end - free_start);
|
||||
#endif
|
||||
@@ -332,11 +332,11 @@ mdb_insert_row(MdbTableDef *table, int num_fields, MdbField *fields)
|
||||
|
||||
|
||||
new_pg = mdb_new_data_pg(entry);
|
||||
num_rows = mdb_get_int16(mdb, fmt->row_count_offset);
|
||||
num_rows = mdb_pg_get_int16(mdb, fmt->row_count_offset);
|
||||
pos = mdb->fmt->pg_size;
|
||||
|
||||
for (i=0;i<num_rows;i++) {
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (i*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (i*2));
|
||||
row_end = mdb_find_end_of_row(mdb, i);
|
||||
row_size = row_end - row_start + 1;
|
||||
pos -= row_size;
|
||||
@@ -378,7 +378,7 @@ int old_row_size, new_row_size, delta, num_fields;
|
||||
fprintf(stderr, "File is not open for writing\n");
|
||||
return 0;
|
||||
}
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + ((table->cur_row-1)*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + ((table->cur_row-1)*2));
|
||||
row_end = mdb_find_end_of_row(mdb, table->cur_row-1);
|
||||
old_row_size = row_end - row_start;
|
||||
|
||||
@@ -443,14 +443,14 @@ int i, pos;
|
||||
#endif
|
||||
new_pg = mdb_new_data_pg(entry);
|
||||
|
||||
num_rows = mdb_get_int16(mdb, fmt->row_count_offset);
|
||||
num_rows = mdb_pg_get_int16(mdb, fmt->row_count_offset);
|
||||
_mdb_put_int16(new_pg, fmt->row_count_offset, num_rows);
|
||||
|
||||
pos = mdb->fmt->pg_size;
|
||||
|
||||
/* rows before */
|
||||
for (i=0;i<row;i++) {
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (i*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (i*2));
|
||||
row_end = mdb_find_end_of_row(mdb, i);
|
||||
row_size = row_end - row_start + 1;
|
||||
pos -= row_size;
|
||||
@@ -465,7 +465,7 @@ int i, pos;
|
||||
|
||||
/* rows after */
|
||||
for (i=row+1;i<num_rows;i++) {
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (i*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (i*2));
|
||||
row_end = mdb_find_end_of_row(mdb, i);
|
||||
row_size = row_end - row_start + 1;
|
||||
pos -= row_size;
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
#include "connectparams.h"
|
||||
|
||||
static char software_version[] = "$Id: odbc.c,v 1.9 2003/01/15 02:02:09 brianb Exp $";
|
||||
static char software_version[] = "$Id: odbc.c,v 1.10 2003/04/29 17:55:20 brianb Exp $";
|
||||
static void *no_unused_var_warn[] = {software_version,
|
||||
no_unused_var_warn};
|
||||
|
||||
@@ -1058,7 +1058,7 @@ int i;
|
||||
}
|
||||
|
||||
strcpy(rgbValue,
|
||||
mdb_col_to_string(mdb, col->cur_value_start, col->col_type,
|
||||
mdb_col_to_string(mdb, mdb->pg_buf, col->cur_value_start, col->col_type,
|
||||
col->cur_value_len));
|
||||
//*((char *)&rgbValue[col->cur_value_len])='\0';
|
||||
*pcbValue = col->cur_value_len;
|
||||
|
@@ -401,9 +401,11 @@ MdbSQLSarg *sql_sarg;
|
||||
g_ptr_array_free(sql->columns,TRUE);
|
||||
g_ptr_array_free(sql->tables,TRUE);
|
||||
g_ptr_array_free(sql->sargs,TRUE);
|
||||
if (sql->mdb) {
|
||||
mdb_close(sql->mdb);
|
||||
mdb_free_handle(sql->mdb);
|
||||
}
|
||||
}
|
||||
void mdb_sql_reset(MdbSQL *sql)
|
||||
{
|
||||
int i;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
bin_PROGRAMS = mdb-export mdb-array mdb-schema mdb-tables mdb-parsecsv mdb-header mdb-sql mdb-ver 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 prtable prcat prdata prkkd prdump prole updrow prindex
|
||||
LIBS = $(GLIB_LIBS) $(READLINE_LIBS) @LEXLIB@
|
||||
DEFS = @DEFS@ -DLOCALEDIR=\"$(localedir)\"
|
||||
INCLUDES = -I$(top_srcdir)/include $(GLIB_CFLAGS)
|
||||
|
@@ -23,7 +23,26 @@
|
||||
#include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
#undef MDB_BIND_SIZE
|
||||
#define MDB_BIND_SIZE 200000
|
||||
|
||||
#define is_text_type(x) (x==MDB_TEXT || x==MDB_MEMO || x==MDB_SDATETIME)
|
||||
void
|
||||
print_col(gchar *col_val, int quote_text, int col_type)
|
||||
{
|
||||
gchar *s;
|
||||
|
||||
if (quote_text && is_text_type(col_type)) {
|
||||
fprintf(stdout,"\"");
|
||||
for (s=col_val;*s;s++) {
|
||||
if (*s=='"') fprintf(stdout,"\"\"");
|
||||
else fprintf(stdout,"%c",*s);
|
||||
}
|
||||
fprintf(stdout,"\"");
|
||||
} else {
|
||||
fprintf(stdout,"%s",col_val);
|
||||
}
|
||||
}
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -38,7 +57,6 @@ char *delimiter = ",";
|
||||
char header_row = 1;
|
||||
char quote_text = 1;
|
||||
int opt;
|
||||
char *s;
|
||||
|
||||
while ((opt=getopt(argc, argv, "HQd:"))!=-1) {
|
||||
switch (opt) {
|
||||
@@ -102,30 +120,25 @@ char *s;
|
||||
}
|
||||
|
||||
while(mdb_fetch_row(table)) {
|
||||
if (quote_text && is_text_type(col->col_type)) {
|
||||
fprintf(stdout,"\"");
|
||||
for (s=bound_values[0];*s;s++) {
|
||||
if (*s=='"') fprintf(stdout,"\"\"");
|
||||
else fprintf(stdout,"%c",*s);
|
||||
}
|
||||
fprintf(stdout,"\"");
|
||||
/* fprintf(stdout,"\"%s\"",bound_values[0]); */
|
||||
} else {
|
||||
fprintf(stdout,"%s",bound_values[0]);
|
||||
col=g_ptr_array_index(table->columns,0);
|
||||
if (col->col_type == MDB_OLE) {
|
||||
mdb_ole_read(mdb, col, bound_values[0], MDB_BIND_SIZE);
|
||||
}
|
||||
|
||||
print_col(bound_values[0],
|
||||
quote_text,
|
||||
col->col_type);
|
||||
|
||||
for (j=1;j<table->num_cols;j++) {
|
||||
col=g_ptr_array_index(table->columns,j);
|
||||
if (quote_text && is_text_type(col->col_type)) {
|
||||
if (col->col_type == MDB_OLE) {
|
||||
if (col->cur_value_len)
|
||||
mdb_ole_read(mdb, col, bound_values[j], MDB_BIND_SIZE);
|
||||
}
|
||||
fprintf(stdout,"%s",delimiter);
|
||||
fprintf(stdout,"\"");
|
||||
for (s=bound_values[j];*s;s++) {
|
||||
if (*s=='"') fprintf(stdout,"\"\"");
|
||||
else fprintf(stdout,"%c",*s);
|
||||
}
|
||||
fprintf(stdout,"\"");
|
||||
} else {
|
||||
fprintf(stdout,"%s%s",delimiter,bound_values[j]);
|
||||
}
|
||||
print_col(bound_values[j],
|
||||
quote_text,
|
||||
col->col_type);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "mdbtools.h"
|
||||
|
||||
int bind_column(MdbTableDef *table, char *colname, unsigned char *data, int *len);
|
||||
void read_to_row(MdbTableDef *table, char *sargname);
|
||||
|
||||
int
|
||||
@@ -90,6 +91,7 @@ MdbColumn *col;
|
||||
printf("column %d\n",found);
|
||||
mdb_bind_column(table, found, data);
|
||||
mdb_bind_len(table, found, len);
|
||||
return 0;
|
||||
}
|
||||
void read_to_row(MdbTableDef *table, char *sargname)
|
||||
{
|
||||
|
Reference in New Issue
Block a user