mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-09-18 18:22:07 +08:00
new index code
This commit is contained in:
13
HACKERS
13
HACKERS
@@ -106,7 +106,7 @@ The header to table definition pages start look something like this:
|
||||
| 0x02 | 1 byte | Page type |
|
||||
| 0x01 | 1 byte | Unknown |
|
||||
| 'VC' | 2 bytes | ??? |
|
||||
| 0x00 | 4 bytes | Unknown |
|
||||
| 0x00 | 4 bytes | Pointer to continuation page (if multipage table def) |
|
||||
| ???? | 4 bytes | appears to be a length of the data |
|
||||
| ???? | 4 bytes | number of rows of data in this table |
|
||||
| 0x00 | 4 bytes | ??? |
|
||||
@@ -115,14 +115,14 @@ The header to table definition pages start look something like this:
|
||||
| ???? | 2 bytes | ??? |
|
||||
| ???? | 2 bytes | number of columns in table |
|
||||
| ???? | 4 bytes | number of indexes for this table |
|
||||
| ???? | 4 bytes | number of indexes for this table (repeat) |
|
||||
| ???? | 4 bytes | number of index entries for this table |
|
||||
| 0x00 | 1 byte | ??? |
|
||||
| ???? | 2 bytes | page number of first datapage for table |
|
||||
| ???? | 2 bytes | ??? |
|
||||
| ???? | 2 bytes | page number of first datapage for table |
|
||||
| 0x00 | 1 byte | ??? |
|
||||
+-------------------------------------------------------------------------+
|
||||
| Iterate for the 2 x number of indexes |
|
||||
| Iterate for 2 x number of indexes |
|
||||
+-------------------------------------------------------------------------+
|
||||
| ???? | 4 bytes | number of rows in table |
|
||||
| ???? | 4 bytes | number of rows in the index |
|
||||
@@ -154,10 +154,11 @@ Column Type may be one of the following (not complete).
|
||||
Following the 18 byte column records begins the column names, listed in order
|
||||
with a 1 byte size prefix preceding each name.
|
||||
|
||||
After a number of bytes (generally 0x3a) the names of the indexes are listed.
|
||||
After this are a series of 39 byte fields for each index. At offset 34 is a 4 byte page number where the index lives.
|
||||
|
||||
It is currently unknown how indexes are mapped to columns and how they point at
|
||||
index pages or the format of the index pages.
|
||||
Beyond this are a series of 20 byte fields for each 'index entry'. There may be more entrys than indexes and byte 20 represents its type (0x00 for normal index, 0x01 for Primary Key, and 0x02 otherwise).
|
||||
|
||||
It is currently unknown how indexes are mapped to columns or the format of the index pages.
|
||||
|
||||
Data Rows
|
||||
---------
|
||||
|
2
README
2
README
@@ -15,7 +15,7 @@ MDB files and a ODBC/SQL frontend.
|
||||
Files in libmdb are licensed under LGPL and the utilities under the GPL, see
|
||||
COPYING.LIB and COPYING files respectively.
|
||||
|
||||
To install type see the INSTALL file
|
||||
To install see the INSTALL file
|
||||
|
||||
Check out http://mdbtools.sourceforge.net for CVS, mailing list and similar.
|
||||
|
||||
|
@@ -80,6 +80,11 @@ enum {
|
||||
MDB_NOTNULL
|
||||
};
|
||||
|
||||
enum {
|
||||
MDB_ASC,
|
||||
MDB_DESC
|
||||
};
|
||||
|
||||
/* hash to store registered backends */
|
||||
GHashTable *mdb_backends;
|
||||
|
||||
@@ -121,15 +126,26 @@ typedef struct {
|
||||
MdbCatalogEntry *entry;
|
||||
char name[MDB_MAX_OBJ_NAME+1];
|
||||
int num_cols;
|
||||
int num_rows;
|
||||
int num_pgs;
|
||||
int first_data_pg;
|
||||
GPtrArray *columns;
|
||||
int num_rows;
|
||||
int index_start;
|
||||
int num_real_idxs;
|
||||
int num_idxs;
|
||||
GPtrArray *indices;
|
||||
int first_data_pg;
|
||||
int cur_pg_num;
|
||||
int cur_phys_pg;
|
||||
int cur_row;
|
||||
} MdbTableDef;
|
||||
|
||||
typedef struct {
|
||||
int index_num;
|
||||
char name[MDB_MAX_OBJ_NAME+1];
|
||||
unsigned char primary_key;
|
||||
int first_pg;
|
||||
unsigned char sort_order;
|
||||
} MdbIndex;
|
||||
|
||||
typedef struct {
|
||||
char name[MDB_MAX_OBJ_NAME+1];
|
||||
} MdbColumnProp;
|
||||
|
@@ -20,7 +20,7 @@ INSTALL= @INSTALL@
|
||||
LIBLIST = libmdb.a
|
||||
|
||||
INC = -I ../include `glib-config --cflags`
|
||||
OBJS = catalog.o mem.o file.o kkd.o table.o data.o dump.o backend.o money.o sargs.o
|
||||
OBJS = catalog.o mem.o file.o kkd.o table.o data.o dump.o backend.o money.o sargs.o index.o
|
||||
|
||||
all: libmdb
|
||||
|
||||
@@ -54,5 +54,6 @@ kkd.o: kkd.c ../include/mdbtools.h
|
||||
mem.o: mem.c ../include/mdbtools.h
|
||||
table.o: table.c ../include/mdbtools.h
|
||||
sargs.o: sargs.c ../include/mdbtools.h
|
||||
index.o: sargs.c ../include/mdbtools.h
|
||||
money.o: money.c
|
||||
|
||||
|
@@ -245,6 +245,7 @@ MdbHandle *mdb = entry->mdb;
|
||||
if (!mdb_read_pg(mdb, table->cur_phys_pg++))
|
||||
return 0;
|
||||
} while (mdb->pg_buf[0]!=0x01 || mdb_get_int32(mdb, 4)!=entry->table_pg);
|
||||
/* fprintf(stderr,"returning new page %ld\n", table->cur_phys_pg); */
|
||||
return table->cur_phys_pg;
|
||||
}
|
||||
int mdb_rewind_table(MdbTableDef *table)
|
||||
|
69
src/libmdb/index.c
Normal file
69
src/libmdb/index.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* MDB Tools - A library for reading MS Access database file
|
||||
* Copyright (C) 2000 Brian Bruns
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "mdbtools.h"
|
||||
|
||||
GPtrArray *mdb_read_indices(MdbTableDef *table)
|
||||
{
|
||||
MdbHandle *mdb = table->entry->mdb;
|
||||
MdbIndex idx, *pidx;
|
||||
int len, i;
|
||||
int cur_pos;
|
||||
int name_sz;
|
||||
|
||||
/* FIX ME -- doesn't handle multipage table headers */
|
||||
|
||||
table->indices = g_ptr_array_new();
|
||||
|
||||
cur_pos = table->index_start;
|
||||
|
||||
for (i=0;i<table->num_real_idxs;i++) {
|
||||
memset(&idx, '\0', sizeof(MdbIndex));
|
||||
idx.index_num = i;
|
||||
cur_pos += 34;
|
||||
idx.first_pg = mdb_get_int32(mdb, cur_pos);
|
||||
cur_pos += 5;
|
||||
mdb_append_index(table->indices, &idx);
|
||||
}
|
||||
|
||||
for (i=0;i<table->num_idxs;i++) {
|
||||
pidx = g_ptr_array_index (table->indices, i);
|
||||
cur_pos += 19;
|
||||
if (mdb->pg_buf[cur_pos++]==0x01)
|
||||
pidx->primary_key=1;
|
||||
}
|
||||
|
||||
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';
|
||||
//fprintf(stderr, "index name %s\n", pidx->name);
|
||||
cur_pos += name_sz;
|
||||
}
|
||||
}
|
||||
void mdb_index_dump(MdbIndex *idx)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stdout,"index number %d\n", idx->index_num);
|
||||
fprintf(stdout,"index name %s\n", idx->name);
|
||||
fprintf(stdout,"index first page %d\n", idx->first_pg);
|
||||
if (idx->primary_key) fprintf(stdout,"index is a primary key\n");
|
||||
}
|
@@ -75,10 +75,21 @@ mdb_append_column(GPtrArray *columns, MdbColumn *in_col)
|
||||
{
|
||||
MdbColumn *col;
|
||||
|
||||
col = g_memdup(in_col,sizeof(MdbCatalogEntry));
|
||||
col = g_memdup(in_col,sizeof(MdbColumn));
|
||||
g_ptr_array_add(columns, col);
|
||||
}
|
||||
mdb_free_columns(GPtrArray *columns)
|
||||
{
|
||||
g_ptr_array_free(columns, TRUE);
|
||||
}
|
||||
mdb_append_index(GPtrArray *indices, MdbIndex *in_idx)
|
||||
{
|
||||
MdbIndex *idx;
|
||||
|
||||
idx = g_memdup(in_idx,sizeof(MdbIndex));
|
||||
g_ptr_array_add(indices, idx);
|
||||
}
|
||||
mdb_free_indices(GPtrArray *indices)
|
||||
{
|
||||
g_ptr_array_free(indices, TRUE);
|
||||
}
|
||||
|
@@ -46,6 +46,9 @@ int mdb_test_int(MdbSarg *sarg, gint32 i)
|
||||
int mdb_test_sarg(MdbHandle *mdb, MdbColumn *col, MdbSarg *sarg, int offset, int len)
|
||||
{
|
||||
switch (col->col_type) {
|
||||
case MDB_BYTE:
|
||||
return mdb_test_int(sarg, mdb_get_byte(mdb, offset));
|
||||
break;
|
||||
case MDB_INT:
|
||||
return mdb_test_int(sarg, mdb_get_int16(mdb, offset));
|
||||
break;
|
||||
|
@@ -42,7 +42,8 @@ int len, i;
|
||||
|
||||
table->num_rows = mdb_get_int32(mdb,12);
|
||||
table->num_cols = mdb_get_int16(mdb,25);
|
||||
table->num_pgs = mdb_get_int32(mdb,31);
|
||||
table->num_idxs = mdb_get_int32(mdb,27);
|
||||
table->num_real_idxs = mdb_get_int32(mdb,31);
|
||||
table->first_data_pg = mdb_get_int16(mdb,36);
|
||||
|
||||
return table;
|
||||
@@ -75,7 +76,7 @@ int name_sz;
|
||||
|
||||
table->columns = g_ptr_array_new();
|
||||
|
||||
cur_col = 43 + (table->num_pgs * 8);
|
||||
cur_col = 43 + (table->num_real_idxs * 8);
|
||||
|
||||
/* new code based on patch submitted by Tim Nelson 2000.09.27 */
|
||||
|
||||
@@ -134,6 +135,7 @@ int name_sz;
|
||||
|
||||
cur_name += name_sz + 1;
|
||||
}
|
||||
table->index_start = cur_name;
|
||||
return table->columns;
|
||||
}
|
||||
|
||||
@@ -141,16 +143,20 @@ void mdb_table_dump(MdbCatalogEntry *entry)
|
||||
{
|
||||
MdbTableDef *table;
|
||||
MdbColumn *col;
|
||||
MdbIndex *idx;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
int i;
|
||||
|
||||
table = mdb_read_table(entry);
|
||||
fprintf(stdout,"definition page = %d\n",entry->table_pg);
|
||||
fprintf(stdout,"number of datarows = %d\n",table->num_rows);
|
||||
fprintf(stdout,"number of columns = %d\n",table->num_cols);
|
||||
fprintf(stdout,"number of datapages = %d\n",table->num_pgs);
|
||||
fprintf(stdout,"number of indices = %d\n",table->num_real_idxs);
|
||||
fprintf(stdout,"first data page = %d\n",table->first_data_pg);
|
||||
|
||||
mdb_read_columns(table);
|
||||
mdb_read_indices(table);
|
||||
|
||||
for (i=0;i<table->num_cols;i++) {
|
||||
col = g_ptr_array_index(table->columns,i);
|
||||
|
||||
@@ -159,4 +165,10 @@ int i;
|
||||
mdb_get_coltype_string(mdb->default_backend, col->col_type),
|
||||
col->col_size);
|
||||
}
|
||||
|
||||
for (i=0;i<table->num_idxs;i++) {
|
||||
idx = g_ptr_array_index (table->indices, i);
|
||||
mdb_index_dump(idx);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user