mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-11-26 02:09:49 +08:00
Port to Windows and SQLite Extension
This commit is contained in:
19
src/libmdb/ReadMe.txt
Normal file
19
src/libmdb/ReadMe.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
========================================================================
|
||||
mdbtools Project Overview
|
||||
========================================================================
|
||||
|
||||
Author: The Jimmytaker (jimmytaker@gmx.de)
|
||||
|
||||
This is a port of the mdb-tools library to Windows. I adapted the mdb-tools 0.7 to work as a library in Windows as a part of my work that required me to develop a solution to port Access databases to SQLite usable under both Windows and OS X.
|
||||
|
||||
List of changes:
|
||||
|
||||
- Adapt the code to compile under both VS and MAC (declaration - initialization, void* - char*/unsigned char*, sprintf(), ssize_t, strcasecmp())
|
||||
- Enforce consistency g_malloc - g_free and malloc - free
|
||||
- Make reading 0 as date return "00:00:00" as t->tm_year == -1 fails the debug assertion >= 0
|
||||
- Introduce SQLite support.
|
||||
- Allow schema generation to char* and not only to FILE* from within the library
|
||||
|
||||
Requirements to build and use:
|
||||
|
||||
The only dependency is on glib. You need to provide the glib headers for the project to be built.
|
||||
@@ -57,6 +57,49 @@ static MdbBackendType mdb_access_types[] = {
|
||||
MdbBackendType_STRUCT_ELEMENT("Numeric",1,1,0)
|
||||
};
|
||||
|
||||
/** SQLite data types. According to the SQLite specs only the first set of elements are supported.
|
||||
* However, during testing I found out that if I use the first set, then all texts, and dates are written in
|
||||
* Memo fields, which makes them visible only after clicking on them (one at a time) in a DB Manager. The second set of elements
|
||||
* makes these fields directly visible in a DB Manager like they are visible in Access and therefore I prefer them.
|
||||
*/
|
||||
static MdbBackendType mdb_sqlite_types[] = {
|
||||
//MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("REAL", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("REAL", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("REAL", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("TEXT", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("TEXT", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("TEXT", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
//MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
//MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
|
||||
MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("REAL", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("REAL", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("REAL", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("DateTime", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("varchar", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("TEXT", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("BLOB", 0,0,1),
|
||||
MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
MdbBackendType_STRUCT_ELEMENT("INTEGER", 0,0,0),
|
||||
};
|
||||
|
||||
/* Oracle data types */
|
||||
static MdbBackendType mdb_oracle_types[] = {
|
||||
MdbBackendType_STRUCT_ELEMENT("Oracle_Unknown 0x00",0,0,0),
|
||||
@@ -237,7 +280,7 @@ quote_with_squotes(const gchar* value)
|
||||
return quote_generic(value, '\'', '\'');
|
||||
}
|
||||
|
||||
char * __attribute__((deprecated))
|
||||
char *
|
||||
mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
||||
{
|
||||
static int warn_deprecated = 0;
|
||||
@@ -255,7 +298,7 @@ mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
||||
return backend->types_table[col_type].name;
|
||||
}
|
||||
|
||||
int __attribute__((deprecated))
|
||||
int
|
||||
mdb_coltype_takes_length(MdbBackend *backend, int col_type)
|
||||
{
|
||||
static int warn_deprecated = 0;
|
||||
@@ -303,17 +346,13 @@ mdb_colbacktype_takes_length(const MdbColumn *col)
|
||||
return type->needs_length;
|
||||
}
|
||||
|
||||
void __attribute__((deprecated)) mdb_init_backends() {
|
||||
fprintf(stderr, "mdb_init_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* _mdb_init_backends
|
||||
*
|
||||
* Initializes the mdb_backends hash and loads the builtin backends.
|
||||
* Use mdb_remove_backends() to destroy this hash when done.
|
||||
*/
|
||||
void __attribute__ ((constructor)) _mdb_init_backends()
|
||||
void _mdb_init_backends()
|
||||
{
|
||||
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
|
||||
@@ -327,6 +366,16 @@ void __attribute__ ((constructor)) _mdb_init_backends()
|
||||
NULL,
|
||||
NULL,
|
||||
quote_schema_name_bracket_merge);
|
||||
mdb_register_backend("sqlite", //A lot of guessing and gut feelings went into this one. For my DBs it works fine.
|
||||
MDB_SHEXP_DROPTABLE|MDB_SHEXP_RELATIONS|MDB_SHEXP_DEFVALUES,
|
||||
mdb_sqlite_types, NULL, NULL,
|
||||
"date('now')", "date('now')",
|
||||
"-- That file uses encoding %s\n",
|
||||
"DROP TABLE IF EXISTS %s;\n",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
quote_schema_name_rquotes_merge);
|
||||
mdb_register_backend("sybase",
|
||||
MDB_SHEXP_DROPTABLE|MDB_SHEXP_CST_NOTNULL|MDB_SHEXP_CST_NOTEMPTY|MDB_SHEXP_COMMENTS|MDB_SHEXP_DEFVALUES,
|
||||
mdb_sybase_types, &mdb_sybase_shortdate_type, NULL,
|
||||
@@ -368,6 +417,13 @@ void __attribute__ ((constructor)) _mdb_init_backends()
|
||||
"COMMENT ON TABLE %s IS %s;\n",
|
||||
quote_schema_name_rquotes_merge);
|
||||
}
|
||||
|
||||
/** Supposed to be deprecated in version 0.7, however I could not understand how to work without it. */
|
||||
void mdb_init_backends() {
|
||||
_mdb_init_backends();
|
||||
//fprintf(stderr, "mdb_init_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||
}
|
||||
|
||||
void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendType *backend_type, MdbBackendType *type_shortdate, MdbBackendType *type_autonum, const char *short_now, const char *long_now, const char *charset_statement, const char *drop_statement, const char *constaint_not_empty_statement, const char *column_comment_statement, const char *table_comment_statement, gchar* (*quote_schema_name)(const gchar*, const gchar*))
|
||||
{
|
||||
MdbBackend *backend = (MdbBackend *) g_malloc0(sizeof(MdbBackend));
|
||||
@@ -386,20 +442,24 @@ void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendTy
|
||||
g_hash_table_insert(mdb_backends, backend_name, backend);
|
||||
}
|
||||
|
||||
void __attribute__((deprecated)) mdb_remove_backends() {
|
||||
fprintf(stderr, "mdb_remove_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* mdb_remove_backends
|
||||
*
|
||||
* Removes all entries from and destroys the mdb_backends hash.
|
||||
*/
|
||||
void __attribute__ ((destructor)) _mdb_remove_backends()
|
||||
void _mdb_remove_backends()
|
||||
{
|
||||
g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL);
|
||||
g_hash_table_destroy(mdb_backends);
|
||||
}
|
||||
|
||||
/** Supposed to be deprecated in version 0.7, however I could not understand how to work without it. */
|
||||
void mdb_remove_backends() {
|
||||
//fprintf(stderr, "mdb_remove_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||
_mdb_remove_backends();
|
||||
}
|
||||
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data)
|
||||
{
|
||||
MdbBackend *backend = (MdbBackend *)value;
|
||||
@@ -483,7 +543,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
||||
fprintf (outfile, " UNIQUE");
|
||||
fprintf(outfile, " INDEX %s ON %s (", quoted_name, quoted_table_name);
|
||||
}
|
||||
free(quoted_name);
|
||||
g_free(quoted_name); //changed from free
|
||||
free(index_name);
|
||||
|
||||
for (j=0;j<idx->num_keys;j++) {
|
||||
@@ -496,7 +556,7 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
||||
/* no DESC for primary keys */
|
||||
fprintf(outfile, " DESC");
|
||||
|
||||
free(quoted_name);
|
||||
g_free(quoted_name); //changed from free
|
||||
|
||||
}
|
||||
fprintf (outfile, ");\n");
|
||||
@@ -504,6 +564,97 @@ mdb_print_indexes(FILE* outfile, MdbTableDef *table, char *dbnamespace)
|
||||
fputc ('\n', outfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* mdb_print_indexes
|
||||
* @buf: Where to print the sql
|
||||
* @bi: Index into buf
|
||||
* @bsize: Size of buf
|
||||
* @table: Table to process
|
||||
* @dbnamespace: Target namespace/schema name
|
||||
*/
|
||||
static void
|
||||
mdb_print_indexess(char* buf, unsigned int *bi, unsigned int *bsize, MdbTableDef *table, char *dbnamespace)
|
||||
{
|
||||
unsigned int i, j;
|
||||
char* quoted_table_name;
|
||||
char* index_name;
|
||||
char* quoted_name;
|
||||
MdbHandle* mdb = table->entry->mdb;
|
||||
MdbIndex *idx;
|
||||
MdbColumn *col;
|
||||
|
||||
if (strcmp(mdb->backend_name, "postgres")) {
|
||||
*bi += sprintf(buf + *bi, "-- Indexes are not implemented for %s\n\n", mdb->backend_name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* read indexes */
|
||||
mdb_read_indices(table);
|
||||
|
||||
*bi += sprintf(buf + *bi, "-- CREATE INDEXES ...\n");
|
||||
|
||||
quoted_table_name = mdb->default_backend->quote_schema_name(dbnamespace, table->name);
|
||||
|
||||
for (i=0;i<table->num_idxs;i++) {
|
||||
|
||||
if (*bi > *bsize/2) { //extend the buffer if needed
|
||||
char *b;
|
||||
*bsize *= 2;
|
||||
b = (char*) g_realloc(buf, *bsize);
|
||||
buf = b;
|
||||
}
|
||||
|
||||
idx = (MdbIndex*) g_ptr_array_index (table->indices, i);
|
||||
if (idx->index_type==2)
|
||||
continue;
|
||||
|
||||
index_name = (char*) malloc(strlen(table->name)+strlen(idx->name)+5+1);
|
||||
strcpy(index_name, table->name);
|
||||
if (idx->index_type==1)
|
||||
strcat(index_name, "_pkey");
|
||||
else {
|
||||
strcat(index_name, "_");
|
||||
strcat(index_name, idx->name);
|
||||
strcat(index_name, "_idx");
|
||||
}
|
||||
quoted_name = mdb->default_backend->quote_schema_name(dbnamespace, index_name);
|
||||
if (idx->index_type==1) {
|
||||
*bi += sprintf(buf + *bi, "ALTER TABLE %s ADD CONSTRAINT %s PRIMARY KEY (", quoted_table_name, quoted_name);
|
||||
} else {
|
||||
*bi += sprintf(buf + *bi, "CREATE");
|
||||
if (idx->flags & MDB_IDX_UNIQUE)
|
||||
*bi += sprintf(buf + *bi, " UNIQUE");
|
||||
*bi += sprintf(buf + *bi, " INDEX %s ON %s (", quoted_name, quoted_table_name);
|
||||
}
|
||||
g_free(quoted_name); //changed from free
|
||||
free(index_name);
|
||||
|
||||
for (j=0;j<idx->num_keys;j++) {
|
||||
|
||||
if (*bi > *bsize/2) { //extend the buffer if needed
|
||||
char *b;
|
||||
*bsize *= 2;
|
||||
b = (char*) g_realloc(buf, *bsize);
|
||||
buf = b;
|
||||
}
|
||||
|
||||
if (j)
|
||||
*bi += sprintf(buf + *bi, ", ");
|
||||
col= (MdbColumn*) g_ptr_array_index(table->columns,idx->key_col_num[j]-1);
|
||||
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||
*bi += sprintf(buf + *bi, "%s", quoted_name);
|
||||
if (idx->index_type!=1 && idx->key_col_order[j])
|
||||
/* no DESC for primary keys */
|
||||
*bi += sprintf(buf + *bi, " DESC");
|
||||
|
||||
g_free(quoted_name); //changed from free
|
||||
|
||||
}
|
||||
*bi += sprintf(buf + *bi, ");\n");
|
||||
}
|
||||
*bi += sprintf(buf + *bi, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* mdb_get_relationships
|
||||
* @mdb: Handle to open MDB database file
|
||||
@@ -529,7 +680,7 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
|
||||
gchar *text = NULL; /* String to be returned */
|
||||
static char *bound[5]; /* Bound values */
|
||||
static MdbTableDef *table; /* Relationships table */
|
||||
int backend = 0; /* Backends: 1=oracle, 2=postgres */
|
||||
int backend = 0; /* Backends: 1=oracle, 2=postgres, 3=sqlite */
|
||||
char *quoted_table_1, *quoted_column_1,
|
||||
*quoted_table_2, *quoted_column_2,
|
||||
*constraint_name, *quoted_constraint_name;
|
||||
@@ -539,6 +690,8 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
|
||||
backend = 1;
|
||||
} else if (!strcmp(mdb->backend_name, "postgres")) {
|
||||
backend = 2;
|
||||
} else if (!strcmp(mdb->backend_name, "sqlite")) {
|
||||
backend = 3;
|
||||
} else {
|
||||
if (is_init == 0) { /* the first time through */
|
||||
is_init = 1;
|
||||
@@ -601,7 +754,7 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
|
||||
grbit = atoi(bound[4]);
|
||||
constraint_name = g_strconcat(bound[1], "_", bound[0], "_fk", NULL);
|
||||
quoted_constraint_name = mdb->default_backend->quote_schema_name(dbnamespace, constraint_name);
|
||||
free(constraint_name);
|
||||
g_free(constraint_name); //changed from free
|
||||
|
||||
if (grbit & 0x00000002) {
|
||||
text = g_strconcat(
|
||||
@@ -613,6 +766,7 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
|
||||
switch (backend) {
|
||||
case 1: /* oracle */
|
||||
case 2: /* postgres */
|
||||
case 3: /* sqlite */
|
||||
text = g_strconcat(
|
||||
"ALTER TABLE ", quoted_table_1,
|
||||
" ADD CONSTRAINT ", quoted_constraint_name,
|
||||
@@ -625,16 +779,16 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(quoted_table_1);
|
||||
free(quoted_column_1);
|
||||
free(quoted_table_2);
|
||||
free(quoted_column_2);
|
||||
free(quoted_constraint_name);
|
||||
g_free(quoted_table_1); //changed from free
|
||||
g_free(quoted_column_1); //changed from free
|
||||
g_free(quoted_table_2); //changed from free
|
||||
g_free(quoted_column_2); //changed from free
|
||||
g_free(quoted_constraint_name); //changed from free
|
||||
|
||||
return (char *)text;
|
||||
}
|
||||
|
||||
static void
|
||||
/*static*/ void
|
||||
generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options)
|
||||
{
|
||||
MdbTableDef *table;
|
||||
@@ -668,7 +822,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
|
||||
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||
fprintf (outfile, "\t%s\t\t\t%s", quoted_name,
|
||||
mdb_get_colbacktype_string (col));
|
||||
free(quoted_name);
|
||||
g_free(quoted_name); //changed from free
|
||||
|
||||
if (mdb_colbacktype_takes_length(col)) {
|
||||
|
||||
@@ -693,15 +847,15 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
|
||||
if (export_options & MDB_SHEXP_DEFVALUES) {
|
||||
int done = 0;
|
||||
if (col->props) {
|
||||
gchar *defval = g_hash_table_lookup(col->props->hash, "DefaultValue");
|
||||
gchar *defval = (gchar*) g_hash_table_lookup(col->props->hash, "DefaultValue");
|
||||
if (defval) {
|
||||
size_t def_len = strlen(defval);
|
||||
fputs(" DEFAULT ", outfile);
|
||||
/* ugly hack to detect the type */
|
||||
if (defval[0]=='"' && defval[def_len-1]=='"') {
|
||||
/* this is a string */
|
||||
gchar *output_default = malloc(def_len-1);
|
||||
gchar *output_default_escaped = malloc(def_len-1);
|
||||
gchar *output_default = (gchar*) malloc(def_len-1);
|
||||
gchar *output_default_escaped/* = malloc(def_len-1)*/; //no need to malloc here, see two lines below
|
||||
memcpy(output_default, defval+1, def_len-2);
|
||||
output_default[def_len-2] = 0;
|
||||
output_default_escaped = quote_with_squotes(output_default);
|
||||
@@ -759,11 +913,11 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
|
||||
fprintf(outfile,
|
||||
mdb->default_backend->column_comment_statement,
|
||||
quoted_table_name, quoted_name, comment);
|
||||
free(comment);
|
||||
g_free(comment); //changed from free
|
||||
}
|
||||
}
|
||||
|
||||
free(quoted_name);
|
||||
g_free(quoted_name); //changed from free
|
||||
}
|
||||
|
||||
/* Add the constraints on table */
|
||||
@@ -774,7 +928,7 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
|
||||
fprintf(outfile,
|
||||
mdb->default_backend->table_comment_statement,
|
||||
quoted_table_name, comment);
|
||||
free(comment);
|
||||
g_free(comment); //changed from free
|
||||
}
|
||||
}
|
||||
fputc('\n', outfile);
|
||||
@@ -784,7 +938,181 @@ generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace,
|
||||
// prints all the indexes of that table
|
||||
mdb_print_indexes(outfile, table, dbnamespace);
|
||||
|
||||
free(quoted_table_name);
|
||||
g_free(quoted_table_name); //changed from free
|
||||
|
||||
mdb_free_tabledef (table);
|
||||
}
|
||||
|
||||
/** Does the same as the above but putting the data in buf.
|
||||
* In Windows there is no way to write to memory through a FILE pointer, and writing to disk slows down a lot
|
||||
*/
|
||||
void
|
||||
generate_table_schemas(char *buf, unsigned int *bi, unsigned int *bsize, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options)
|
||||
{
|
||||
MdbTableDef *table;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
MdbColumn *col;
|
||||
unsigned int i;
|
||||
char* quoted_table_name;
|
||||
char* quoted_name;
|
||||
MdbProperties *props;
|
||||
const char *prop_value;
|
||||
|
||||
quoted_table_name = mdb->default_backend->quote_schema_name(dbnamespace, entry->object_name);
|
||||
|
||||
/* drop the table if it exists */
|
||||
if (export_options & MDB_SHEXP_DROPTABLE)
|
||||
*bi = sprintf (buf, mdb->default_backend->drop_statement, quoted_table_name);
|
||||
|
||||
/* create the table */
|
||||
*bi += sprintf(buf + *bi, "CREATE TABLE %s\n", quoted_table_name);
|
||||
*bi += sprintf(buf + *bi, " (\n");
|
||||
|
||||
table = mdb_read_table (entry);
|
||||
|
||||
/* get the columns */
|
||||
mdb_read_columns (table);
|
||||
|
||||
/* loop over the columns, dumping the names and types */
|
||||
for (i = 0; i < table->num_cols; i++) {
|
||||
|
||||
if (*bi > *bsize/2) { //extend the buffer if needed
|
||||
char *b;
|
||||
*bsize *= 2;
|
||||
b = (char*) g_realloc(buf, *bsize);
|
||||
buf = b;
|
||||
}
|
||||
|
||||
col = (MdbColumn*) g_ptr_array_index (table->columns, i);
|
||||
|
||||
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||
*bi += sprintf(buf + *bi, "\t%s\t\t\t%s", quoted_name,
|
||||
mdb_get_colbacktype_string (col));
|
||||
g_free(quoted_name); //changed from free
|
||||
|
||||
if (mdb_colbacktype_takes_length(col)) {
|
||||
|
||||
/* more portable version from DW patch */
|
||||
if (col->col_size == 0)
|
||||
*bi += sprintf(buf + *bi, " (255)");
|
||||
else
|
||||
*bi += sprintf(buf + *bi, " (%d)", col->col_size);
|
||||
}
|
||||
|
||||
if (export_options & MDB_SHEXP_CST_NOTNULL) {
|
||||
if (col->col_type == MDB_BOOL) {
|
||||
/* access booleans are never null */
|
||||
*bi += sprintf(buf + *bi, " NOT NULL");
|
||||
} else {
|
||||
const gchar *not_null = mdb_col_get_prop(col, "Required");
|
||||
if (not_null && not_null[0]=='y')
|
||||
*bi += sprintf(buf + *bi, " NOT NULL");
|
||||
}
|
||||
}
|
||||
|
||||
if (export_options & MDB_SHEXP_DEFVALUES) {
|
||||
int done = 0;
|
||||
if (col->props) {
|
||||
gchar *defval = (gchar*) g_hash_table_lookup(col->props->hash, "DefaultValue");
|
||||
if (defval) {
|
||||
size_t def_len = strlen(defval);
|
||||
*bi += sprintf(buf + *bi, " DEFAULT ");
|
||||
/* ugly hack to detect the type */
|
||||
if (defval[0]=='"' && defval[def_len-1]=='"') {
|
||||
/* this is a string */
|
||||
gchar *output_default = (gchar*) malloc(def_len-1);
|
||||
gchar *output_default_escaped;
|
||||
memcpy(output_default, defval+1, def_len-2);
|
||||
output_default[def_len-2] = 0;
|
||||
output_default_escaped = quote_with_squotes(output_default);
|
||||
*bi += sprintf(buf + *bi, output_default_escaped);
|
||||
g_free(output_default_escaped);
|
||||
free(output_default);
|
||||
} else if (!strcmp(defval, "Yes"))
|
||||
*bi += sprintf(buf + *bi, "TRUE");
|
||||
else if (!strcmp(defval, "No"))
|
||||
*bi += sprintf(buf + *bi, "FALSE");
|
||||
else if (!strcasecmp(defval, "date()")) {
|
||||
if (!strcmp(mdb_col_get_prop(col, "Format"), "Short Date"))
|
||||
*bi += sprintf(buf + *bi, mdb->default_backend->short_now);
|
||||
else
|
||||
*bi += sprintf(buf + *bi, mdb->default_backend->long_now);
|
||||
}
|
||||
else
|
||||
*bi += sprintf(buf + *bi, defval);
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
if (!done && col->col_type == MDB_BOOL)
|
||||
/* access booleans are false by default */
|
||||
*bi += sprintf(buf + *bi, " DEFAULT FALSE");
|
||||
}
|
||||
if (i < table->num_cols - 1)
|
||||
*bi += sprintf(buf + *bi, ", \n");
|
||||
else
|
||||
*bi += sprintf(buf + *bi, "\n");
|
||||
} /* for */
|
||||
|
||||
*bi += sprintf(buf + *bi, ");\n");
|
||||
|
||||
/* Add the constraints on columns */
|
||||
for (i = 0; i < table->num_cols; i++) {
|
||||
|
||||
if (*bi > *bsize/2) { //extend the buffer if needed
|
||||
char *b;
|
||||
*bsize *= 2;
|
||||
b = (char*) g_realloc(buf, *bsize);
|
||||
buf = b;
|
||||
}
|
||||
|
||||
col = (MdbColumn*) g_ptr_array_index (table->columns, i);
|
||||
props = col->props;
|
||||
if (!props)
|
||||
continue;
|
||||
|
||||
quoted_name = mdb->default_backend->quote_schema_name(NULL, col->name);
|
||||
|
||||
if (export_options & MDB_SHEXP_CST_NOTEMPTY) {
|
||||
prop_value = mdb_col_get_prop(col, "AllowZeroLength");
|
||||
if (prop_value && prop_value[0]=='n')
|
||||
*bi += sprintf(buf + *bi,
|
||||
mdb->default_backend->constaint_not_empty_statement,
|
||||
quoted_table_name, quoted_name);
|
||||
}
|
||||
|
||||
if (export_options & MDB_SHEXP_COMMENTS) {
|
||||
prop_value = mdb_col_get_prop(col, "Description");
|
||||
if (prop_value) {
|
||||
char *comment = quote_with_squotes(prop_value);
|
||||
*bi += sprintf(buf + *bi,
|
||||
mdb->default_backend->column_comment_statement,
|
||||
quoted_table_name, quoted_name, comment);
|
||||
g_free(comment); //changed from free
|
||||
}
|
||||
}
|
||||
|
||||
g_free(quoted_name); //changed from free
|
||||
}
|
||||
|
||||
/* Add the constraints on table */
|
||||
if (export_options & MDB_SHEXP_COMMENTS) {
|
||||
prop_value = mdb_table_get_prop(table, "Description");
|
||||
if (prop_value) {
|
||||
char *comment = quote_with_squotes(prop_value);
|
||||
*bi += sprintf(buf + *bi,
|
||||
mdb->default_backend->table_comment_statement,
|
||||
quoted_table_name, comment);
|
||||
g_free(comment); //changed from free
|
||||
}
|
||||
}
|
||||
*bi += sprintf(buf + *bi, "\n");
|
||||
|
||||
|
||||
if (export_options & MDB_SHEXP_INDEXES)
|
||||
// prints all the indexes of that table
|
||||
mdb_print_indexess(buf, bi, bsize, table, dbnamespace);
|
||||
|
||||
g_free(quoted_table_name); //changed from free
|
||||
|
||||
mdb_free_tabledef (table);
|
||||
}
|
||||
@@ -796,6 +1124,7 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace
|
||||
unsigned int i;
|
||||
char *the_relation;
|
||||
MdbCatalogEntry *entry;
|
||||
const char *charset;
|
||||
|
||||
/* clear unsupported options */
|
||||
export_options &= mdb->default_backend->capabilities;
|
||||
@@ -811,14 +1140,14 @@ mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace
|
||||
"-- ----------------------------------------------------------\n\n",
|
||||
outfile);
|
||||
|
||||
const char *charset = mdb_target_charset(mdb);
|
||||
charset = mdb_target_charset(mdb);
|
||||
if (charset) {
|
||||
fprintf(outfile, mdb->default_backend->charset_statement, charset);
|
||||
fputc('\n', outfile);
|
||||
}
|
||||
|
||||
for (i=0; i < mdb->num_catalog; i++) {
|
||||
entry = g_ptr_array_index (mdb->catalog, i);
|
||||
entry = (MdbCatalogEntry *) g_ptr_array_index (mdb->catalog, i);
|
||||
if (entry->object_type == MDB_TABLE) {
|
||||
if ((tabname && !strcmp(entry->object_name, tabname))
|
||||
|| (!tabname && mdb_is_user_table(entry))) {
|
||||
|
||||
@@ -473,7 +473,7 @@ size_t
|
||||
mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr)
|
||||
{
|
||||
guint32 ole_len;
|
||||
void *buf;
|
||||
unsigned char* buf;
|
||||
int row_start;
|
||||
size_t len;
|
||||
|
||||
@@ -496,6 +496,7 @@ mdb_ole_read_next(MdbHandle *mdb, MdbColumn *col, void *ole_ptr)
|
||||
}
|
||||
mdb_debug(MDB_DEBUG_OLE,"start %d len %d", row_start, len);
|
||||
|
||||
|
||||
if (col->bind_ptr)
|
||||
memcpy(col->bind_ptr, buf + row_start + 4, len - 4);
|
||||
col->cur_blob_pg_row = mdb_get_int32(buf, row_start);
|
||||
@@ -506,7 +507,7 @@ size_t
|
||||
mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
|
||||
{
|
||||
guint32 ole_len;
|
||||
void *buf;
|
||||
unsigned char* buf;
|
||||
int row_start;
|
||||
size_t len;
|
||||
|
||||
@@ -536,7 +537,7 @@ mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
|
||||
col->cur_blob_pg_row >> 8);
|
||||
|
||||
if (mdb_find_pg_row(mdb, col->cur_blob_pg_row,
|
||||
&buf, &row_start, &len)) {
|
||||
(void**) &buf, &row_start, &len)) {
|
||||
return 0;
|
||||
}
|
||||
mdb_debug(MDB_DEBUG_OLE,"start %d len %d", row_start, len);
|
||||
@@ -554,7 +555,7 @@ mdb_ole_read(MdbHandle *mdb, MdbColumn *col, void *ole_ptr, int chunk_size)
|
||||
col->cur_blob_pg_row >> 8);
|
||||
|
||||
if (mdb_find_pg_row(mdb, col->cur_blob_pg_row,
|
||||
&buf, &row_start, &len)) {
|
||||
(void**) &buf, &row_start, &len)) {
|
||||
return 0;
|
||||
}
|
||||
mdb_debug(MDB_DEBUG_OLE,"start %d len %d", row_start, len);
|
||||
@@ -672,7 +673,7 @@ static char *mdb_memo_to_string(MdbHandle *mdb, int start, int size)
|
||||
guint32 memo_len;
|
||||
gint32 row_start, pg_row;
|
||||
size_t len;
|
||||
void *buf, *pg_buf = mdb->pg_buf;
|
||||
char *buf, *pg_buf = (char*) mdb->pg_buf;
|
||||
char *text = (char *) g_malloc(MDB_BIND_SIZE);
|
||||
|
||||
if (size<MDB_MEMO_OVERHEAD) {
|
||||
@@ -830,13 +831,17 @@ static char *
|
||||
mdb_date_to_string(MdbHandle *mdb, int start)
|
||||
{
|
||||
struct tm t;
|
||||
char *text = (char *) g_malloc(MDB_BIND_SIZE);
|
||||
char *text;
|
||||
double td = mdb_get_double(mdb->pg_buf, start);
|
||||
|
||||
mdb_date_to_tm(td, &t);
|
||||
|
||||
strftime(text, MDB_BIND_SIZE, date_fmt, &t);
|
||||
|
||||
//If td == 0, t->tm_year == -1, which fails the debug assertion >= 0
|
||||
if (!td) {
|
||||
text = (char *) g_strdup("00:00:00");
|
||||
} else {
|
||||
text = (char *) g_malloc(MDB_BIND_SIZE);
|
||||
mdb_date_to_tm(td, &t);
|
||||
strftime(text, MDB_BIND_SIZE, date_fmt, &t);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -892,7 +897,7 @@ int floor_log10(double f, int is_single)
|
||||
}
|
||||
#endif
|
||||
|
||||
char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int size)
|
||||
char *mdb_col_to_string(MdbHandle *mdb, char *buf, int start, int datatype, int size)
|
||||
{
|
||||
char *text = NULL;
|
||||
float tf;
|
||||
@@ -927,7 +932,7 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int
|
||||
if (size<0) {
|
||||
text = g_strdup("");
|
||||
} else {
|
||||
text = g_malloc(size);
|
||||
text = (char *) g_malloc(size);
|
||||
memcpy((char*)buf+start, text, size);
|
||||
}
|
||||
case MDB_TEXT:
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "mdbtools.h"
|
||||
#include <inttypes.h>
|
||||
//#include <inttypes.h>
|
||||
|
||||
#ifdef DMALLOC
|
||||
#include "dmalloc.h"
|
||||
@@ -174,6 +174,7 @@ MdbHandle *mdb_open(const char *filename, MdbFileFlags flags)
|
||||
int open_flags;
|
||||
|
||||
mdb = (MdbHandle *) g_malloc0(sizeof(MdbHandle));
|
||||
mdb_init_backends();
|
||||
mdb_set_default_backend(mdb, "access");
|
||||
#ifdef HAVE_ICONV
|
||||
mdb->iconv_in = (iconv_t)-1;
|
||||
@@ -284,6 +285,7 @@ void
|
||||
mdb_close(MdbHandle *mdb)
|
||||
{
|
||||
if (!mdb) return;
|
||||
mdb_remove_backends();
|
||||
mdb_free_catalog(mdb);
|
||||
g_free(mdb->stats);
|
||||
g_free(mdb->backend_name);
|
||||
@@ -299,7 +301,7 @@ mdb_close(MdbHandle *mdb)
|
||||
}
|
||||
|
||||
mdb_iconv_close(mdb);
|
||||
|
||||
|
||||
g_free(mdb);
|
||||
}
|
||||
/**
|
||||
@@ -365,7 +367,7 @@ static ssize_t _mdb_read_pg(MdbHandle *mdb, void *pg_buf, unsigned long pg)
|
||||
|
||||
fstat(mdb->f->fd, &status);
|
||||
if (status.st_size < offset) {
|
||||
fprintf(stderr,"offset %jd is beyond EOF\n",(intmax_t)offset);
|
||||
fprintf(stderr,"offset %jd is beyond EOF\n",offset);
|
||||
return 0;
|
||||
}
|
||||
if (mdb->stats && mdb->stats->collect)
|
||||
@@ -416,7 +418,7 @@ unsigned char mdb_pg_get_byte(MdbHandle *mdb, int offset)
|
||||
return mdb->pg_buf[offset];
|
||||
}
|
||||
|
||||
int mdb_get_int16(void *buf, int offset)
|
||||
int mdb_get_int16(unsigned char *buf, int offset)
|
||||
{
|
||||
guint16 l;
|
||||
memcpy(&l, buf + offset, 2);
|
||||
@@ -429,13 +431,13 @@ int mdb_pg_get_int16(MdbHandle *mdb, int offset)
|
||||
return mdb_get_int16(mdb->pg_buf, offset);
|
||||
}
|
||||
|
||||
long mdb_get_int32_msb(void *buf, int offset)
|
||||
long mdb_get_int32_msb(unsigned char *buf, int offset)
|
||||
{
|
||||
gint32 l;
|
||||
memcpy(&l, buf + offset, 4);
|
||||
return (long)GINT32_FROM_BE(l);
|
||||
}
|
||||
long mdb_get_int32(void *buf, int offset)
|
||||
long mdb_get_int32(unsigned char *buf, int offset)
|
||||
{
|
||||
gint32 l;
|
||||
memcpy(&l, buf + offset, 4);
|
||||
@@ -448,7 +450,7 @@ long mdb_pg_get_int32(MdbHandle *mdb, int offset)
|
||||
return mdb_get_int32(mdb->pg_buf, offset);
|
||||
}
|
||||
|
||||
float mdb_get_single(void *buf, int offset)
|
||||
float mdb_get_single(unsigned char *buf, int offset)
|
||||
{
|
||||
union {guint32 g; float f;} f;
|
||||
memcpy(&f, buf + offset, 4);
|
||||
@@ -462,7 +464,7 @@ float mdb_pg_get_single(MdbHandle *mdb, int offset)
|
||||
return mdb_get_single(mdb->pg_buf, offset);
|
||||
}
|
||||
|
||||
double mdb_get_double(void *buf, int offset)
|
||||
double mdb_get_double(unsigned char *buf, int offset)
|
||||
{
|
||||
union {guint64 g; double d;} d;
|
||||
memcpy(&d, buf + offset, 8);
|
||||
|
||||
20
src/libmdb/libmdb.sln
Normal file
20
src/libmdb/libmdb.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmdb", "libmdb.vcxproj", "{9D8A6CF2-D072-4265-986E-558CC01EFF3F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9D8A6CF2-D072-4265-986E-558CC01EFF3F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9D8A6CF2-D072-4265-986E-558CC01EFF3F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9D8A6CF2-D072-4265-986E-558CC01EFF3F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9D8A6CF2-D072-4265-986E-558CC01EFF3F}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
105
src/libmdb/libmdb.vcxproj
Normal file
105
src/libmdb/libmdb.vcxproj
Normal file
@@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9D8A6CF2-D072-4265-986E-558CC01EFF3F}</ProjectGuid>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<Keyword>ManagedCProj</Keyword>
|
||||
<RootNamespace>libmdb</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CLRSupport>false</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CLRSupport>false</CLRSupport>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>..\..\include;.\glib</AdditionalIncludeDirectories>
|
||||
<CompileAsManaged>false</CompileAsManaged>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>
|
||||
</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<AdditionalIncludeDirectories>..\..\include;.\glib</AdditionalIncludeDirectories>
|
||||
<CompileAsManaged>false</CompileAsManaged>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>
|
||||
</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="backend.c" />
|
||||
<ClCompile Include="catalog.c" />
|
||||
<ClCompile Include="data.c" />
|
||||
<ClCompile Include="dump.c" />
|
||||
<ClCompile Include="file.c" />
|
||||
<ClCompile Include="iconv.c" />
|
||||
<ClCompile Include="index.c" />
|
||||
<ClCompile Include="like.c" />
|
||||
<ClCompile Include="map.c" />
|
||||
<ClCompile Include="mem.c" />
|
||||
<ClCompile Include="money.c" />
|
||||
<ClCompile Include="options.c" />
|
||||
<ClCompile Include="props.c" />
|
||||
<ClCompile Include="sargs.c" />
|
||||
<ClCompile Include="stats.c" />
|
||||
<ClCompile Include="table.c" />
|
||||
<ClCompile Include="worktable.c" />
|
||||
<ClCompile Include="write.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
69
src/libmdb/libmdb.vcxproj.filters
Normal file
69
src/libmdb/libmdb.vcxproj.filters
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="backend.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="catalog.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="data.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="dump.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="file.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="iconv.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="index.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="like.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="map.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="mem.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="money.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="options.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="props.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sargs.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stats.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="table.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="worktable.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="write.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
#include "mdbtools.h"
|
||||
|
||||
void __attribute__((deprecated)) mdb_init()
|
||||
void mdb_init()
|
||||
{
|
||||
fprintf(stderr, "mdb_init() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||
}
|
||||
|
||||
void __attribute__((deprecated)) mdb_exit()
|
||||
void mdb_exit()
|
||||
{
|
||||
fprintf(stderr, "mdb_exit() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ char *mdb_money_to_string(MdbHandle *mdb, int start)
|
||||
int neg=0;
|
||||
unsigned char multiplier[MAX_NUMERIC_PRECISION], temp[MAX_NUMERIC_PRECISION];
|
||||
unsigned char product[MAX_NUMERIC_PRECISION];
|
||||
unsigned char bytes[num_bytes];
|
||||
unsigned char bytes[8];
|
||||
|
||||
memset(multiplier,0,MAX_NUMERIC_PRECISION);
|
||||
memset(product,0,MAX_NUMERIC_PRECISION);
|
||||
@@ -85,7 +85,7 @@ char *mdb_numeric_to_string(MdbHandle *mdb, int start, int prec, int scale) {
|
||||
int neg=0;
|
||||
unsigned char multiplier[MAX_NUMERIC_PRECISION], temp[MAX_NUMERIC_PRECISION];
|
||||
unsigned char product[MAX_NUMERIC_PRECISION];
|
||||
unsigned char bytes[num_bytes];
|
||||
unsigned char bytes[16];
|
||||
|
||||
memset(multiplier,0,MAX_NUMERIC_PRECISION);
|
||||
memset(product,0,MAX_NUMERIC_PRECISION);
|
||||
|
||||
@@ -25,9 +25,9 @@ mdb_read_props_list(MdbHandle *mdb, gchar *kkd, int len)
|
||||
int pos = 0;
|
||||
gchar *name;
|
||||
GPtrArray *names = NULL;
|
||||
int i=0;
|
||||
|
||||
names = g_ptr_array_new();
|
||||
int i=0;
|
||||
#if MDB_DEBUG
|
||||
mdb_buffer_dump(kkd, 0, len);
|
||||
#endif
|
||||
@@ -151,24 +151,26 @@ mdb_dump_props(MdbProperties *props, FILE *outfile, int show_name) {
|
||||
* and returns a GPtrArray of MdbProps*
|
||||
*/
|
||||
GArray*
|
||||
mdb_kkd_to_props(MdbHandle *mdb, void *buffer, size_t len) {
|
||||
mdb_kkd_to_props(MdbHandle *mdb, char *buffer, size_t len) {
|
||||
guint32 record_len;
|
||||
guint16 record_type;
|
||||
size_t pos;
|
||||
GPtrArray *names = NULL;
|
||||
MdbProperties *props;
|
||||
GArray *result;
|
||||
|
||||
#if MDB_DEBUG
|
||||
mdb_buffer_dump(buffer, 0, len);
|
||||
#endif
|
||||
mdb_debug(MDB_DEBUG_PROPS,"starting prop parsing of type %s", buffer);
|
||||
|
||||
if (strcmp("KKD", buffer) && strcmp("MR2", buffer)) {
|
||||
fprintf(stderr, "Unrecognized format.\n");
|
||||
mdb_buffer_dump(buffer, 0, len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GArray *result = g_array_new(0, 0, sizeof(MdbProperties*));
|
||||
result = g_array_new(0, 0, sizeof(MdbProperties*));
|
||||
|
||||
pos = 4;
|
||||
while (pos < len) {
|
||||
|
||||
@@ -76,7 +76,7 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
MdbFormatConstants *fmt = mdb->fmt;
|
||||
int row_start, pg_row;
|
||||
void *buf, *pg_buf = mdb->pg_buf;
|
||||
unsigned char *buf, *pg_buf = mdb->pg_buf;
|
||||
guint i;
|
||||
|
||||
mdb_read_pg(mdb, entry->table_pg);
|
||||
@@ -94,8 +94,8 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
|
||||
|
||||
/* grab a copy of the usage map */
|
||||
pg_row = mdb_get_int32(pg_buf, fmt->tab_usage_map_offset);
|
||||
mdb_find_pg_row(mdb, pg_row, &buf, &row_start, &(table->map_sz));
|
||||
table->usage_map = g_memdup(buf + row_start, table->map_sz);
|
||||
mdb_find_pg_row(mdb, pg_row, (void**) &buf, &row_start, &(table->map_sz));
|
||||
table->usage_map = (unsigned char*) g_memdup(buf + row_start, table->map_sz);
|
||||
if (mdb_get_option(MDB_DEBUG_USAGE))
|
||||
mdb_buffer_dump(buf, row_start, table->map_sz);
|
||||
mdb_debug(MDB_DEBUG_USAGE,"usage map found on page %ld row %d start %d len %d",
|
||||
@@ -103,8 +103,8 @@ MdbTableDef *mdb_read_table(MdbCatalogEntry *entry)
|
||||
|
||||
/* grab a copy of the free space page map */
|
||||
pg_row = mdb_get_int32(pg_buf, fmt->tab_free_map_offset);
|
||||
mdb_find_pg_row(mdb, pg_row, &buf, &row_start, &(table->freemap_sz));
|
||||
table->free_usage_map = g_memdup(buf + row_start, table->freemap_sz);
|
||||
mdb_find_pg_row(mdb, pg_row, (void**) &buf, &row_start, &(table->freemap_sz));
|
||||
table->free_usage_map = (unsigned char*) g_memdup(buf + row_start, table->freemap_sz);
|
||||
mdb_debug(MDB_DEBUG_USAGE,"free map found on page %ld row %d start %d len %d\n",
|
||||
pg_row >> 8, pg_row & 0xff, row_start, table->freemap_sz);
|
||||
|
||||
@@ -127,7 +127,7 @@ MdbTableDef *mdb_read_table_by_name(MdbHandle *mdb, gchar *table_name, int obj_t
|
||||
mdb_read_catalog(mdb, obj_type);
|
||||
|
||||
for (i=0; i<mdb->num_catalog; i++) {
|
||||
entry = g_ptr_array_index(mdb->catalog, i);
|
||||
entry = (MdbCatalogEntry *) g_ptr_array_index(mdb->catalog, i);
|
||||
if (!strcasecmp(entry->object_name, table_name))
|
||||
return mdb_read_table(entry);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ read_pg_if_8(MdbHandle *mdb, int *cur_pos)
|
||||
* are still advanced and the page cursor is still updated.
|
||||
*/
|
||||
void *
|
||||
read_pg_if_n(MdbHandle *mdb, void *buf, int *cur_pos, size_t len)
|
||||
read_pg_if_n(MdbHandle *mdb, unsigned char *buf, int *cur_pos, size_t len)
|
||||
{
|
||||
/* Advance to page which contains the first byte */
|
||||
while (*cur_pos >= mdb->fmt->pg_size) {
|
||||
@@ -215,6 +215,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
||||
unsigned int i, j;
|
||||
int cur_pos;
|
||||
size_t name_sz;
|
||||
GArray *allprops;
|
||||
|
||||
table->columns = g_ptr_array_new();
|
||||
|
||||
@@ -302,7 +303,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
|
||||
/* Sort the columns by col_num */
|
||||
g_ptr_array_sort(table->columns, (GCompareFunc)mdb_col_comparer);
|
||||
|
||||
GArray *allprops = table->entry->props;
|
||||
allprops = table->entry->props;
|
||||
if (allprops)
|
||||
for (i=0;i<table->num_cols;i++) {
|
||||
pcol = g_ptr_array_index(table->columns, i);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "mdbtools.h"
|
||||
#include "time.h"
|
||||
#include "math.h"
|
||||
#include <inttypes.h>
|
||||
//#include <inttypes.h>
|
||||
|
||||
#ifdef DMALLOC
|
||||
#include "dmalloc.h"
|
||||
@@ -30,7 +30,7 @@
|
||||
static int mdb_add_row_to_leaf_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg, MdbField *idx_fields, guint32 pgnum, guint16 rownum);
|
||||
|
||||
void
|
||||
mdb_put_int16(void *buf, guint32 offset, guint32 value)
|
||||
mdb_put_int16(unsigned char *buf, guint32 offset, guint32 value)
|
||||
{
|
||||
value = GINT32_TO_LE(value);
|
||||
memcpy(buf + offset, &value, 2);
|
||||
@@ -44,7 +44,7 @@ __attribute__((alias("mdb_put_int16")));
|
||||
#endif
|
||||
|
||||
void
|
||||
mdb_put_int32(void *buf, guint32 offset, guint32 value)
|
||||
mdb_put_int32(unsigned char *buf, guint32 offset, guint32 value)
|
||||
{
|
||||
value = GINT32_TO_LE(value);
|
||||
memcpy(buf + offset, &value, 4);
|
||||
@@ -58,7 +58,7 @@ __attribute__((alias("mdb_put_int32")));
|
||||
#endif
|
||||
|
||||
void
|
||||
mdb_put_int32_msb(void *buf, guint32 offset, guint32 value)
|
||||
mdb_put_int32_msb(unsigned char *buf, guint32 offset, guint32 value)
|
||||
{
|
||||
value = GINT32_TO_BE(value);
|
||||
memcpy(buf + offset, &value, 4);
|
||||
@@ -81,7 +81,7 @@ mdb_write_pg(MdbHandle *mdb, unsigned long pg)
|
||||
fstat(mdb->f->fd, &status);
|
||||
/* is page beyond current size + 1 ? */
|
||||
if (status.st_size < offset + mdb->fmt->pg_size) {
|
||||
fprintf(stderr,"offset %jd is beyond EOF\n",(intmax_t)offset);
|
||||
fprintf(stderr,"offset %jd is beyond EOF\n",offset);
|
||||
return 0;
|
||||
}
|
||||
lseek(mdb->f->fd, offset, SEEK_SET);
|
||||
@@ -172,7 +172,7 @@ mdb_crack_row(MdbTableDef *table, int row_start, int row_end, MdbField *fields)
|
||||
MdbColumn *col;
|
||||
MdbCatalogEntry *entry = table->entry;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
void *pg_buf = mdb->pg_buf;
|
||||
unsigned char *pg_buf = mdb->pg_buf;
|
||||
unsigned int row_var_cols=0, row_cols;
|
||||
unsigned char *nullmask;
|
||||
unsigned int bitmask_sz;
|
||||
@@ -594,7 +594,7 @@ mdb_insert_row(MdbTableDef *table, int num_fields, MdbField *fields)
|
||||
guint16
|
||||
mdb_add_row_to_pg(MdbTableDef *table, unsigned char *row_buffer, int new_row_size)
|
||||
{
|
||||
void *new_pg;
|
||||
unsigned char *new_pg;
|
||||
int num_rows, i, pos, row_start;
|
||||
size_t row_size;
|
||||
MdbCatalogEntry *entry = table->entry;
|
||||
@@ -725,7 +725,7 @@ MdbCatalogEntry *entry = table->entry;
|
||||
MdbHandle *mdb = entry->mdb;
|
||||
int pg_size = mdb->fmt->pg_size;
|
||||
int rco = mdb->fmt->row_count_offset;
|
||||
void *new_pg;
|
||||
unsigned char *new_pg;
|
||||
guint16 num_rows;
|
||||
int row_start;
|
||||
size_t row_size;
|
||||
@@ -793,7 +793,7 @@ mdb_copy_index_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg)
|
||||
MdbColumn *col;
|
||||
guint32 pg_row;
|
||||
guint16 row = 0;
|
||||
void *new_pg;
|
||||
unsigned char *new_pg;
|
||||
unsigned char key_hash[256];
|
||||
int keycol;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user