Running into an issue with a MySQL Decimal field and PreparedStatements. There is not a specific Decimal bind type list. What should I be using for Decimal fields?
It appears that MySQLPreparedStatement.MYSQL_TYPE_DOUBLE works as expected.
Upon further review, Decimal fields don’t appear to work with Prepared Statements - at all. I’ve tried everything.
I assume you are using the C - API? I assure you it does indeed work. I was struggling with this myself your post showed up in google.
For the read use MYSQL_TYPE_NEWDECIMAL, make sure your buffer is char and don’t forget to set the LENGTH of the string
.....
is_null = 0;
dataType = MYSQL_TYPE_NEWDECIMAL;
memset(bufferValue.simplePtr, 0, SIMPLE_BUFFER_SIZE);
bind->buffer = bufferValue.simplePtr;
bind->buffer_length= SIMPLE_BUFFER_SIZE;
bind->is_null = &is_null;
bind->buffer_type = dataType;
-----
for the write use MYSQL_TYPE_STRING, and again, you are writing to a char buffer.
.....
is_null = 0;
valueSize = strlen((char *)strPtr);
strcpy((char *)bufferValue.simplePtr, (char *)strPtr);
bind->buffer = bufferValue.simplePtr;
bufferSize = SIMPLE_BUFFER_SIZE;
bind->buffer_type = MYSQL_TYPE_STRING;
bind->length = &valueSize;
bind->is_null = &is_null;
.....
I also struggled with BIT, but you did not mention that.