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:
Evan Miller
2020-09-02 22:14:57 -04:00
parent 0023e4efe4
commit 7f7761e884
8 changed files with 37 additions and 12 deletions

View File

@@ -167,6 +167,7 @@ static SQLRETURN do_connect (
// ODBC requires ISO format dates, see
// https://docs.microsoft.com/en-us/sql/relational-databases/native-client-odbc-date-time/datetime-data-type-conversions-odbc?view=sql-server-ver15
mdb_set_date_fmt( dbc->sqlconn->mdb, "%F %H:%M:%S" );
mdb_set_shortdate_fmt( dbc->sqlconn->mdb, "%F" );
return SQL_SUCCESS;
}
else
@@ -1592,8 +1593,7 @@ SQLRETURN SQL_API SQLGetData(
struct tm tmp_t;
mdb_date_to_tm(mdb_get_double(mdb->pg_buf, col->cur_value_start), &tmp_t);
const char *format = mdb_col_get_prop(col, "Format");
if (format && !strcmp(format, "Short Date")) {
if (mdb_col_is_shortdate(col)) {
DATE_STRUCT sql_dt;
sql_dt.year = tmp_t.tm_year + 1900;
sql_dt.month = tmp_t.tm_mon + 1;