mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-11-25 17:59:54 +08:00
MDB_DEPRECATED redefined, Constructor MACRO, generate_table_schema changed to not static, date_fmt to ISODate
__attribute__ does not exist in Visual Studio. Therefore replaced wherever it appeared with a macro: Redefines MDB_DEPRECATED to support Visual Studio Define a Constructor MACRO so that __attribute__((constructor/destructor)) behavior is achieved in Visual Studio. Just using generate_table_schema through mdb_print_schema deletes the purpose of a very good tool. generate_table_schemas is a rewrite of generate_table_schema but sends the data to a char* instead of FILE*. There is NO fmemopen() or similar in Visual Studio, so there is NO way to access memory through a FILE* except for first writing to the disk and then reading from the disk in memory. I cannot suggest how to handle the case when td == 0 for the dates. The databases I work with often have just 00:00:00 in the DateTime column which is not consistent with the rest of the column either, but I have to deal with it somehow. Leaving void* where char* is needed as a function parameter returns a compilation error in Visual Studio.
This commit is contained in:
@@ -50,7 +50,13 @@
|
|||||||
#define MDB_MEMO_OVERHEAD 12
|
#define MDB_MEMO_OVERHEAD 12
|
||||||
#define MDB_BIND_SIZE 16384
|
#define MDB_BIND_SIZE 16384
|
||||||
|
|
||||||
#define MDB_DEPRECATED __attribute__((deprecated))
|
#ifndef _WIN32
|
||||||
|
#define MDB_DEPRECATED(type, func) type __attribute__((deprecated)) func
|
||||||
|
#else
|
||||||
|
#define MDB_DEPRECATED(type, func) __declspec(deprecated) type func
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS 1
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MDB_PAGE_DB = 0,
|
MDB_PAGE_DB = 0,
|
||||||
@@ -437,8 +443,8 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* mem.c */
|
/* mem.c */
|
||||||
extern void MDB_DEPRECATED mdb_init();
|
extern MDB_DEPRECATED(void, mdb_init());
|
||||||
extern void MDB_DEPRECATED mdb_exit();
|
extern MDB_DEPRECATED(void, mdb_exit());
|
||||||
|
|
||||||
/* file.c */
|
/* file.c */
|
||||||
extern ssize_t mdb_read_pg(MdbHandle *mdb, unsigned long pg);
|
extern ssize_t mdb_read_pg(MdbHandle *mdb, unsigned long pg);
|
||||||
@@ -508,14 +514,14 @@ extern int mdb_read_row(MdbTableDef *table, unsigned int row);
|
|||||||
extern void mdb_buffer_dump(const void *buf, int start, size_t len);
|
extern void mdb_buffer_dump(const void *buf, int start, size_t len);
|
||||||
|
|
||||||
/* backend.c */
|
/* backend.c */
|
||||||
extern char* MDB_DEPRECATED mdb_get_coltype_string(MdbBackend *backend, int col_type);
|
extern MDB_DEPRECATED(char*, mdb_get_coltype_string(MdbBackend *backend, int col_type));
|
||||||
extern int MDB_DEPRECATED mdb_coltype_takes_length(MdbBackend *backend, int col_type);
|
extern MDB_DEPRECATED(int, mdb_coltype_takes_length(MdbBackend *backend, int col_type));
|
||||||
extern const MdbBackendType* mdb_get_colbacktype(const MdbColumn *col);
|
extern const MdbBackendType* mdb_get_colbacktype(const MdbColumn *col);
|
||||||
extern const char* mdb_get_colbacktype_string(const MdbColumn *col);
|
extern const char* mdb_get_colbacktype_string(const MdbColumn *col);
|
||||||
extern int mdb_colbacktype_takes_length(const MdbColumn *col);
|
extern int mdb_colbacktype_takes_length(const MdbColumn *col);
|
||||||
extern void MDB_DEPRECATED mdb_init_backends();
|
extern MDB_DEPRECATED(void, mdb_init_backends());
|
||||||
extern 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*));
|
extern 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*));
|
||||||
extern void MDB_DEPRECATED mdb_remove_backends();
|
extern MDB_DEPRECATED(void, mdb_remove_backends());
|
||||||
extern int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name);
|
extern int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name);
|
||||||
extern void generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options);
|
extern void generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options);
|
||||||
extern void generate_table_schemas(char *buf, unsigned int *bi, unsigned int *bsize, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options);
|
extern void generate_table_schemas(char *buf, unsigned int *bi, unsigned int *bsize, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options);
|
||||||
|
|||||||
@@ -259,8 +259,8 @@ quote_with_squotes(const gchar* value)
|
|||||||
return quote_generic(value, '\'', '\'');
|
return quote_generic(value, '\'', '\'');
|
||||||
}
|
}
|
||||||
|
|
||||||
char * MDB_DEPRECATED
|
MDB_DEPRECATED (char *,
|
||||||
mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
mdb_get_coltype_string(MdbBackend *backend, int col_type))
|
||||||
{
|
{
|
||||||
static int warn_deprecated = 0;
|
static int warn_deprecated = 0;
|
||||||
static char buf[16];
|
static char buf[16];
|
||||||
@@ -277,8 +277,8 @@ mdb_get_coltype_string(MdbBackend *backend, int col_type)
|
|||||||
return backend->types_table[col_type].name;
|
return backend->types_table[col_type].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MDB_DEPRECATED
|
MDB_DEPRECATED (int,
|
||||||
mdb_coltype_takes_length(MdbBackend *backend, int col_type)
|
mdb_coltype_takes_length(MdbBackend *backend, int col_type))
|
||||||
{
|
{
|
||||||
static int warn_deprecated = 0;
|
static int warn_deprecated = 0;
|
||||||
if (!warn_deprecated) {
|
if (!warn_deprecated) {
|
||||||
@@ -325,17 +325,47 @@ mdb_colbacktype_takes_length(const MdbColumn *col)
|
|||||||
return type->needs_length;
|
return type->needs_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MDB_DEPRECATED mdb_init_backends() {
|
MDB_DEPRECATED(void, mdb_init_backends()) {
|
||||||
fprintf(stderr, "mdb_init_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
fprintf(stderr, "mdb_init_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
|
#define CCALL __cdecl
|
||||||
|
#pragma section(".CRT$XCU",read)
|
||||||
|
#define INITIALIZER(f) \
|
||||||
|
static void __cdecl f(void); \
|
||||||
|
__declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \
|
||||||
|
static void __cdecl f(void)
|
||||||
|
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
|
||||||
|
#define CCALL
|
||||||
|
#define INITIALIZER(f) \
|
||||||
|
static void f(void) __attribute__((constructor));
|
||||||
|
static void f(void)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mdb_remove_backends
|
||||||
|
*
|
||||||
|
* Removes all entries from and destroys the mdb_backends hash.
|
||||||
|
*/
|
||||||
|
static void CCALL _mdb_remove_backends(void)
|
||||||
|
{
|
||||||
|
g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL);
|
||||||
|
g_hash_table_destroy(mdb_backends);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _mdb_init_backends
|
* _mdb_init_backends
|
||||||
*
|
*
|
||||||
* Initializes the mdb_backends hash and loads the builtin backends.
|
* Initializes the mdb_backends hash and loads the builtin backends.
|
||||||
* Use mdb_remove_backends() to destroy this hash when done.
|
* Use mdb_remove_backends() to destroy this hash when done.
|
||||||
*/
|
*/
|
||||||
void __attribute__ ((constructor)) _mdb_init_backends()
|
INITIALIZER(_mdb_init_backends)
|
||||||
{
|
{
|
||||||
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
|
mdb_backends = g_hash_table_new(g_str_hash, g_str_equal);
|
||||||
|
|
||||||
@@ -399,6 +429,8 @@ void __attribute__ ((constructor)) _mdb_init_backends()
|
|||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
quote_schema_name_rquotes_merge);
|
quote_schema_name_rquotes_merge);
|
||||||
|
|
||||||
|
atexit(_mdb_remove_backends);
|
||||||
}
|
}
|
||||||
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*))
|
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*))
|
||||||
{
|
{
|
||||||
@@ -418,20 +450,10 @@ void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendTy
|
|||||||
g_hash_table_insert(mdb_backends, backend_name, backend);
|
g_hash_table_insert(mdb_backends, backend_name, backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MDB_DEPRECATED mdb_remove_backends() {
|
MDB_DEPRECATED(void, mdb_remove_backends()) {
|
||||||
fprintf(stderr, "mdb_remove_backends() is DEPRECATED and does nothing. Stop calling it.\n");
|
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()
|
|
||||||
{
|
|
||||||
g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL);
|
|
||||||
g_hash_table_destroy(mdb_backends);
|
|
||||||
}
|
|
||||||
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data)
|
static gboolean mdb_drop_backend(gpointer key, gpointer value, gpointer data)
|
||||||
{
|
{
|
||||||
MdbBackend *backend = (MdbBackend *)value;
|
MdbBackend *backend = (MdbBackend *)value;
|
||||||
@@ -760,7 +782,7 @@ mdb_get_relationships(MdbHandle *mdb, const gchar *dbnamespace, const char* tabl
|
|||||||
return (char *)text;
|
return (char *)text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ void
|
void
|
||||||
generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options)
|
generate_table_schema(FILE *outfile, MdbCatalogEntry *entry, char *dbnamespace, guint32 export_options)
|
||||||
{
|
{
|
||||||
MdbTableDef *table;
|
MdbTableDef *table;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ static char *mdb_date_to_string(MdbHandle *mdb, int start);
|
|||||||
static size_t mdb_copy_ole(MdbHandle *mdb, void *dest, int start, int size);
|
static size_t mdb_copy_ole(MdbHandle *mdb, void *dest, int start, int size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char date_fmt[64] = "%x %X";
|
static char date_fmt[64] = "%Y-%m-%dT%H:%M:%S"; //ISODate
|
||||||
|
|
||||||
void mdb_set_date_fmt(const char *fmt)
|
void mdb_set_date_fmt(const char *fmt)
|
||||||
{
|
{
|
||||||
@@ -836,7 +836,7 @@ mdb_date_to_string(MdbHandle *mdb, int start)
|
|||||||
|
|
||||||
//If td == 0, t->tm_year == -1, which fails the debug assertion >= 0
|
//If td == 0, t->tm_year == -1, which fails the debug assertion >= 0
|
||||||
if (!td) {
|
if (!td) {
|
||||||
text = (char *) g_strdup("00:00:00");
|
text = (char *) g_strdup("0");
|
||||||
} else {
|
} else {
|
||||||
text = (char *) g_malloc(MDB_BIND_SIZE);
|
text = (char *) g_malloc(MDB_BIND_SIZE);
|
||||||
mdb_date_to_tm(td, &t);
|
mdb_date_to_tm(td, &t);
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mdbtools.h"
|
#include "mdbtools.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
//#include <inttypes.h>
|
//#include <inttypes.h>
|
||||||
|
|
||||||
#ifdef DMALLOC
|
#ifdef DMALLOC
|
||||||
@@ -174,7 +177,6 @@ MdbHandle *mdb_open(const char *filename, MdbFileFlags flags)
|
|||||||
int open_flags;
|
int open_flags;
|
||||||
|
|
||||||
mdb = (MdbHandle *) g_malloc0(sizeof(MdbHandle));
|
mdb = (MdbHandle *) g_malloc0(sizeof(MdbHandle));
|
||||||
mdb_init_backends();
|
|
||||||
mdb_set_default_backend(mdb, "access");
|
mdb_set_default_backend(mdb, "access");
|
||||||
#ifdef HAVE_ICONV
|
#ifdef HAVE_ICONV
|
||||||
mdb->iconv_in = (iconv_t)-1;
|
mdb->iconv_in = (iconv_t)-1;
|
||||||
@@ -261,7 +263,7 @@ MdbHandle *mdb_open(const char *filename, MdbFileFlags flags)
|
|||||||
|
|
||||||
/* get the db password located at 0x42 bytes into the file */
|
/* get the db password located at 0x42 bytes into the file */
|
||||||
for (pos=0;pos<14;pos++) {
|
for (pos=0;pos<14;pos++) {
|
||||||
j = mdb_get_int32(mdb,0x42+pos);
|
j = mdb_get_int32(mdb,0x42+pos); //warning C4133: 'function' : incompatible types - from 'MdbHandle *' to 'unsigned char *'
|
||||||
j ^= key[pos];
|
j ^= key[pos];
|
||||||
if ( j != 0)
|
if ( j != 0)
|
||||||
mdb->f->db_passwd[pos] = j;
|
mdb->f->db_passwd[pos] = j;
|
||||||
@@ -285,7 +287,6 @@ void
|
|||||||
mdb_close(MdbHandle *mdb)
|
mdb_close(MdbHandle *mdb)
|
||||||
{
|
{
|
||||||
if (!mdb) return;
|
if (!mdb) return;
|
||||||
mdb_remove_backends();
|
|
||||||
mdb_free_catalog(mdb);
|
mdb_free_catalog(mdb);
|
||||||
g_free(mdb->stats);
|
g_free(mdb->stats);
|
||||||
g_free(mdb->backend_name);
|
g_free(mdb->backend_name);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<AdditionalIncludeDirectories>..\..\include;.\glib</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\include;.\glib</AdditionalIncludeDirectories>
|
||||||
<CompileAsManaged>false</CompileAsManaged>
|
<CompileAsManaged>false</CompileAsManaged>
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
<AdditionalIncludeDirectories>..\..\include;.\glib</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>..\..\include;.\glib</AdditionalIncludeDirectories>
|
||||||
<CompileAsManaged>false</CompileAsManaged>
|
<CompileAsManaged>false</CompileAsManaged>
|
||||||
|
|||||||
@@ -18,12 +18,12 @@
|
|||||||
|
|
||||||
#include "mdbtools.h"
|
#include "mdbtools.h"
|
||||||
|
|
||||||
void MDB_DEPRECATED mdb_init()
|
MDB_DEPRECATED (void, mdb_init())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "mdb_init() is DEPRECATED and does nothing. Stop calling it.\n");
|
fprintf(stderr, "mdb_init() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MDB_DEPRECATED mdb_exit()
|
MDB_DEPRECATED(void, mdb_exit())
|
||||||
{
|
{
|
||||||
fprintf(stderr, "mdb_exit() is DEPRECATED and does nothing. Stop calling it.\n");
|
fprintf(stderr, "mdb_exit() is DEPRECATED and does nothing. Stop calling it.\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@
|
|||||||
#include "mdbtools.h"
|
#include "mdbtools.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
//#include <inttypes.h>
|
//#include <inttypes.h>
|
||||||
|
|
||||||
#ifdef DMALLOC
|
#ifdef DMALLOC
|
||||||
|
|||||||
Reference in New Issue
Block a user