index work

dmalloc headers
mem leak fixes
start on i18n
This commit is contained in:
brianb
2003-01-28 23:51:06 +00:00
parent 95c0805c08
commit 75216d7a90
26 changed files with 226 additions and 29 deletions

View File

@@ -23,6 +23,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/* Access data types */
char *mdb_access_types[] =
{"Unknown 0x00",

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
char *
mdb_get_objtype_string(int obj_type)
{
@@ -91,6 +95,9 @@ int type;
}
}
//mdb_dump_catalog(mdb, MDB_TABLE);
mdb_free_tabledef(table);
return mdb->catalog;
}

View File

@@ -21,6 +21,10 @@
#include "time.h"
#include "math.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#define MDB_DEBUG_OLE 1
char *mdb_money_to_string(MdbHandle *mdb, int start, char *s);

View File

@@ -2,6 +2,10 @@
#include <string.h>
#include <stdio.h>
#ifdef DMALLOC
#include "dmalloc.h"
#endif
void buffer_dump(const unsigned char* buf, int start, int end)
{
char asc[20];

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
MdbFormatConstants MdbJet4Constants = {
4096, 0x0c, 12, 45, 47, 51, 55, 56, 63, 12, 15, 23, 5, 25
};
@@ -143,7 +147,10 @@ mdb_close(MdbHandle *mdb)
{
if (mdb->f) {
mdb->f->refs--;
if (mdb->f->refs<=0) mdb_free_file(mdb->f);
if (mdb->f->refs<=0) {
mdb_free_file(mdb->f);
mdb->f = NULL;
}
}
}
MdbHandle *mdb_clone_handle(MdbHandle *mdb)

View File

@@ -18,6 +18,11 @@
*/
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
char idx_to_text[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0-7 0x00-0x07 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8-15 0x09-0x0f */
@@ -53,43 +58,70 @@ char idx_to_text[] = {
0x81, 0x00, 0x00, 0x00, 'x', 0x00, 0x00, 0x00, /* 0xf8-0xff */
};
GPtrArray *
mdb_read_indices(MdbTableDef *table)
{
MdbHandle *mdb = table->entry->mdb;
MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
MdbFormatConstants *fmt = mdb->fmt;
MdbIndex idx, *pidx;
int i, j;
int idx_num, key_num, col_num;
int cur_pos;
int name_sz;
int name_sz, idx2_sz;
gchar *tmpbuf;
/* FIX ME -- doesn't handle multipage table headers */
table->indices = g_ptr_array_new();
cur_pos = table->index_start + 39 * table->num_real_idxs;
if (IS_JET4(mdb)) {
cur_pos = table->index_start + 52 * table->num_real_idxs;
idx2_sz = 27;
} else {
cur_pos = table->index_start + 39 * table->num_real_idxs;
idx2_sz = 19;
}
for (i=0;i<table->num_idxs;i++) {
memset(&idx, '\0', sizeof(MdbIndex));
idx.table = table;
idx.index_num = mdb_get_int16(mdb, cur_pos);
cur_pos += 19;
cur_pos +=4;
idx.index_num = read_pg_if_16(mdb, &cur_pos);
read_pg_if(mdb, &cur_pos, idx2_sz - 4);
cur_pos += idx2_sz - 4;
idx.index_type = mdb->pg_buf[cur_pos++];
mdb_append_index(table->indices, &idx);
}
for (i=0;i<table->num_idxs;i++) {
pidx = g_ptr_array_index (table->indices, i);
name_sz=mdb->pg_buf[cur_pos++];
memcpy(pidx->name, &mdb->pg_buf[cur_pos], name_sz);
pidx->name[name_sz]='\0';
read_pg_if(mdb, &cur_pos, 0);
if (IS_JET4(mdb)) {
name_sz=read_pg_if_16(mdb, &cur_pos);
cur_pos += 2;
tmpbuf = g_malloc((name_sz + 1)*2);
read_pg_if_n(mdb, tmpbuf, &cur_pos, name_sz*2);
mdb_unicode2ascii(mdb, tmpbuf, 0, name_sz, pidx->name);
g_free(tmpbuf);
cur_pos += name_sz;
} else {
name_sz=mdb->pg_buf[cur_pos++];
read_pg_if_n(mdb, pidx->name, &cur_pos, name_sz);
pidx->name[name_sz]='\0';
cur_pos += name_sz;
}
//fprintf(stderr, "index name %s\n", pidx->name);
cur_pos += name_sz;
}
cur_pos = table->index_start;
mdb_read_alt_pg(mdb, entry->table_pg);
mdb_read_pg(mdb, entry->table_pg);
idx_num=0;
for (i=0;i<table->num_real_idxs;i++) {
if (IS_JET4(mdb)) cur_pos += 4;
do {
pidx = g_ptr_array_index (table->indices, idx_num++);
} while (pidx && pidx->index_type==2);
@@ -103,11 +135,13 @@ int name_sz;
continue;
}
pidx->num_rows = mdb_get_int32(mdb, 43+(i*8) );
pidx->num_rows = _mdb_get_int32(mdb->alt_pg_buf,
fmt->tab_cols_start_offset +
(i*fmt->tab_ridx_entry_size));
key_num=0;
for (j=0;j<MDB_MAX_IDX_COLS;j++) {
col_num=mdb_get_int16(mdb,cur_pos);
col_num=read_pg_if_16(mdb,&cur_pos);
cur_pos += 2;
if (col_num != 0xFFFF) {
/* set column number to a 1 based column number and store */
@@ -123,9 +157,11 @@ int name_sz;
}
pidx->num_keys = key_num;
cur_pos += 4;
pidx->first_pg = mdb_get_int32(mdb, cur_pos);
pidx->first_pg = read_pg_if_32(mdb, &cur_pos);
cur_pos += 4;
read_pg_if(mdb, &cur_pos, 1);
pidx->flags = mdb->pg_buf[cur_pos++];
if (IS_JET4(mdb)) cur_pos += 9;
}
return NULL;
}
@@ -569,7 +605,7 @@ mdb_choose_index(MdbTableDef *table, int *choice)
}
}
/* and the winner is: *choice */
if (!least) return MDB_TABLE_SCAN;
if (least==99) return MDB_TABLE_SCAN;
return MDB_INDEX_SCAN;
}
void
@@ -590,6 +626,7 @@ mdb_index_scan_init(MdbHandle *mdb, MdbTableDef *table)
mdb_read_pg(table->mdbidx, table->scan_idx->first_pg);
//printf("best index is %s\n",table->scan_idx->name);
}
//printf("TABLE SCAN? %d\n", table->strategy);
}
void
mdb_index_scan_free(MdbTableDef *table)

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/*
** Note: This code is mostly garbage right now...just a test to parse out the

View File

@@ -20,6 +20,10 @@
#include <stdio.h>
#include <string.h>
#ifdef DMALLOC
#include "dmalloc.h"
#endif
//#define MDB_DEBUG_LIKE 1
int mdb_like_cmp(char *s, char *r)

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
void mdb_init()
{
mdb_init_backends();

View File

@@ -20,6 +20,10 @@
#include <stdio.h>
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#define MAXPRECISION 9
/*
** these routines are copied from the freetds project which does something

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
void
mdb_sql_walk_tree(MdbSargNode *node, MdbSargTreeFunc func, gpointer data)
{

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
void
mdb_stats_on(MdbHandle *mdb)
{

View File

@@ -19,6 +19,10 @@
#include "mdbtools.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#define MDB_DEBUG_USAGE 0
static gint mdb_col_comparer(MdbColumn *a, MdbColumn *b)
@@ -86,7 +90,8 @@ int rownum, row_start, row_end;
** read the next page if offset is > pg_size
** return true if page was read
*/
static int read_pg_if(MdbHandle *mdb, int *cur_pos, int offset)
int
read_pg_if(MdbHandle *mdb, int *cur_pos, int offset)
{
if (*cur_pos + offset >= mdb->fmt->pg_size) {
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
@@ -95,6 +100,47 @@ static int read_pg_if(MdbHandle *mdb, int *cur_pos, int offset)
}
return 0;
}
guint32
read_pg_if_32(MdbHandle *mdb, int *cur_pos)
{
unsigned char c[4];
int i, rc = 0;
for (i=0;i<4;i++) {
rc += read_pg_if(mdb, cur_pos, i);
c[i] = mdb->pg_buf[(*cur_pos) + i];
}
return _mdb_get_int32(c, 0);
}
guint16
read_pg_if_16(MdbHandle *mdb, int *cur_pos)
{
unsigned char low_byte, high_byte;
int rc = 0;
rc += read_pg_if(mdb, cur_pos, 0);
low_byte = mdb->pg_buf[*cur_pos];
rc += read_pg_if(mdb, cur_pos, 1);
high_byte = mdb->pg_buf[(*cur_pos) + 1];
return (high_byte * 256 + low_byte);
}
guint16
read_pg_if_n(MdbHandle *mdb, unsigned char *buf, int *cur_pos, int len)
{
int half;
if (*cur_pos + len < mdb->fmt->pg_size) {
memcpy(buf, &mdb->pg_buf[*cur_pos], len);
return 0;
}
half = (mdb->fmt->pg_size - *cur_pos - 1);
memcpy(buf, &mdb->pg_buf[*cur_pos], half);
mdb_read_pg(mdb, mdb_get_int32(mdb,4));
memcpy(buf, &mdb->pg_buf[8], len - half);
*cur_pos = 8 - (mdb->fmt->pg_size - (*cur_pos));
return 1;
}
GPtrArray *mdb_read_columns(MdbTableDef *table)
{

View File

@@ -21,6 +21,10 @@
#include "time.h"
#include "math.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#define MDB_DEBUG_WRITE 1
void