Added (premilinary) support for null columns.

Added support routines for C files generated by parsecsv utilities.
This commit is contained in:
brianb
2000-03-19 02:50:05 +00:00
parent 5a4f0eefcd
commit 401e3f45e3
5 changed files with 69 additions and 45 deletions

22
src/extras/mdbsupport.c Normal file
View File

@@ -0,0 +1,22 @@
/* support routines for code generated by the util programs */
#include "util.h"
#include <stdio.h>
void dump_int (int i)
{
fprintf (stdout, ">>%d<<\n", i);
}
void dump_long (long l)
{
fprintf (stdout, ">>%ld<<\n", l);
}
void dump_string (char *s)
{
if ((s == NULL) || (strlen (s) == 0))
fprintf (stdout, "(null)\n");
else
fprintf (stdout, ">>%s<<\n", s);
}

4
src/extras/mdbsupport.h Normal file
View File

@@ -0,0 +1,4 @@
void dump_int (int i);
void dump_long (long l);
void dump_string (char *s);

View File

@@ -43,11 +43,35 @@ int rows, row_end;
return row_end; return row_end;
} }
int mdb_read_row(MdbTableDef *table, int pg_num, int row) static int mdb_is_null(unsigned char *null_mask, int col_num)
{
int byte_num = (col_num - 1) / 8;
int bit_num = (col_num - 1) % 8;
if ((1 << bit_num) & null_mask[byte_num]) {
return 0;
} else {
return 1;
}
}
static int mdb_xfer_bound_data(MdbHandle *mdb, int start, MdbColumn *col, int len)
{
if (col->bind_ptr) {
if (len) {
strcpy(col->bind_ptr,
mdb_col_to_string(mdb, start, col->col_type, len));
return col->col_size;
} else {
strcpy(col->bind_ptr, "");
}
}
return 0;
}
int mdb_read_row(MdbTableDef *table, int row)
{ {
MdbHandle *mdb = table->entry->mdb; MdbHandle *mdb = table->entry->mdb;
MdbColumn *col; MdbColumn *col;
int j; int i, j;
int num_cols, var_cols, fixed_cols; 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;
@@ -55,6 +79,7 @@ int col_start, len;
int eod; /* end of data */ int eod; /* end of data */
int delflag, lookupflag; int delflag, lookupflag;
int bitmask_sz; int bitmask_sz;
unsigned char null_mask[8]; /* 256 columns max / 8 bits per byte */
row_start = mdb_get_int16(mdb, 10+(row*2)); row_start = mdb_get_int16(mdb, 10+(row*2));
row_end = mdb_find_end_of_row(mdb, row); row_end = mdb_find_end_of_row(mdb, row);
@@ -64,8 +89,8 @@ int bitmask_sz;
if (row_start & 0x4000) lookupflag++; if (row_start & 0x4000) lookupflag++;
row_start &= 0x0FFF; /* remove flags */ row_start &= 0x0FFF; /* remove flags */
#if DEBUG #if DEBUG
fprintf(stdout,"Pg %d Row %d bytes %d to %d %s %s\n", fprintf(stdout,"Row %d bytes %d to %d %s %s\n",
pg_num, row, row_start, row_end, row, row_start, row_end,
lookupflag ? "[lookup]" : "", lookupflag ? "[lookup]" : "",
delflag ? "[delflag]" : ""); delflag ? "[delflag]" : "");
#endif #endif
@@ -91,6 +116,9 @@ int bitmask_sz;
} }
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]; eod = mdb->pg_buf[row_end-1-var_cols-bitmask_sz];
for (i=0;i<bitmask_sz;i++) {
null_mask[i]=mdb->pg_buf[row_end - bitmask_sz + i + 1];
}
#if MDB_DEBUG #if MDB_DEBUG
fprintf(stdout,"#cols: %-3d #varcols %-3d EOD %-3d\n", fprintf(stdout,"#cols: %-3d #varcols %-3d EOD %-3d\n",
@@ -107,22 +135,11 @@ int bitmask_sz;
col = g_ptr_array_index(table->columns,j); col = g_ptr_array_index(table->columns,j);
if (mdb_is_fixed_col(col) && if (mdb_is_fixed_col(col) &&
++fixed_cols_found <= fixed_cols) { ++fixed_cols_found <= fixed_cols) {
if (col->bind_ptr) { if (mdb_is_null(null_mask, j+1)) {
strcpy(col->bind_ptr, mdb_xfer_bound_data(mdb, 0, col, 0);
mdb_col_to_string(mdb, } else {
row_start + col_start, mdb_xfer_bound_data(mdb,row_start + col_start, col, col->col_size);
col->col_type,
col->col_size)
);
} }
#if MDB_DEBUG
fprintf(stdout,"fixed col %s = %s\n",
col->name,
mdb_col_to_string(mdb,
row_start + col_start,
col->col_type,
0));
#endif
col_start += col->col_size; col_start += col->col_size;
} }
} }
@@ -142,29 +159,11 @@ int bitmask_sz;
- var_cols_found - var_cols_found
- 1 ] - col_start; - 1 ] - col_start;
#if MDB_DEBUG if (mdb_is_null(null_mask, j+1)) {
fprintf(stdout,"coltype %d colstart %d len %d\n", mdb_xfer_bound_data(mdb, 0, col, 0);
col->col_type, } else {
col_start, mdb_xfer_bound_data(mdb,row_start + col_start, col, len);
len);
#endif
if (col->bind_ptr) {
strcpy(col->bind_ptr,
mdb_col_to_string(mdb,
row_start + col_start,
col->col_type,
len)
);
} }
#if MDB_DEBUG
fprintf(stdout,"var col %s = %s\n",
col->name,
mdb_col_to_string(mdb,
row_start + col_start,
col->col_type,
len));
#endif
col_start += len; col_start += len;
} }
} }
@@ -201,7 +200,6 @@ int rows;
rows = mdb_get_int16(mdb,8); rows = mdb_get_int16(mdb,8);
mdb_read_row(table, mdb_read_row(table,
table->cur_pg_num,
table->cur_row); table->cur_row);
table->cur_row++; table->cur_row++;
@@ -236,7 +234,7 @@ char *bound_values[256]; /* warning doesn't handle tables > 256 columns. Can th
pg_num + table->first_data_pg, pg_num + table->first_data_pg,
rows); rows);
for (i=0;i<rows;i++) { for (i=0;i<rows;i++) {
mdb_read_row(table, table->first_data_pg + pg_num, i); mdb_read_row(table, i);
for (j=0;j<table->num_cols;j++) { for (j=0;j<table->num_cols;j++) {
fprintf(stdout, "column %d is %s\n", j+1, bound_values[j]); fprintf(stdout, "column %d is %s\n", j+1, bound_values[j]);
} }

View File

@@ -77,7 +77,7 @@ main (int argc, char **argv)
fprintf (cfile, "\n"); fprintf (cfile, "\n");
fprintf (cfile, "#include <stdio.h>\n"); fprintf (cfile, "#include <stdio.h>\n");
fprintf (cfile, "#include \"types.h\"\n"); fprintf (cfile, "#include \"types.h\"\n");
fprintf (cfile, "#include \"dump.h\"\n"); fprintf (cfile, "#include \"mdbsupport.h\"\n");
fprintf (cfile, "\n"); fprintf (cfile, "\n");
fprintf (cfile, "const %s %s_array [] = {\n", argv [1], argv [1]); fprintf (cfile, "const %s %s_array [] = {\n", argv [1], argv [1]);