ODBC SQLBindParameter for string array
Andre
andre at s-e-a-p.de
Sat Jan 25 03:05:11 PST 2014
Hi,
I have some issues with the ODBC SQLBindParameter. I already
achieved to add an array of integers but the scenario of writting
a string array is not working.
While doing the INSERT statement 3 rows are added to the
database. The first row has the correct value "A". The second row
has not value instead of "B". And the third row has a strange
value and the character 'P' instead of "C".
Do you have some idea?
Kind regards
André
// CREATE TABLE demo(name VARCHAR(1))
// INSERT INTO demo (name) VALUES (?)
string[] stringArr = ["A","B","C"];
SQLSetStmtAttr(hStmt, SQL_ATTR_PARAMSET_SIZE,
cast(SQLPOINTER) stringArr.length, 0);
SQLSetStmtAttr(hStmt, SQL_ATTR_PARAM_BIND_TYPE, cast(SQLPOINTER)
SQL_PARAM_BIND_BY_COLUMN, 0);
SQLINTEGER[] lengIndArr = new SQLINTEGER[](table.rowCount);
// Get max length, in this example always: 1
int maxLength = 0;
foreach(str;stringArr){
if(str.length > maxLength){
maxLength = str.length;
}
}
// SQLCHAR is defined as ubyte
SQLCHAR[][] charArr = new SQLCHAR[][](stringArr.length, maxLength
+ 1);
// +1 for \0 character
foreach(i, str;stringArr){
charArr[i] = cast(SQLCHAR[]) (str~"\0");
lengIndArr[i] = SQL_NTS; // Null terminated string
}
SQLBindParameter( hStmt, cast(SQLUSMALLINT) 1, cast(SQLSMALLINT)
SQL_PARAM_INPUT, cast(SQLSMALLINT)SQL_C_CHAR,
cast(SQLSMALLINT)SQL_VARCHAR,
maxLength, 0, charArr[0].ptr , maxLength + 1, lengIndArr.ptr);
More information about the Digitalmars-d-learn
mailing list