Georg fixed endian issue, added support for MDB_BOOL

I (Brian) reorged data.c, added AUTHORS file
This commit is contained in:
brianb
2000-03-11 22:37:10 +00:00
parent 282902b6e3
commit 48d80d3de8
3 changed files with 120 additions and 61 deletions

3
AUTHORS Normal file
View File

@@ -0,0 +1,3 @@
Brian Bruns <camber@ais.org>
Karl Nyberg <karl@grebyn.com>
Georg Bauer <gb@hugo.westfalen.de>

View File

@@ -48,6 +48,7 @@ enum {
MDB_UNKNOWN_0B MDB_UNKNOWN_0B
}; };
enum { enum {
MDB_BOOL = 0x01,
MDB_INT = 0x03, MDB_INT = 0x03,
MDB_LONGINT = 0x04, MDB_LONGINT = 0x04,
MDB_SDATETIME = 0x08, MDB_SDATETIME = 0x08,
@@ -96,6 +97,7 @@ typedef struct {
char name[MDB_MAX_OBJ_NAME+1]; char name[MDB_MAX_OBJ_NAME+1];
int col_type; int col_type;
int col_size; int col_size;
void *bind_ptr;
GHashTable *properties; GHashTable *properties;
} MdbColumn; } MdbColumn;

View File

@@ -19,42 +19,53 @@
#include "mdbtools.h" #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; MdbHandle *mdb = table->entry->mdb;
int i, j, pg_num; MdbColumn col;
int rows, num_cols, var_cols, fixed_cols; int j;
int num_cols, var_cols, fixed_cols;
int row_start, row_end; int row_start, row_end;
int fixed_cols_found, var_cols_found; int fixed_cols_found, var_cols_found;
int col_start, len; int col_start, len;
int eod; /* end of data */ int eod; /* end of data */
int delflag, lookupflag; int delflag, lookupflag;
for (pg_num=1;pg_num<=table->num_pgs;pg_num++) { row_start = mdb_get_int16(mdb, 10+(row*2));
mdb_read_pg(mdb,table->first_data_pg + pg_num); row_end = mdb_find_end_of_row(mdb, row);
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; delflag = lookupflag = 0;
if (row_start & 0x8000) delflag++; if (row_start & 0x8000) delflag++;
if (row_start & 0x4000) lookupflag++; if (row_start & 0x4000) lookupflag++;
row_start &= 0x0FFF; /* remove flags */ row_start &= 0x0FFF; /* remove flags */
fprintf(stdout,"Pg %d Row %d bytes %d to %d %s %s\n", fprintf(stdout,"Pg %d Row %d bytes %d to %d %s %s\n",
pg_num, i, row_start, row_end, pg_num, row, row_start, row_end,
lookupflag ? "[lookup]" : "", lookupflag ? "[lookup]" : "",
delflag ? "[delflag]" : ""); delflag ? "[delflag]" : "");
if (delflag || lookupflag) { if (delflag || lookupflag) {
row_end = row_start-1; row_end = row_start-1;
continue; return 0;
} }
buffer_dump(mdb->pg_buf, row_start, row_end); buffer_dump(mdb->pg_buf, row_start, row_end);
num_cols = mdb->pg_buf[row_start]; num_cols = mdb->pg_buf[row_start];
@@ -62,35 +73,72 @@ int delflag, lookupflag;
fixed_cols = num_cols - var_cols; fixed_cols = num_cols - var_cols;
eod = mdb->pg_buf[row_end-2-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); fprintf(stdout,"#cols: %-3d #varcols %-3d EOD %-3d\n",
num_cols, var_cols, eod);
col_start = 1; col_start = 1;
fixed_cols_found = 0; fixed_cols_found = 0;
var_cols_found = 0; var_cols_found = 0;
/* fixed columns */
for (j=0;j<table->num_cols;j++) { for (j=0;j<table->num_cols;j++) {
col = g_array_index(table->columns,MdbColumn,j); col = g_array_index(table->columns,MdbColumn,j);
if (mdb_is_fixed_col(&col) && if (mdb_is_fixed_col(&col) &&
++fixed_cols_found <= fixed_cols) { ++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)); 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; col_start += col.col_size;
} }
} }
/* variable columns */
for (j=0;j<table->num_cols;j++) { for (j=0;j<table->num_cols;j++) {
col = g_array_index(table->columns,MdbColumn,j); col = g_array_index(table->columns,MdbColumn,j);
if (!mdb_is_fixed_col(&col) && if (!mdb_is_fixed_col(&col) &&
++var_cols_found <= var_cols) { ++var_cols_found <= var_cols) {
col_start = mdb->pg_buf[row_end-1-var_cols_found]; col_start = mdb->pg_buf[row_end-1-var_cols_found];
if (var_cols_found==var_cols) if (var_cols_found==var_cols)
len=eod - col_start; len=eod - col_start;
else else
len=col_start - mdb->pg_buf[row_end-1-var_cols_found-1]; 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)); 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; col_start += len;
} }
} }
row_end = row_start-1; 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);
for (i=0;i<rows;i++) {
mdb_read_row(table, table->first_data_pg + pg_num, i);
}
} }
} }
@@ -102,22 +150,28 @@ int mdb_is_fixed_col(MdbColumn *col)
else else
return TRUE; 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]; static char text[256];
switch (datatype) { switch (datatype) {
case MDB_BOOL:
sprintf(text,"%d", mdb->pg_buf[start]);
return text;
break;
case MDB_INT: case MDB_INT:
sprintf(text,"%ld",*((gint16 *)buf)); sprintf(text,"%ld",mdb_get_int16(mdb, start));
return "test"; return text;
break; break;
case MDB_LONGINT: case MDB_LONGINT:
sprintf(text,"%ld",*((gint32 *)buf)); sprintf(text,"%ld",mdb_get_int32(mdb, start));
return text; return text;
break; break;
case MDB_TEXT: case MDB_TEXT:
strncpy(text, buf, size); if (size<0) {
return "(oops)";
}
strncpy(text, &mdb->pg_buf[start], size);
text[size]='\0'; text[size]='\0';
return text; return text;
break; break;