none
用ODBC 的 Binding Arrays of Parameters 为啥每次执行只可以插入一行? RRS feed

  • 问题

  • 代码如下:

    SQLRETURN rc;
        int ARRAY_SIZE = 10;

     SQLUINTEGER    PartIDArray[ARRAY_SIZE] ;
     SQLUINTEGER     PriceArray[ARRAY_SIZE] ;
     SQLINTEGER     PartIDIndArray[ARRAY_SIZE], PriceIndArray[ARRAY_SIZE];
     SQLUSMALLINT   i, ParamStatusArray[ARRAY_SIZE];
     SQLULEN ParamsProcessed;

     memset(PartIDIndArray, 0, sizeof(PartIDIndArray));
     memset(PriceIndArray, 0, sizeof(PriceIndArray));


     rc = SQLSetStmtAttr (*phstmt, SQL_ATTR_ROW_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
        rc = SQLSetStmtAttr (*phstmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)ARRAY_SIZE, 0);
     rc = SQLSetStmtAttr(*phstmt, SQL_ATTR_PARAM_STATUS_PTR, ParamStatusArray, 0);
     rc = SQLSetStmtAttr(*phstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &ParamsProcessed, 0);


        string strsql = "INSERT INTO definition (def_id,def_type ) values (?,?)" ;
        rc = SQLBindParameter(*phstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 5,0, (SQLPOINTER)PartIDArray, 0, (SQLINTEGER*)PartIDIndArray);
        rc = SQLBindParameter(*phstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 5,0, (SQLPOINTER)PriceArray, 0, (SQLINTEGER*)PriceIndArray);

     // Set part ID, description, and price.
     for (i = 0; i < ARRAY_SIZE; i++) {
      PartIDArray[i] = i;
      PriceArray[i]= i;
        PartIDIndArray[i] = 0;
        PriceIndArray[i] = 0;
     }

     // Execute the statement.
     SQLExecDirect(*phstmt, (SQLCHAR *)strsql.c_str(), SQL_NTS);

    2013年10月29日 7:10

答案

全部回复