remove jumps from column start calculation for JET4

adding -1 and -d flags to mdb-tables
added table not found message to prtable
This commit is contained in:
brianb
2002-04-21 03:09:26 +00:00
parent e7927f94bc
commit 695cc9c00a
4 changed files with 70 additions and 47 deletions

View File

@@ -145,7 +145,7 @@ unsigned char isnull;
if (row_start & 0x8000) lookupflag++; if (row_start & 0x8000) lookupflag++;
if (row_start & 0x4000) delflag++; if (row_start & 0x4000) delflag++;
row_start &= 0x0FFF; /* remove flags */ row_start &= 0x0FFF; /* remove flags */
#if DEBUG #if MDB_DEBUG
fprintf(stdout,"Row %d bytes %d to %d %s %s\n", fprintf(stdout,"Row %d bytes %d to %d %s %s\n",
row, row_start, row_end, row, row_start, row_end,
lookupflag ? "[lookup]" : "", lookupflag ? "[lookup]" : "",
@@ -231,7 +231,7 @@ unsigned char isnull;
num_of_jumps++; num_of_jumps++;
} }
if (mdb->jet_version==MDB_VER_JET4) { if (mdb->jet_version==MDB_VER_JET4) {
col_ptr = row_end - 2 - bitmask_sz - num_of_jumps - 1; col_ptr = row_end - 2 - bitmask_sz - 1;
eod = mdb_get_int16(mdb, col_ptr - var_cols*2); eod = mdb_get_int16(mdb, col_ptr - var_cols*2);
col_start = mdb_get_int16(mdb, col_ptr); col_start = mdb_get_int16(mdb, col_ptr);
} else { } else {
@@ -244,6 +244,10 @@ unsigned char isnull;
col_start = mdb->pg_buf[col_ptr]; col_start = mdb->pg_buf[col_ptr];
} }
#if MDB_DEBUG
fprintf(stdout,"col_start %d num_of_jumps %d\n",
col_start, num_of_jumps);
#endif
/* variable columns */ /* variable columns */
for (j=0;j<table->num_cols;j++) { for (j=0;j<table->num_cols;j++) {
@@ -277,7 +281,9 @@ unsigned char isnull;
} }
isnull = mdb_is_null(null_mask, j+1); isnull = mdb_is_null(null_mask, j+1);
//printf("binding len %d isnull %d col_start %d row_start %d row_end %d bitmask %d var_cols_found %d buf %d\n", len, isnull,col_start,row_start,row_end, bitmask_sz, var_cols_found, mdb->pg_buf[row_end - bitmask_sz - var_cols_found * 2 - 1 - num_of_jumps ]); #if MDB_DEBUG
printf("binding len %d isnull %d col_start %d row_start %d row_end %d bitmask %d var_cols_found %d buf %d\n", len, isnull,col_start,row_start,row_end, bitmask_sz, var_cols_found, mdb->pg_buf[row_end - bitmask_sz - var_cols_found * 2 - 1 - num_of_jumps ]);
#endif
rc = _mdb_attempt_bind(mdb, col, isnull, rc = _mdb_attempt_bind(mdb, col, isnull,
row_start + col_start, len); row_start + col_start, len);
if (!rc) return 0; if (!rc) return 0;

View File

