> 255 column patches and multipage table defs from Tim Nelson

mdb-export fixes
spec file
This commit is contained in:
brianb
2000-10-13 21:33:04 +00:00
parent 9a00f0eb2a
commit fb576534d8
9 changed files with 229 additions and 52 deletions

View File

@@ -99,7 +99,7 @@ char *mdb_postgres_types[] =
"Postgres_Unknown 0x0e",
"Serial"};
char *bound_values[256];
char *bound_values[MDB_MAX_COLS];
char *relationships[4];
MdbColumn *col;
MdbCatalogEntry entry;

View File

@@ -35,21 +35,22 @@ int mdb_find_end_of_row(MdbHandle *mdb, int row)
{
int row_start, row_end, i;
/* Search the previous "row start" values for the first non-deleted one.
* If we don't find one, then the end of the page is the correct value.
*/
for (i = row - 1; i >= 0; i--) {
row_start = mdb_get_int16(mdb, (10 + i * 2));
if (!(row_start & 0x8000)) {
break;
}
}
/* Search the previous "row start" values for the first non-deleted
one.
* If we don't find one, then the end of the page is the correct value.
*/
for (i = row - 1; i >= 0; i--) {
row_start = mdb_get_int16(mdb, (10 + i * 2));
if (!(row_start & 0x8000)) {
break;
}
}
if (i == -1) {
row_end = mdb->pg_size - 1;
} else {
row_end = row_start - 1;
}
if (i == -1) {
row_end = mdb->pg_size - 1;
} else {
row_end = row_start - 1;
}
return row_end;
}
@@ -86,6 +87,7 @@ int num_cols, var_cols, fixed_cols;
int row_start, row_end;
int fixed_cols_found, var_cols_found;
int col_start, len;
int num_of_jumps=0, jumps_used=0;
int eod; /* end of data */
int delflag, lookupflag;
int bitmask_sz;
@@ -105,7 +107,8 @@ unsigned char null_mask[33]; /* 256 columns max / 8 bits per byte */
delflag ? "[delflag]" : "");
#endif
if (delflag || lookupflag) {
return -1;
row_end = row_start-1;
return 0;
}
#if MDB_DEBUG
@@ -153,12 +156,37 @@ unsigned char null_mask[33]; /* 256 columns max / 8 bits per byte */
}
}
if (col_start >= 256) {
num_of_jumps++;
jumps_used++;
row_start = row_start + col_start - (col_start % 256);
}
col_start = row_start;
while (col_start+256 < row_end-bitmask_sz-1-var_cols-num_of_jumps){
col_start += 256;
num_of_jumps++;
}
eod = mdb->pg_buf[row_end-1-var_cols-bitmask_sz-num_of_jumps];
col_start = mdb->pg_buf[row_end-bitmask_sz-1-num_of_jumps];
/* variable columns */
for (j=0;j<table->num_cols;j++) {
col = g_ptr_array_index(table->columns,j);
if (!mdb_is_fixed_col(col) &&
++var_cols_found <= var_cols) {
col_start = mdb->pg_buf[row_end-bitmask_sz-var_cols_found];
/* col_start = mdb->pg_buf[row_end-bitmask_sz-var_cols_found]; */
/* more code goes here but the diff is mangled */
if (var_cols_found == mdb->pg_buf[row_end-bitmask_sz-jumps_used-1] &&
jumps_used < num_of_jumps) {
row_start += 256;
col_start -= 256;
jumps_used++;
}
if (var_cols_found==var_cols)
len=eod - col_start;
@@ -166,7 +194,7 @@ unsigned char null_mask[33]; /* 256 columns max / 8 bits per byte */
len=mdb->pg_buf[row_end
- bitmask_sz
- var_cols_found
- 1 ] - col_start;
- 1 - num_of_jumps ] - col_start;
if (mdb_is_null(null_mask, j+1)) {
mdb_xfer_bound_data(mdb, 0, col, 0);
@@ -177,7 +205,7 @@ unsigned char null_mask[33]; /* 256 columns max / 8 bits per byte */
}
}
return 0;
return 1;
}
int mdb_read_next_dpg(MdbTableDef *table)
{
@@ -219,14 +247,8 @@ int rows;
if (!mdb_read_next_dpg(table)) return 0;
}
/* Skip over any deleted rows.
* mdb_read_row() returns -1 on deleted rows.
* mdb_read_row() returns 0 on actual rows.
*/
while(mdb_read_row(table,
table->cur_row)) {
table->cur_row++;
}
mdb_read_row(table,
table->cur_row);
table->cur_row++;
return 1;
@@ -236,7 +258,7 @@ void mdb_data_dump(MdbTableDef *table)
MdbHandle *mdb = table->entry->mdb;
int i, j, pg_num;
int rows;
char *bound_values[256]; /* warning doesn't handle tables > 256 columns. Can that happen? */
char *bound_values[MDB_MAX_COLS];
for (i=0;i<table->num_cols;i++) {
bound_values[i] = (char *) malloc(256);
@@ -316,6 +338,10 @@ static char text[MDB_BIND_SIZE];
sprintf(text,"%ld",mdb_get_int32(mdb, start));
return text;
break;
case MDB_FLOAT:
sprintf(text,"%f",mdb_get_double(mdb, start));
return text;
break;
case MDB_DOUBLE:
sprintf(text,"%f",mdb_get_double(mdb, start));
return text;

View File

@@ -135,6 +135,27 @@ unsigned char *c;
mdb->cur_pos+=4;
return l;
}
float mdb_get_single(MdbHandle *mdb, int offset)
{
float f, f2;
unsigned char *c;
int i;
if (offset <0 || offset+4 > mdb->pg_size) return -1;
memcpy(&f, &mdb->pg_buf[offset], 4);
#ifdef HW_BIG_ENDIAN
f2 = f;
for (i=0; i<sizeof(f); i++) {
*(((unsigned char *)&f)+i) =
*(((unsigned char *)&f2)+sizeof(f)-1-i);
}
#endif
mdb->cur_pos+=4;
return f;
}
double mdb_get_double(MdbHandle *mdb, int offset)
{
double d, d2;

View File

@@ -48,41 +48,92 @@ int len, i;
return table;
}
/*
** read the next page if offset is > pg_size
** return true if page was read
*/
static int read_pg_if(MdbHandle *mdb, int *cur_pos, int offset)
{
if (*cur_pos + offset >= mdb->pg_size) {
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
*cur_pos = 8 - (mdb->pg_size - (*cur_pos));
return 1;
}
return 0;
}
GPtrArray *mdb_read_columns(MdbTableDef *table)
{
MdbHandle *mdb = table->entry->mdb;
MdbColumn col;
MdbColumn col, *pcol;
int len, i;
unsigned char low_byte, high_byte;
int cur_col, cur_name;
int col_type, col_size;
int col_start, name_start;
char name[MDB_MAX_OBJ_NAME+1];
int name_sz;
table->columns = g_ptr_array_new();
col_start = 43 + (table->num_pgs * 8);
name_start = col_start + (table->num_cols * 18);
cur_col = 43 + (table->num_pgs * 8);
cur_col = col_start;
cur_name = name_start;
/* new code based on patch submitted by Tim Nelson 2000.09.27 */
for (i=0;i<table->num_cols;i++) {
/*
** column attributes
*/
for (i=0; i<table->num_cols;i++) {
memset(&col,'\0', sizeof(MdbColumn));
read_pg_if(mdb, &cur_col, 0);
col.col_type = mdb->pg_buf[cur_col];
col.is_fixed = mdb->pg_buf[cur_col+13] & 0x01 ? 1 : 0;
col.col_size = mdb_get_int16(mdb,cur_col+16);
/* get the name */
name_sz = mdb->pg_buf[cur_name];
memcpy(col.name,&mdb->pg_buf[cur_name+1],name_sz);
col.name[name_sz]='\0';
cur_col += 18;
cur_name += name_sz + 1;
read_pg_if(mdb, &cur_col, 13);
col.is_fixed = mdb->pg_buf[cur_col+13] & 0x01 ? 1 : 0;
read_pg_if(mdb, &cur_col, 17);
low_byte = mdb->pg_buf[cur_col+16];
read_pg_if(mdb, &cur_col, 18);
high_byte = mdb->pg_buf[cur_col+17];
col.col_size += high_byte * 256 + low_byte;
mdb_append_column(table->columns, &col);
cur_col += 18;
}
cur_name = cur_col;
/*
** column names
*/
for (i=0;i<table->num_cols;i++) {
/* fetch the column */
pcol = g_ptr_array_index (table->columns, i);
/* we have reached the end of page */
read_pg_if(mdb, &cur_name, 0);
name_sz = mdb->pg_buf[cur_name];
/* determine amount of name on this page */
len = ((cur_name + name_sz) > mdb->pg_size) ?
mdb->pg_size - cur_name :
name_sz;
if (len) {
memcpy(pcol->name, &mdb->pg_buf[cur_name+1], len);
}
/* name wrapped over page */
if (len < name_sz) {
/* read the next pg */
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
cur_name = 8 - (mdb->pg_size - cur_name);
/* get the rest of the name */
memcpy(&pcol->name[len], &mdb->pg_buf[cur_name], name_sz - len);
}
pcol->name[name_sz]='\0';
cur_name += name_sz + 1;
}
return table->columns;
}