mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
fix compiler warnings in libmdb/ util/ sql/
This commit is contained in:
parent
244e519c50
commit
278cf8ef42
@ -64,5 +64,11 @@ extern void mdb_sql_listtables(MdbSQL *sql);
|
||||
extern void mdb_sql_select(MdbSQL *sql);
|
||||
extern void mdbsql_bind_all(MdbSQL *sql);
|
||||
extern void mdb_sql_dump_node(MdbSargNode *node, int level);
|
||||
extern void mdb_sql_close(MdbSQL *sql);
|
||||
extern void mdb_sql_add_or(MdbSQL *sql);
|
||||
extern void mdb_sql_add_and(MdbSQL *sql);
|
||||
extern void mdb_sql_listtables(MdbSQL *sql);
|
||||
extern void mdb_sql_add_not(MdbSQL *sql);
|
||||
extern void mdb_sql_describe_table(MdbSQL *sql);
|
||||
|
||||
#endif
|
||||
|
@ -371,12 +371,13 @@ extern gint32 mdb_pg_get_int24(MdbHandle *mdb, int offset);
|
||||
extern long mdb_pg_get_int32(MdbHandle *mdb, int offset);
|
||||
extern float mdb_pg_get_single(MdbHandle *mdb, int offset);
|
||||
extern double mdb_pg_get_double(MdbHandle *mdb, int offset);
|
||||
extern gint32 mdb_pg_get_int24_msb(MdbHandle *mdb, int offset);
|
||||
extern MdbHandle *mdb_open(char *filename);
|
||||
extern MdbHandle *_mdb_open(char *filename, gboolean writable);
|
||||
extern void mdb_close(MdbHandle *mdb);
|
||||
extern MdbHandle *mdb_clone_handle(MdbHandle *mdb);
|
||||
extern void mdb_swap_pgbuf(MdbHandle *mdb);
|
||||
extern long _mdb_get_int32(unsigned char *buf, int offset);
|
||||
extern gint32 mdb_get_int24_msb(MdbHandle *mdb, int offset);
|
||||
extern void mdb_free_tabledef(MdbTableDef *table);
|
||||
|
||||
/* catalog.c */
|
||||
@ -391,6 +392,11 @@ extern void mdb_dump_catalog(MdbHandle *mdb, int obj_type);
|
||||
extern MdbTableDef *mdb_read_table(MdbCatalogEntry *entry);
|
||||
extern GPtrArray *mdb_read_columns(MdbTableDef *table);
|
||||
extern void mdb_table_dump(MdbCatalogEntry *entry);
|
||||
extern guint16 read_pg_if_16(MdbHandle *mdb, int *cur_pos);
|
||||
extern guint32 read_pg_if_32(MdbHandle *mdb, int *cur_pos);
|
||||
extern int read_pg_if(MdbHandle *mdb, int *cur_pos, int offset);
|
||||
extern guint16 read_pg_if_n(MdbHandle *mdb, unsigned char *buf, int *cur_pos, int len);
|
||||
|
||||
|
||||
/* data.c */
|
||||
extern int mdb_bind_column_by_name(MdbTableDef *table, gchar *col_name, void *bind_ptr);
|
||||
@ -426,6 +432,11 @@ extern int mdb_test_sarg(MdbHandle *mdb, MdbColumn *col, MdbSargNode *node, void
|
||||
extern void mdb_sql_walk_tree(MdbSargNode *node, MdbSargTreeFunc func, gpointer data);
|
||||
extern int mdb_find_indexable_sargs(MdbSargNode *node, gpointer data);
|
||||
extern int mdb_add_sarg_by_name(MdbTableDef *table, char *colname, MdbSarg *in_sarg);
|
||||
extern int mdb_test_string(MdbSargNode *node, char *s);
|
||||
extern int mdb_test_int(MdbSargNode *node, gint32 i);
|
||||
extern int mdb_add_sarg(MdbColumn *col, MdbSarg *in_sarg);
|
||||
|
||||
|
||||
|
||||
/* index.c */
|
||||
extern GPtrArray *mdb_read_indices(MdbTableDef *table);
|
||||
@ -433,6 +444,8 @@ extern void mdb_index_dump(MdbTableDef *table, MdbIndex *idx);
|
||||
extern void mdb_index_scan_free(MdbTableDef *table);
|
||||
extern int mdb_index_find_next_on_page(MdbHandle *mdb, MdbIndexPage *ipg);
|
||||
extern int mdb_index_find_next(MdbHandle *mdb, MdbIndex *idx, MdbIndexChain *chain, guint32 *pg, guint16 *row);
|
||||
extern void mdb_index_hash_text(guchar *text, guchar *hash);
|
||||
extern void mdb_index_scan_init(MdbHandle *mdb, MdbTableDef *table);
|
||||
|
||||
/* stats.c */
|
||||
extern void mdb_stats_on(MdbHandle *mdb);
|
||||
@ -444,6 +457,24 @@ extern int mdb_like_cmp(char *s, char *r);
|
||||
|
||||
/* write.c */
|
||||
extern int mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields);
|
||||
extern int mdb_pack_row(MdbTableDef *table, unsigned char *row_buffer, int num_fields, MdbField *fields);
|
||||
extern void mdb_add_row_to_pg(MdbTableDef *table, unsigned char *row_buffer, int new_row_size);
|
||||
extern int mdb_replace_row(MdbTableDef *table, int row, unsigned char *new_row, int new_row_size);
|
||||
extern int mdb_update_index(MdbTableDef *table, MdbIndex *idx, int num_fields, MdbField *fields);
|
||||
extern int mdb_pg_get_freespace(MdbHandle *mdb);
|
||||
extern int mdb_update_row(MdbTableDef *table);
|
||||
extern unsigned char *mdb_new_data_pg(MdbCatalogEntry *entry);
|
||||
|
||||
/* map.c */
|
||||
extern guint32 mdb_map_find_next_freepage(MdbTableDef *table, int row_size);
|
||||
|
||||
/* props.c */
|
||||
extern GPtrArray *mdb_read_props_list(gchar *kkd, int len);
|
||||
extern void mdb_free_props(MdbProperties *props);
|
||||
extern MdbProperties *mdb_read_props(MdbHandle *mdb, GPtrArray *names, gchar *kkd, int len);
|
||||
|
||||
/* worktable.c */
|
||||
extern MdbTableDef *mdb_create_temp_table(MdbHandle *mdb, char *name);
|
||||
extern void mdb_temp_table_add_col(MdbTableDef *table, MdbColumn *col);
|
||||
|
||||
#endif /* _mdbtools_h_ */
|
||||
|
@ -120,11 +120,11 @@ int did_first;
|
||||
|
||||
char *mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
||||
{
|
||||
static char buf[100];
|
||||
static char buf[16];
|
||||
|
||||
if (col_type > 0x10 ) {
|
||||
// return NULL;
|
||||
sprintf(buf,"type %04x", col_type);
|
||||
snprintf(buf,sizeof(buf), "type %04x", col_type);
|
||||
return buf;
|
||||
} else {
|
||||
return backend->types_table[col_type].name;
|
||||
|
@ -190,18 +190,18 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
MdbHandle *mdb = table->entry->mdb;
|
||||
MdbFormatConstants *fmt = mdb->fmt;
|
||||
MdbColumn *col;
|
||||
int i, j, rc;
|
||||
int num_cols, var_cols, fixed_cols;
|
||||
int i, rc;
|
||||
//int num_cols, var_cols, fixed_cols;
|
||||
int row_start, row_end;
|
||||
int fixed_cols_found, var_cols_found;
|
||||
int col_start, len, next_col;
|
||||
int num_of_jumps=0, jumps_used=0;
|
||||
int eod; /* end of data */
|
||||
//int fixed_cols_found, var_cols_found;
|
||||
//int col_start, len, next_col;
|
||||
//int num_of_jumps=0, jumps_used=0;
|
||||
//int eod; /* end of data */
|
||||
int delflag, lookupflag;
|
||||
int bitmask_sz;
|
||||
int col_ptr, deleted_columns=0;
|
||||
unsigned char null_mask[33]; /* 256 columns max / 8 bits per byte */
|
||||
unsigned char isnull;
|
||||
//int bitmask_sz;
|
||||
//int col_ptr, deleted_columns=0;
|
||||
//unsigned char null_mask[33]; /* 256 columns max / 8 bits per byte */
|
||||
//unsigned char isnull;
|
||||
MdbField fields[256];
|
||||
int num_fields;
|
||||
|
||||
@ -227,8 +227,8 @@ int mdb_read_row(MdbTableDef *table, int row)
|
||||
return 0;
|
||||
}
|
||||
|
||||
num_fields = mdb_crack_row(table, row_start, row_end, &fields);
|
||||
if (!mdb_test_sargs(table, &fields, num_fields)) return 0;
|
||||
num_fields = mdb_crack_row(table, row_start, row_end, fields);
|
||||
if (!mdb_test_sargs(table, fields, num_fields)) return 0;
|
||||
|
||||
#if MDB_DEBUG
|
||||
fprintf(stdout,"sarg test passed row %d \n", row);
|
||||
@ -572,7 +572,7 @@ guint32 pg;
|
||||
do {
|
||||
if (table->strategy==MDB_INDEX_SCAN) {
|
||||
|
||||
if (!mdb_index_find_next(table->mdbidx, table->scan_idx, table->chain, &pg, &(table->cur_row))) {
|
||||
if (!mdb_index_find_next(table->mdbidx, table->scan_idx, table->chain, &pg, (guint16 *) &(table->cur_row))) {
|
||||
mdb_index_scan_free(table);
|
||||
return 0;
|
||||
}
|
||||
@ -1008,6 +1008,8 @@ static int trim_trailing_zeros(char * buff, int n)
|
||||
|
||||
if (*p == '.')
|
||||
*p = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *mdb_col_to_string(MdbHandle *mdb, unsigned char *buf, int start, int datatype, int size)
|
||||
@ -1037,13 +1039,13 @@ double td;
|
||||
return text;
|
||||
break;
|
||||
case MDB_FLOAT:
|
||||
tf = mdb_get_single(mdb, start);
|
||||
tf = mdb_get_single(mdb->pg_buf, start);
|
||||
n = sprintf(text,"%.*f",FLT_DIG - (int)ceil(log10(tf)), tf);
|
||||
trim_trailing_zeros(text, n);
|
||||
return text;
|
||||
break;
|
||||
case MDB_DOUBLE:
|
||||
td = mdb_get_double(mdb, start);
|
||||
td = mdb_get_double(mdb->pg_buf, start);
|
||||
n = sprintf(text,"%.*f",DBL_DIG - (int)ceil(log10(td)), td);
|
||||
trim_trailing_zeros(text, n);
|
||||
return text;
|
||||
|
@ -222,6 +222,7 @@ mdb_index_cache_sarg(MdbColumn *col, MdbSarg *sarg, MdbSarg *idx_sarg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
int
|
||||
mdb_index_test_sarg(MdbHandle *mdb, MdbColumn *col, MdbSarg *sarg, int offset, int len)
|
||||
{
|
||||
@ -249,6 +250,7 @@ int lastchar;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
int
|
||||
mdb_index_test_sargs(MdbHandle *mdb, MdbIndex *idx, int offset, int len)
|
||||
{
|
||||
|
@ -306,8 +306,10 @@ mdb_update_indexes(MdbTableDef *table, int num_fields, MdbField *fields)
|
||||
mdb_update_index(table, idx, num_fields, fields);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
mdb_init_index_chain(MdbTableDef *table, MdbIndex *idx)
|
||||
{
|
||||
MdbCatalogEntry *entry = table->entry;
|
||||
@ -317,6 +319,8 @@ mdb_init_index_chain(MdbTableDef *table, MdbIndex *idx)
|
||||
table->chain = g_malloc0(sizeof(MdbIndexChain));
|
||||
table->mdbidx = mdb_clone_handle(mdb);
|
||||
mdb_read_pg(table->mdbidx, table->scan_idx->first_pg);
|
||||
|
||||
return 1;
|
||||
}
|
||||
int
|
||||
mdb_update_index(MdbTableDef *table, MdbIndex *idx, int num_fields, MdbField *fields)
|
||||
@ -342,18 +346,19 @@ mdb_update_index(MdbTableDef *table, MdbIndex *idx, int num_fields, MdbField *fi
|
||||
fields[i].siz);
|
||||
}
|
||||
//mdb_find_leaf_pg();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
mdb_insert_row(MdbTableDef *table, int num_fields, MdbField *fields)
|
||||
{
|
||||
int new_row_size, num_rows, i, pos, row_start, row_end, row_size;
|
||||
int new_row_size;
|
||||
unsigned char row_buffer[4096];
|
||||
MdbCatalogEntry *entry = table->entry;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
MdbFormatConstants *fmt = mdb->fmt;
|
||||
guint32 pgnum;
|
||||
unsigned char *new_pg;
|
||||
|
||||
if (!mdb->f->writable) {
|
||||
fprintf(stderr, "File is not open for writing\n");
|
||||
@ -382,6 +387,8 @@ mdb_insert_row(MdbTableDef *table, int num_fields, MdbField *fields)
|
||||
}
|
||||
|
||||
mdb_update_indexes(table, num_fields, fields);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
* Assumes caller has verfied space is available on page and adds the new
|
||||
@ -463,7 +470,7 @@ int old_row_size, new_row_size, delta, num_fields;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
num_fields = mdb_crack_row(table, row_start, row_end, &fields);
|
||||
num_fields = mdb_crack_row(table, row_start, row_end, fields);
|
||||
|
||||
#if MDB_DEBUG_WRITE
|
||||
for (i=0;i<num_fields;i++) {
|
||||
@ -479,7 +486,7 @@ int old_row_size, new_row_size, delta, num_fields;
|
||||
}
|
||||
}
|
||||
|
||||
new_row_size = mdb_pack_row(table, row_buffer, num_fields, &fields);
|
||||
new_row_size = mdb_pack_row(table, row_buffer, num_fields, fields);
|
||||
#if MDB_DEBUG_WRITE
|
||||
buffer_dump(row_buffer, 0, new_row_size-1);
|
||||
#endif
|
||||
|
@ -436,7 +436,7 @@ MdbSQLSarg *sql_sarg;
|
||||
if (sql_sarg->sarg) g_free(sql_sarg->sarg);
|
||||
}
|
||||
if (sql->sarg_tree) {
|
||||
mdb_sql_free_tree(sql);
|
||||
mdb_sql_free_tree(sql->sarg_tree);
|
||||
sql->sarg_tree = NULL;
|
||||
}
|
||||
g_list_free(sql->sarg_stack);
|
||||
@ -484,8 +484,6 @@ void mdb_sql_listtables(MdbSQL *sql)
|
||||
MdbCatalogEntry *entry;
|
||||
MdbHandle *mdb = sql->mdb;
|
||||
MdbField fields[4];
|
||||
int num_fields = 0;
|
||||
char tmpstr[256];
|
||||
unsigned char row_buffer[4096];
|
||||
unsigned char *new_pg;
|
||||
int row_size;
|
||||
@ -530,7 +528,7 @@ void mdb_sql_listtables(MdbSQL *sql)
|
||||
fields[0].start = 0;
|
||||
fields[0].colnum = 0;
|
||||
|
||||
row_size = mdb_pack_row(ttable, row_buffer, 1, &fields);
|
||||
row_size = mdb_pack_row(ttable, row_buffer, 1, fields);
|
||||
mdb_add_row_to_pg(ttable,row_buffer, row_size);
|
||||
ttable->num_rows++;
|
||||
}
|
||||
@ -551,7 +549,6 @@ void mdb_sql_describe_table(MdbSQL *sql)
|
||||
int i;
|
||||
char colsize[11];
|
||||
MdbField fields[4];
|
||||
int num_fields = 0;
|
||||
char tmpstr[256];
|
||||
unsigned char row_buffer[4096];
|
||||
unsigned char *new_pg;
|
||||
@ -646,7 +643,7 @@ void mdb_sql_describe_table(MdbSQL *sql)
|
||||
fields[2].start = 0;
|
||||
fields[2].colnum = 2;
|
||||
|
||||
row_size = mdb_pack_row(ttable, row_buffer, 3, &fields);
|
||||
row_size = mdb_pack_row(ttable, row_buffer, 3, fields);
|
||||
mdb_add_row_to_pg(ttable,row_buffer, row_size);
|
||||
ttable->num_rows++;
|
||||
}
|
||||
|
@ -103,7 +103,6 @@ void dump_kkd(gchar *kkd, int len)
|
||||
guint32 record_len, record_type;
|
||||
int pos = 0;
|
||||
GPtrArray *names = NULL;
|
||||
gchar *name;
|
||||
MdbProperties *props;
|
||||
|
||||
#ifdef MDB_DEBUG
|
||||
@ -139,7 +138,7 @@ void dump_kkd(gchar *kkd, int len)
|
||||
printf("sequence error!\n");
|
||||
break;
|
||||
}
|
||||
props = mdb_read_props(names, &kkd[pos+6], record_len - 6);
|
||||
props = mdb_read_props(mdb, names, &kkd[pos+6], record_len - 6);
|
||||
printf("type 0x01 name %s\n", props->name ? props->name : "(none)");
|
||||
g_hash_table_foreach(props->hash, print_keyvalue, NULL);
|
||||
mdb_free_props(props);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
static char *santize_name(char *str, int santize);
|
||||
static char *sanitize_name(char *str, int sanitize);
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
@ -101,7 +101,7 @@ main (int argc, char **argv)
|
||||
fprintf (stdout, "DROP TABLE %s%s;\n", namespace, sanitize_name(entry->object_name,s));
|
||||
|
||||
/* create the table */
|
||||
fprintf (stdout, "CREATE TABLE %s%s\n", sanitize_name(entry->object_name,s));
|
||||
fprintf (stdout, "CREATE TABLE %s%s\n", namespace, sanitize_name(entry->object_name,s));
|
||||
fprintf (stdout, " (\n");
|
||||
|
||||
table = mdb_read_table (entry);
|
||||
|
@ -101,10 +101,10 @@ void check_row(MdbHandle *mdb, MdbIndex *idx, guint32 pg, int row, unsigned char
|
||||
|
||||
fmt = mdb->fmt;
|
||||
mdb_read_pg(mdb, pg);
|
||||
row_start = mdb_get_int16(mdb, (fmt->row_count_offset + 2) + (row*2));
|
||||
row_start = mdb_pg_get_int16(mdb, (fmt->row_count_offset + 2) + (row*2));
|
||||
row_end = mdb_find_end_of_row(mdb, row);
|
||||
|
||||
num_fields = mdb_crack_row(table, row_start, row_end, &fields);
|
||||
num_fields = mdb_crack_row(table, row_start, row_end, fields);
|
||||
for (i=0;i<idx->num_keys;i++) {
|
||||
col=g_ptr_array_index(table->columns,idx->key_col_num[i]-1);
|
||||
if (col->col_type==MDB_TEXT) {
|
||||
@ -146,14 +146,14 @@ walk_index(MdbHandle *mdb, MdbIndex *idx)
|
||||
|
||||
memset(&chain, 0, sizeof(MdbIndexChain));
|
||||
printf("name %s\n", idx->name);
|
||||
printf("root page %ld\n", idx->first_pg);
|
||||
printf("root page %lu\n", (long unsigned) idx->first_pg);
|
||||
/* clone the handle to search the index, and use the original to read
|
||||
* the data */
|
||||
mdbidx = mdb_clone_handle(mdb);
|
||||
mdb_read_pg(mdbidx, idx->first_pg);
|
||||
//printf("page type %02x %s\n", mdbidx->pg_buf[0], page_name(mdbidx->pg_buf[0]));
|
||||
while (mdb_index_find_next(mdbidx, idx, &chain, &pg, &row)) {
|
||||
printf("row = %d pg = %lu\n", row, pg);
|
||||
printf("row = %d pg = %lu\n", row, (long unsigned) pg);
|
||||
check_row(mdb, idx, pg, row, &mdbidx->pg_buf[start], len - 4);
|
||||
}
|
||||
mdb_close(mdbidx);
|
||||
|
Loading…
Reference in New Issue
Block a user