@@ -20,6 +20,7 @@
#include "mdbtools.h" #include "mdbtools.h"
#define is_text_type(x) (x==MDB_TEXT || x==MDB_MEMO || x==MDB_SDATETIME)
main(int argc, char **argv) main(int argc, char **argv)
{ {
int rows; int rows;
@@ -98,13 +99,14 @@ int opt;
} }
while(mdb_fetch_row(table)) { while(mdb_fetch_row(table)) {
if (quote_text && is_text_type(col->col_type)) {
fprintf(stdout,"\"%s\"",bound_values[0]);
} else {
fprintf(stdout,"%s",bound_values[0]); fprintf(stdout,"%s",bound_values[0]);
}
for (j=1;j<table->num_cols;j++) { for (j=1;j<table->num_cols;j++) {
col=g_ptr_array_index(table->columns,j); col=g_ptr_array_index(table->columns,j);
if (quote_text && if (quote_text && is_text_type(col->col_type)) {
(col->col_type==MDB_TEXT ||
col->col_type==MDB_MEMO ||
col->col_type==MDB_SDATETIME)) {
fprintf(stdout,"%s\"%s\"",delimiter,bound_values[j]); fprintf(stdout,"%s\"%s\"",delimiter,bound_values[j]);
} else { } else {
fprintf(stdout,"%s%s",delimiter,bound_values[j]); fprintf(stdout,"%s%s",delimiter,bound_values[j]);

View File

@@ -27,50 +27,60 @@ MdbHandle *mdb;
MdbCatalogEntry *entry; MdbCatalogEntry *entry;
MdbTableDef *table; MdbTableDef *table;
MdbColumn *col; MdbColumn *col;
char *delimiter = NULL;
int line_break=0;
int opt;
if (argc < 2) { if (argc < 2) {
fprintf (stderr, "Usage: %s <file>\n",argv[0]); fprintf (stderr, "Usage: %s [-1 | -d<delimiter>] <file>\n",argv[0]);
exit (1); exit (1);
} }
while ((opt=getopt(argc, argv, "1d:"))!=-1) {
switch (opt) {
case '1':
line_break = 1;
break;
case 'd':
delimiter = (char *) malloc(strlen(optarg)+1);
strcpy(delimiter, optarg);
break;
}
}
/* initialize the library */ /* initialize the library */
mdb_init(); mdb_init();
/* open the database */ /* open the database */
mdb = mdb_open (argv[optind]);
mdb = mdb_open (argv[1]);
/* read the catalog */ /* read the catalog */
mdb_read_catalog (mdb, MDB_TABLE); mdb_read_catalog (mdb, MDB_TABLE);
/* loop over each entry in the catalog */ /* loop over each entry in the catalog */
for (i=0; i < mdb->num_catalog; i++) {
for (i=0; i < mdb->num_catalog; i++)
{
entry = g_ptr_array_index (mdb->catalog, i); entry = g_ptr_array_index (mdb->catalog, i);
/* if it's a table */ /* if it's a table */
if (entry->object_type == MDB_TABLE) {
if (entry->object_type == MDB_TABLE)
{
/* skip the MSys tables */ /* skip the MSys tables */
if (strncmp (entry->object_name, "MSys", 4)) if (strncmp (entry->object_name, "MSys", 4)) {
{ if (line_break)
fprintf (stdout, "%s\n", entry->object_name);
/* make sure it's a table (may be redundant) */ else if (delimiter)
fprintf (stdout, "%s%s", entry->object_name, delimiter);
if (!strcmp (mdb_get_objtype_string (entry->object_type), "Table")) else
{
/* drop the table if it exists */
fprintf (stdout, "%s ", entry->object_name); fprintf (stdout, "%s ", entry->object_name);
} }
} }
} }
} if (!line_break)
fprintf (stdout, "\n"); fprintf (stdout, "\n");
mdb_free_handle (mdb); mdb_free_handle (mdb);
mdb_exit(); mdb_exit();
if (delimiter) free(delimiter);
} }

View File

@@ -28,6 +28,7 @@ unsigned char buf[2048];
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry *entry; MdbCatalogEntry *entry;
GList *l; GList *l;
int found = 0;
if (argc<3) { if (argc<3) {
@@ -45,9 +46,13 @@ GList *l;
if (entry->object_type == MDB_TABLE && if (entry->object_type == MDB_TABLE &&
!strcmp(entry->object_name,argv[2])) { !strcmp(entry->object_name,argv[2])) {
mdb_table_dump(entry); mdb_table_dump(entry);
found++;
} }
} }
if (!found) {
fprintf(stderr,"No table named %s found.\n", argv[2]);
}
mdb_free_handle(mdb); mdb_free_handle(mdb);
mdb_exit(); mdb_exit();
} }