ODBC SQLBindParameter for string array

Andre andre at s-e-a-p.de
Tue Jan 28 07:48:55 PST 2014


On Monday, 27 January 2014 at 14:18:17 UTC, Regan Heath wrote:
> Try this:
>
> // SQLCHAR is defined as ubyte
> SQLCHAR*[] charArr = new SQLCHAR*[](stringArr.length);
>
> foreach(i, str;stringArr){
>     charArr[i] =   cast(SQLCHAR*) toStringz(str); // import 
> std.string
>     lengIndArr[i] = SQL_NTS; // Null terminated string
> }
>
> The SQL API is expecting an array of (C) char* pointers, not an 
> array of D's ubyte[] (which is actually twice the size).
>
>> 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,   // I don't think the +1 is necessary..
>>  lengIndArr.ptr);
>
> Regan

Thanks a lot for your help!

Kind regards
André



More information about the Digitalmars-d-learn mailing list