Fix handling of numeric types in ODBC driver

Fixes #255 and supersedes #256
This commit is contained in:
Evan Miller 2021-02-15 19:50:15 -05:00
parent b9c065885c
commit e655cba907
3 changed files with 14 additions and 6 deletions

View File

@ -544,6 +544,10 @@ void mdb_set_boolean_fmt_words(MdbHandle *mdb);
void mdb_set_boolean_fmt_numbers(MdbHandle *mdb);
int mdb_read_row(MdbTableDef *table, unsigned int row);
/* money.c */
char *mdb_money_to_string(MdbHandle *mdb, int start);
char *mdb_numeric_to_string(MdbHandle *mdb, int start, int scale, int prec);
/* dump.c */
void mdb_buffer_dump(const void *buf, off_t start, size_t len);

View File

@ -24,9 +24,6 @@
#define OFFSET_MASK 0x1fff
#define OLE_BUFFER_SIZE (MDB_BIND_SIZE*64)
char *mdb_money_to_string(MdbHandle *mdb, int start);
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, const char *fmt, void *buf, int start);
@ -1000,9 +997,11 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int
double td;
switch (datatype) {
case MDB_NUMERIC:
case MDB_BOOL:
/* shouldn't happen. bools are handled specially
** by mdb_xfer_bound_bool() */
fprintf(stderr, "Warning: mdb_col_to_string called on an unsupported data type.\n");
break;
case MDB_BYTE:
text = g_strdup_printf("%d", mdb_get_byte(buf, start));
@ -1050,7 +1049,6 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int
break;
case MDB_MONEY:
text = mdb_money_to_string(mdb, start);
case MDB_NUMERIC:
break;
case MDB_REPID:
text = mdb_uuid_to_string(mdb->pg_buf, start);

View File

@ -1662,8 +1662,14 @@ SQLRETURN SQL_API SQLGetData(
strcpy(stmt->sqlState, "HY090"); // Invalid string or buffer length
return SQL_ERROR;
}
char *str = mdb_col_to_string(mdb, mdb->pg_buf,
col->cur_value_start, col->col_type, col->cur_value_len);
char *str = NULL;
if (col->col_type == MDB_NUMERIC) {
str = mdb_numeric_to_string(mdb, col->cur_value_start,
col->col_scale, col->col_prec);
} else {
str = mdb_col_to_string(mdb, mdb->pg_buf,
col->cur_value_start, col->col_type, col->cur_value_len);
}
size_t len = strlen(str);
if (stmt->pos >= len) {