mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-02-26 05:33:03 +08:00
Improved support for "Short Date" fields
* Separate -D (date only) and -T (date/time) format options in mdb-export and mdb-json * New public mdb_set_shortdate_fmt() function in libmdb * New private(ish) mdb_col_is_shortdate() function I'm calling it "shortdate" in order to preserve the existing API. See https://github.com/mdbtools/mdbtools/issues/12
This commit is contained in:
@@ -253,11 +253,6 @@ quote_with_squotes(const gchar* value)
|
||||
return quote_generic(value, '\'', '\'');
|
||||
}
|
||||
|
||||
static int mdb_col_is_shortdate(const MdbColumn *col) {
|
||||
const char *format = mdb_col_get_prop(col, "Format");
|
||||
return format && !strcmp(format, "Short Date");
|
||||
}
|
||||
|
||||
const MdbBackendType*
|
||||
mdb_get_colbacktype(const MdbColumn *col) {
|
||||
MdbBackend *backend = col->table->entry->mdb->default_backend;
|
||||
|
||||
@@ -29,7 +29,7 @@ char *mdb_numeric_to_string(MdbHandle *mdb, int start, int prec, int scale);
|
||||
|
||||
static int _mdb_attempt_bind(MdbHandle *mdb,
|
||||
MdbColumn *col, unsigned char isnull, int offset, int len);
|
||||
static char *mdb_date_to_string(MdbHandle *mdb, void *buf, int start);
|
||||
static char *mdb_date_to_string(MdbHandle *mdb, const char *fmt, void *buf, int start);
|
||||
#ifdef MDB_COPY_OLE
|
||||
static size_t mdb_copy_ole(MdbHandle *mdb, void *dest, int start, int size);
|
||||
#endif
|
||||
@@ -56,6 +56,11 @@ void mdb_set_date_fmt(MdbHandle *mdb, const char *fmt)
|
||||
snprintf(mdb->date_fmt, sizeof(mdb->date_fmt), "%s", fmt);
|
||||
}
|
||||
|
||||
void mdb_set_shortdate_fmt(MdbHandle *mdb, const char *fmt)
|
||||
{
|
||||
snprintf(mdb->shortdate_fmt, sizeof(mdb->shortdate_fmt), "%s", fmt);
|
||||
}
|
||||
|
||||
void mdb_set_boolean_fmt_numbers(MdbHandle *mdb)
|
||||
{
|
||||
mdb->boolean_false_value = boolean_false_number;
|
||||
@@ -257,6 +262,12 @@ int ret;
|
||||
char *str;
|
||||
if (col->col_type == MDB_NUMERIC) {
|
||||
str = mdb_numeric_to_string(mdb, start, col->col_scale, col->col_prec);
|
||||
} else if (col->col_type == MDB_DATETIME) {
|
||||
if (mdb_col_is_shortdate(col)) {
|
||||
str = mdb_date_to_string(mdb, mdb->shortdate_fmt, mdb->pg_buf, start);
|
||||
} else {
|
||||
str = mdb_date_to_string(mdb, mdb->date_fmt, mdb->pg_buf, start);
|
||||
}
|
||||
} else {
|
||||
str = mdb_col_to_string(mdb, mdb->pg_buf, start, col->col_type, len);
|
||||
}
|
||||
@@ -877,7 +888,7 @@ mdb_date_to_tm(double td, struct tm *t)
|
||||
}
|
||||
|
||||
static char *
|
||||
mdb_date_to_string(MdbHandle *mdb, void *buf, int start)
|
||||
mdb_date_to_string(MdbHandle *mdb, const char *fmt, void *buf, int start)
|
||||
{
|
||||
struct tm t;
|
||||
char *text = (char *) g_malloc(mdb->bind_size);
|
||||
@@ -985,7 +996,7 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int
|
||||
}
|
||||
break;
|
||||
case MDB_DATETIME:
|
||||
text = mdb_date_to_string(mdb, buf, start);
|
||||
text = mdb_date_to_string(mdb, mdb->date_fmt, buf, start);
|
||||
break;
|
||||
case MDB_MEMO:
|
||||
text = mdb_memo_to_string(mdb, start, size);
|
||||
|
||||
@@ -174,6 +174,7 @@ static MdbHandle *mdb_handle_from_stream(FILE *stream, MdbFileFlags flags) {
|
||||
MdbHandle *mdb = (MdbHandle *) g_malloc0(sizeof(MdbHandle));
|
||||
mdb_set_default_backend(mdb, "access");
|
||||
mdb_set_date_fmt(mdb, "%x %X");
|
||||
mdb_set_shortdate_fmt(mdb, "%x");
|
||||
mdb_set_bind_size(mdb, MDB_BIND_SIZE);
|
||||
mdb_set_boolean_fmt_numbers(mdb);
|
||||
#ifdef HAVE_ICONV
|
||||
|
||||
@@ -417,3 +417,8 @@ mdb_col_get_prop(const MdbColumn *col, const gchar *key) {
|
||||
return NULL;
|
||||
return g_hash_table_lookup(col->props->hash, key);
|
||||
}
|
||||
|
||||
int mdb_col_is_shortdate(const MdbColumn *col) {
|
||||
const char *format = mdb_col_get_prop(col, "Format");
|
||||
return format && !strcmp(format, "Short Date");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user