I'm trying to use an SQLDA structure to specify the binding variables for my prepared statement. I've got it to work with an SQLINT type, but I can't get it to work with the SQLDATE type, because I get the error:
-1205: Invalid month in date.
I have prepared a statement like this (it's a bit more complicated than this actually, and I have to use dynamic SQL (obviously for the below code I wouldn't, but anyway):

select name, price, descr from catalogue
where date_added >= ?
and quantity >= ?
I used an SQLDA structure and malloc'd it:

static  sqlda   *bindvars = NULL;
bindvars = (sqlda*)malloc(sizeof(sqlda));
bindvars->sqlvar = malloc(max_n * sizeof(sqlvar_struct));

/* date_int holds the date as the number of days since 31/12/1899
 * as a 4-byte integer
bindvars->sqlvar[0].sqldata = (char*)&date_int;
bindvars->sqlvar[0].sqllen = rtypmsize(SQLDATE, 0);
bindvars->sqlvar[0].sqltype = SQLDATE;

bindvars->sqlvar[1].sqldata = (char*)&quantity;
bindvars->sqlvar[1].sqllen = sizeof(int);
bindvars->sqlvar[1].sqltype = SQLINT;
If I run this without the SQLDATE type (just with the SQLINT and quantity), it works fine. But when I add the date, I get the -1205 error.

What am I doing wrong? I've printed out the contents of all the data variables of the SQLDA and they appear to be correct. It's a 4-byte date: 39978 (15/06/2009), which is surely what it expects, no? Does anyone have any experience with SQLDA?

As I said previously, the rest of the prepared statement is dynamic, so I have to use SQLDA, it's just this beginning bit with the date that is causing me grief!

Thank you in advance!