mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
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:
parent
e7927f94bc
commit
695cc9c00a
@ -145,7 +145,7 @@ unsigned char isnull;
|
||||
if (row_start & 0x8000) lookupflag++;
|
||||
if (row_start & 0x4000) delflag++;
|
||||
row_start &= 0x0FFF; /* remove flags */
|
||||
#if DEBUG
|
||||
#if MDB_DEBUG
|
||||
fprintf(stdout,"Row %d bytes %d to %d %s %s\n",
|
||||
row, row_start, row_end,
|
||||
lookupflag ? "[lookup]" : "",
|
||||
@ -231,7 +231,7 @@ unsigned char isnull;
|
||||
num_of_jumps++;
|
||||
}
|
||||
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);
|
||||
col_start = mdb_get_int16(mdb, col_ptr);
|
||||
} else {
|
||||
@ -244,6 +244,10 @@ unsigned char isnull;
|
||||
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 */
|
||||
for (j=0;j<table->num_cols;j++) {
|
||||
@ -277,7 +281,9 @@ unsigned char isnull;
|
||||
}
|
||||
|
||||
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,
|
||||
row_start + col_start, len);
|
||||
if (!rc) return 0;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "mdbtools.h"
|
||||
|
||||
#define is_text_type(x) (x==MDB_TEXT || x==MDB_MEMO || x==MDB_SDATETIME)
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int rows;
|
||||
@ -98,13 +99,14 @@ int opt;
|
||||
}
|
||||
|
||||
while(mdb_fetch_row(table)) {
|
||||
fprintf(stdout,"%s",bound_values[0]);
|
||||
for (j=1;j<table->num_cols;j++) {
|
||||
if (quote_text && is_text_type(col->col_type)) {
|
||||
fprintf(stdout,"\"%s\"",bound_values[0]);
|
||||
} else {
|
||||
fprintf(stdout,"%s",bound_values[0]);
|
||||
}
|
||||
for (j=1;j<table->num_cols;j++) {
|
||||
col=g_ptr_array_index(table->columns,j);
|
||||
if (quote_text &&
|
||||
(col->col_type==MDB_TEXT ||
|
||||
col->col_type==MDB_MEMO ||
|
||||
col->col_type==MDB_SDATETIME)) {
|
||||
if (quote_text && is_text_type(col->col_type)) {
|
||||
fprintf(stdout,"%s\"%s\"",delimiter,bound_values[j]);
|
||||
} else {
|
||||
fprintf(stdout,"%s%s",delimiter,bound_values[j]);
|
||||
|
@ -27,50 +27,60 @@ MdbHandle *mdb;
|
||||
MdbCatalogEntry *entry;
|
||||
MdbTableDef *table;
|
||||
MdbColumn *col;
|
||||
char *delimiter = NULL;
|
||||
int line_break=0;
|
||||
int opt;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf (stderr, "Usage: %s [-1 | -d<delimiter>] <file>\n",argv[0]);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf (stderr, "Usage: %s <file>\n",argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* initialize the library */
|
||||
mdb_init();
|
||||
/* initialize the library */
|
||||
mdb_init();
|
||||
|
||||
/* open the database */
|
||||
/* open the database */
|
||||
mdb = mdb_open (argv[optind]);
|
||||
|
||||
mdb = mdb_open (argv[1]);
|
||||
/* read the catalog */
|
||||
mdb_read_catalog (mdb, MDB_TABLE);
|
||||
|
||||
/* read the catalog */
|
||||
/* loop over each entry in the catalog */
|
||||
for (i=0; i < mdb->num_catalog; i++) {
|
||||
entry = g_ptr_array_index (mdb->catalog, i);
|
||||
|
||||
/* if it's a table */
|
||||
if (entry->object_type == MDB_TABLE) {
|
||||
/* skip the MSys tables */
|
||||
if (strncmp (entry->object_name, "MSys", 4)) {
|
||||
if (line_break)
|
||||
fprintf (stdout, "%s\n", entry->object_name);
|
||||
else if (delimiter)
|
||||
fprintf (stdout, "%s%s", entry->object_name, delimiter);
|
||||
else
|
||||
fprintf (stdout, "%s ", entry->object_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!line_break)
|
||||
fprintf (stdout, "\n");
|
||||
|
||||
mdb_read_catalog (mdb, MDB_TABLE);
|
||||
mdb_free_handle (mdb);
|
||||
mdb_exit();
|
||||
if (delimiter) free(delimiter);
|
||||
|
||||
/* loop over each entry in the catalog */
|
||||
|
||||
for (i=0; i < mdb->num_catalog; i++)
|
||||
{
|
||||
entry = g_ptr_array_index (mdb->catalog, i);
|
||||
|
||||
/* if it's a table */
|
||||
|
||||
if (entry->object_type == MDB_TABLE)
|
||||
{
|
||||
/* skip the MSys tables */
|
||||
if (strncmp (entry->object_name, "MSys", 4))
|
||||
{
|
||||
|
||||
/* make sure it's a table (may be redundant) */
|
||||
|
||||
if (!strcmp (mdb_get_objtype_string (entry->object_type), "Table"))
|
||||
{
|
||||
/* drop the table if it exists */
|
||||
fprintf (stdout, "%s ", entry->object_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fprintf (stdout, "\n");
|
||||
|
||||
mdb_free_handle (mdb);
|
||||
mdb_exit();
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ unsigned char buf[2048];
|
||||
MdbHandle *mdb;
|
||||
MdbCatalogEntry *entry;
|
||||
GList *l;
|
||||
int found = 0;
|
||||
|
||||
|
||||
if (argc<3) {
|
||||
@ -45,9 +46,13 @@ GList *l;
|
||||
if (entry->object_type == MDB_TABLE &&
|
||||
!strcmp(entry->object_name,argv[2])) {
|
||||
mdb_table_dump(entry);
|
||||
found++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
fprintf(stderr,"No table named %s found.\n", argv[2]);
|
||||
}
|
||||
mdb_free_handle(mdb);
|
||||
mdb_exit();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user