From the MySQL reference manual:
If you store a number into an ENUM column, the number is treated as the index into the possible values, and the value stored is the enumeration member with that index.
But when I try to write an SQL_SMALLINT
value to that ENUM column using ODBC I get the error HY000:1:1265 (Data truncated for column ...).
So how can I write a number into a MySQL ENUM column using ODBC, such that this number is interpreted as the enum index?
Edit: Some more information
The column is defined as:
`TrackState` ENUM('NEWE','NEWN','VALID','INVISIBLE','CLOSED','DIED') NULL
and the statement used with ODBC is:
INSERT INTO test (TrackState) VALUES (?)
and in my C code I use SQLBindParameter
with SQL_C_USHORT
and SQL_SMALLINT
to bind an unsigned short variable.
When I change my TrackState column to an ordinary INT
column, the numeric value (which I want to be interpreted as the index of an enum) is successfully written.