mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-05-16 05:26:49 +08:00
Georg fixed endian issue, added support for MDB_BOOL
I (Brian) reorged data.c, added AUTHORS file
This commit is contained in:
parent
282902b6e3
commit
48d80d3de8
3
AUTHORS
Normal file
3
AUTHORS
Normal file
@ -0,0 +1,3 @@
|
||||
Brian Bruns <camber@ais.org>
|
||||
Karl Nyberg <karl@grebyn.com>
|
||||
Georg Bauer <gb@hugo.westfalen.de>
|
@ -48,6 +48,7 @@ enum {
|
||||
MDB_UNKNOWN_0B
|
||||
};
|
||||
enum {
|
||||
MDB_BOOL = 0x01,
|
||||
MDB_INT = 0x03,
|
||||
MDB_LONGINT = 0x04,
|
||||
MDB_SDATETIME = 0x08,
|
||||
@ -96,6 +97,7 @@ typedef struct {
|
||||
char name[MDB_MAX_OBJ_NAME+1];
|
||||
int col_type;
|
||||
int col_size;
|
||||
void *bind_ptr;
|
||||
GHashTable *properties;
|
||||
} MdbColumn;
|
||||
|
||||
|
@ -19,77 +19,125 @@
|
||||
|
||||
#include "mdbtools.h"
|
||||
|
||||
char *mdb_col_to_string(const char *buf, int datatype, int size);
|
||||
char *mdb_col_to_string(MdbHandle *mdb, int start, int datatype, int size);
|
||||
|
||||
void mdb_data_dump(MdbTableDef *table)
|
||||
void mdb_bind_col(MdbColumn *col, void *bind_ptr)
|
||||
{
|
||||
col->bind_ptr = bind_ptr;
|
||||
}
|
||||
int mdb_find_end_of_row(MdbHandle *mdb, int row)
|
||||
{
|
||||
int rows, row_end;
|
||||
|
||||
rows = mdb_get_int16(mdb,8);
|
||||
if (row==0)
|
||||
row_end=2047; /* end of page */
|
||||
else
|
||||
row_end = mdb_get_int16(mdb, (10 + (row-1) * 2)) - 1;
|
||||
|
||||
return row_end;
|
||||
}
|
||||
int mdb_read_row(MdbTableDef *table, int pg_num, int row)
|
||||
{
|
||||
MdbColumn col;
|
||||
MdbHandle *mdb = table->entry->mdb;
|
||||
int i, j, pg_num;
|
||||
int rows, num_cols, var_cols, fixed_cols;
|
||||
MdbColumn col;
|
||||
int j;
|
||||
int num_cols, var_cols, fixed_cols;
|
||||
int row_start, row_end;
|
||||
int fixed_cols_found, var_cols_found;
|
||||
int col_start, len;
|
||||
int eod; /* end of data */
|
||||
int delflag, lookupflag;
|
||||
|
||||
row_start = mdb_get_int16(mdb, 10+(row*2));
|
||||
row_end = mdb_find_end_of_row(mdb, row);
|
||||
|
||||
delflag = lookupflag = 0;
|
||||
if (row_start & 0x8000) delflag++;
|
||||
if (row_start & 0x4000) lookupflag++;
|
||||
row_start &= 0x0FFF; /* remove flags */
|
||||
fprintf(stdout,"Pg %d Row %d bytes %d to %d %s %s\n",
|
||||
pg_num, row, row_start, row_end,
|
||||
lookupflag ? "[lookup]" : "",
|
||||
delflag ? "[delflag]" : "");
|
||||
|
||||
if (delflag || lookupflag) {
|
||||
row_end = row_start-1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer_dump(mdb->pg_buf, row_start, row_end);
|
||||
|
||||
num_cols = mdb->pg_buf[row_start];
|
||||
var_cols = mdb->pg_buf[row_end-1];
|
||||
fixed_cols = num_cols - var_cols;
|
||||
eod = mdb->pg_buf[row_end-2-var_cols];
|
||||
|
||||
fprintf(stdout,"#cols: %-3d #varcols %-3d EOD %-3d\n",
|
||||
num_cols, var_cols, eod);
|
||||
|
||||
col_start = 1;
|
||||
fixed_cols_found = 0;
|
||||
var_cols_found = 0;
|
||||
|
||||
/* fixed columns */
|
||||
for (j=0;j<table->num_cols;j++) {
|
||||
col = g_array_index(table->columns,MdbColumn,j);
|
||||
if (mdb_is_fixed_col(&col) &&
|
||||
++fixed_cols_found <= fixed_cols) {
|
||||
fprintf(stdout,"fixed col %s = %s\n",
|
||||
col.name,
|
||||
mdb_col_to_string(mdb,
|
||||
row_start + col_start,
|
||||
col.col_type,
|
||||
0));
|
||||
col_start += col.col_size;
|
||||
}
|
||||
}
|
||||
|
||||
/* variable columns */
|
||||
for (j=0;j<table->num_cols;j++) {
|
||||
col = g_array_index(table->columns,MdbColumn,j);
|
||||
if (!mdb_is_fixed_col(&col) &&
|
||||
++var_cols_found <= var_cols) {
|
||||
col_start = mdb->pg_buf[row_end-1-var_cols_found];
|
||||
|
||||
if (var_cols_found==var_cols)
|
||||
len=eod - col_start;
|
||||
else
|
||||
len=col_start - mdb->pg_buf[row_end-1-var_cols_found-1];
|
||||
|
||||
fprintf(stdout,"coltype %d colstart %d len %d\n",
|
||||
col.col_type,
|
||||
col_start,
|
||||
len);
|
||||
fprintf(stdout,"var col %s = %s\n",
|
||||
col.name,
|
||||
mdb_col_to_string(mdb,
|
||||
row_start + col_start,
|
||||
col.col_type,
|
||||
len));
|
||||
col_start += len;
|
||||
}
|
||||
}
|
||||
|
||||
row_end = row_start-1;
|
||||
}
|
||||
|
||||
void mdb_data_dump(MdbTableDef *table)
|
||||
{
|
||||
MdbHandle *mdb = table->entry->mdb;
|
||||
int i, pg_num;
|
||||
int rows;
|
||||
|
||||
for (pg_num=1;pg_num<=table->num_pgs;pg_num++) {
|
||||
mdb_read_pg(mdb,table->first_data_pg + pg_num);
|
||||
rows = mdb_get_int16(mdb,8);
|
||||
fprintf(stdout,"Rows on page %d: %d\n",
|
||||
pg_num + table->first_data_pg,
|
||||
rows);
|
||||
row_end=2047;
|
||||
for (i=0;i<rows;i++) {
|
||||
row_start = mdb_get_int16(mdb,10+i*2);
|
||||
delflag = lookupflag = 0;
|
||||
if (row_start & 0x8000) delflag++;
|
||||
if (row_start & 0x4000) lookupflag++;
|
||||
row_start &= 0x0FFF; /* remove flags */
|
||||
fprintf(stdout,"Pg %d Row %d bytes %d to %d %s %s\n",
|
||||
pg_num, i, row_start, row_end,
|
||||
lookupflag ? "[lookup]" : "",
|
||||
delflag ? "[delflag]" : "");
|
||||
|
||||
if (delflag || lookupflag) {
|
||||
row_end = row_start-1;
|
||||
continue;
|
||||
}
|
||||
buffer_dump(mdb->pg_buf, row_start, row_end);
|
||||
|
||||
num_cols = mdb->pg_buf[row_start];
|
||||
var_cols = mdb->pg_buf[row_end-1];
|
||||
fixed_cols = num_cols - var_cols;
|
||||
eod = mdb->pg_buf[row_end-2-var_cols];
|
||||
|
||||
fprintf(stdout,"#cols: %-3d #varcols %-3d EOD %-3d\n", num_cols, var_cols, eod);
|
||||
|
||||
col_start = 1;
|
||||
fixed_cols_found = 0;
|
||||
var_cols_found = 0;
|
||||
for (j=0;j<table->num_cols;j++) {
|
||||
col = g_array_index(table->columns,MdbColumn,j);
|
||||
if (mdb_is_fixed_col(&col) &&
|
||||
++fixed_cols_found <= fixed_cols) {
|
||||
fprintf(stdout,"fixed col %s = %s\n",col.name,mdb_col_to_string(&mdb->pg_buf[row_start + col_start],col.col_type,0));
|
||||
col_start += col.col_size;
|
||||
}
|
||||
}
|
||||
for (j=0;j<table->num_cols;j++) {
|
||||
col = g_array_index(table->columns,MdbColumn,j);
|
||||
if (!mdb_is_fixed_col(&col) &&
|
||||
++var_cols_found <= var_cols) {
|
||||
col_start = mdb->pg_buf[row_end-1-var_cols_found];
|
||||
if (var_cols_found==var_cols)
|
||||
len=eod - col_start;
|
||||
else
|
||||
len=col_start - mdb->pg_buf[row_end-1-var_cols_found-1];
|
||||
fprintf(stdout,"coltype %d colstart %d len %d\n",col.col_type,col_start, len);
|
||||
fprintf(stdout,"var col %s = %s\n", col.name, mdb_col_to_string(&mdb->pg_buf[row_start + col_start],col.col_type,len));
|
||||
col_start += len;
|
||||
}
|
||||
}
|
||||
row_end = row_start-1;
|
||||
mdb_read_row(table, table->first_data_pg + pg_num, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -102,22 +150,28 @@ int mdb_is_fixed_col(MdbColumn *col)
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
char *mdb_col_to_string(const char *buf, int datatype, int size)
|
||||
char *mdb_col_to_string(MdbHandle *mdb, int start, int datatype, int size)
|
||||
{
|
||||
/* FIX ME -- fix for big endian boxes */
|
||||
static char text[256];
|
||||
|
||||
switch (datatype) {
|
||||
case MDB_BOOL:
|
||||
sprintf(text,"%d", mdb->pg_buf[start]);
|
||||
return text;
|
||||
break;
|
||||
case MDB_INT:
|
||||
sprintf(text,"%ld",*((gint16 *)buf));
|
||||
return "test";
|
||||
sprintf(text,"%ld",mdb_get_int16(mdb, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_LONGINT:
|
||||
sprintf(text,"%ld",*((gint32 *)buf));
|
||||
sprintf(text,"%ld",mdb_get_int32(mdb, start));
|
||||
return text;
|
||||
break;
|
||||
case MDB_TEXT:
|
||||
strncpy(text, buf, size);
|
||||
if (size<0) {
|
||||
return "(oops)";
|
||||
}
|
||||
strncpy(text, &mdb->pg_buf[start], size);
|
||||
text[size]='\0';
|
||||
return text;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user