support for memo types (inline only)

text required fields
corrections to bitmask sizing.
moved references to page size to MdbHandle->pg_size
This commit is contained in:
brianb
2000-03-16 02:16:35 +00:00
parent 62e65cdd26
commit 9551d017a8
6 changed files with 37 additions and 19 deletions

View File

@@ -32,6 +32,7 @@
#define MDB_PGSIZE 2048
#define MDB_MAX_OBJ_NAME 30
#define MDB_CATALOG_PG 18
#define MDB_MEMO_OVERHEAD 12
enum {
MDB_FORM = 0,
@@ -71,6 +72,7 @@ typedef struct {
unsigned char pg_buf[MDB_PGSIZE];
int num_catalog;
GArray *catalog;
int pg_size;
} MdbHandle;
typedef struct {
@@ -107,6 +109,7 @@ typedef struct {
int col_size;
void *bind_ptr;
GHashTable *properties;
unsigned char is_fixed;
} MdbColumn;
/* mem.c */

View File

@@ -37,7 +37,7 @@ int rows, row_end;
rows = mdb_get_int16(mdb,8);
if (row==0)
row_end=2047; /* end of page */
row_end = mdb->pg_size - 1; /* end of page */
else
row_end = mdb_get_int16(mdb, (10 + (row-1) * 2)) - 1;
@@ -89,7 +89,7 @@ int bitmask_sz;
else
var_cols++;
}
bitmask_sz = (num_cols - 1) / 8 - 1;
bitmask_sz = (num_cols - 1) / 8 + 1;
eod = mdb->pg_buf[row_end-1-var_cols-bitmask_sz];
#if MDB_DEBUG
@@ -132,12 +132,15 @@ int bitmask_sz;
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-1-var_cols_found];
col_start = mdb->pg_buf[row_end-bitmask_sz-var_cols_found];
if (var_cols_found==var_cols)
len=eod - col_start;
else
len=mdb->pg_buf[row_end-1-var_cols_found-1] - col_start;
len=mdb->pg_buf[row_end
- bitmask_sz
- var_cols_found
- 1 ] - col_start;
#if MDB_DEBUG
fprintf(stdout,"coltype %d colstart %d len %d\n",
@@ -242,11 +245,7 @@ char *bound_values[256]; /* warning doesn't handle tables > 256 columns. Can th
int mdb_is_fixed_col(MdbColumn *col)
{
/* FIX ME -- not complete */
if (col->col_type==MDB_TEXT)
return FALSE;
else
return TRUE;
return col->is_fixed;
}
char *mdb_col_to_string(MdbHandle *mdb, int start, int datatype, int size)
{
@@ -272,6 +271,14 @@ static char text[256];
strncpy(text, &mdb->pg_buf[start], size);
text[size]='\0';
return text;
case MDB_MEMO:
if (size<MDB_MEMO_OVERHEAD) {
return "(oops)";
}
strncpy(text, &mdb->pg_buf[start + MDB_MEMO_OVERHEAD],
size - MDB_MEMO_OVERHEAD);
text[size - MDB_MEMO_OVERHEAD]='\0';
return text;
break;
}
return NULL;

View File

@@ -42,8 +42,8 @@ MdbHandle *mdb;
size_t mdb_read_pg(MdbHandle *mdb, unsigned long pg)
{
size_t len;
off_t offset = pg * MDB_PGSIZE;
struct stat status;
off_t offset = pg * mdb->pg_size;
fstat(mdb->fd, &status);
if (status.st_size < offset) {
@@ -51,12 +51,12 @@ struct stat status;
return 0;
}
lseek(mdb->fd, offset, SEEK_SET);
len = read(mdb->fd,mdb->pg_buf,MDB_PGSIZE);
len = read(mdb->fd,mdb->pg_buf,mdb->pg_size);
if (len==-1) {
perror("read");
return 0;
}
else if (len<MDB_PGSIZE) {
else if (len<mdb->pg_size) {
/* fprintf(stderr,"EOF reached.\n"); */
return 0;
}
@@ -69,7 +69,7 @@ int mdb_get_int16(MdbHandle *mdb, int offset)
unsigned char *c;
int i;
if (offset < 0 || offset+2 > MDB_PGSIZE) return -1;
if (offset < 0 || offset+2 > mdb->pg_size) return -1;
c = &mdb->pg_buf[offset];
i = c[1]*256+c[0];
@@ -82,7 +82,7 @@ long mdb_get_int32(MdbHandle *mdb, int offset)
long l;
unsigned char *c;
if (offset <0 || offset+4 > MDB_PGSIZE) return -1;
if (offset <0 || offset+4 > mdb->pg_size) return -1;
c = &mdb->pg_buf[offset];
l =c[3]; l<<=8;
l+=c[2]; l<<=8;
@@ -94,7 +94,7 @@ unsigned char *c;
}
int mdb_set_pos(MdbHandle *mdb, int pos)
{
if (pos<0 || pos >= MDB_PGSIZE) return 0;
if (pos<0 || pos >= mdb->pg_size) return 0;
mdb->cur_pos=pos;
return pos;

View File

@@ -116,12 +116,12 @@ int rowid = entry->kkd_rowid;
fprintf(stdout,"number of rows = %d\n",rows);
kkd_start = mdb_get_int16(mdb,10+rowid*2);
fprintf(stdout,"kkd start = %d %04x\n",kkd_start,kkd_start);
kkd_end = MDB_PGSIZE;
kkd_end = mdb->pg_size;
for (i=0;i<rows;i++) {
tmp = mdb_get_int16(mdb, 10+i*2);
if (tmp<MDB_PGSIZE &&
tmp>kkd_start &&
tmp<kkd_end) {
if (tmp < mdb->pg_size &&
tmp > kkd_start &&
tmp < kkd_end) {
kkd_end = tmp;
}
}

View File

@@ -25,6 +25,7 @@ MdbHandle *mdb;
mdb = (MdbHandle *) malloc(sizeof(MdbHandle));
memset(mdb, '\0', sizeof(MdbHandle));
mdb->pg_size = MDB_PGSIZE;
return mdb;
}

View File

@@ -103,6 +103,13 @@ int name_sz;
memset(&col,'\0', sizeof(MdbColumn));
col.col_type = mdb->pg_buf[cur_col];
if (col.col_type == MDB_TEXT) {
col.is_fixed = mdb->pg_buf[cur_col+3];
} else if (col.col_type == MDB_MEMO) {
col.is_fixed = 0;
} else {
col.is_fixed = 1;
}
col.col_size = mdb_get_int16(mdb,cur_col+16);
/* get the name */
name_sz = mdb->pg_buf[cur_name];