I need to get rid of fixed array size in C++/ODBC apps. Instead the hardcoded array size (ROWS =10 below) I want to pass the ROWS as the command-line argument. I know how to parse the command line. But how to adjust the following code?
#define ROWS 10
SQLINTEGER idata[ROWS]
SQLCHAR cdata1[ROWS][256]
SQLFLOAT fdata[ROWS]
SQL_TIMESTAMP_STRUCT ts[ROWS]
SQLSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, ROWS)
SQLBindCol(1, &idata)
SQLBindCol(2, cdata1)
SQLBindCol(3, fdata)
SQLBindCol(4, &ts)
SQLExecDirect("query producing a result-set")
Update: I cannot modify the signature of SQLBindCol(..)
Let say I will create std::vector instead of SQLFLOAT fdata[ROWS] but how to pass it into SQLBindCol() which does not expect std::vector?
std::vectororstd::arrayinstead of the c-style arrays.new[]is for. e.g.SQLINTEGER * idata = new SQLINTEGER[rows](and don't forget todelete[]later). The multidimensional arraycdata1is a bigger problem, because that can't be allocated dynamically. The best you can do is an array-of-arrays or a singlenew SQLCHAR[rows*256], one of which might work depending on howSQLBindColworks here. I don't know enough about ODBC to help more than that.