Topic
3 replies Latest Post - ‏2013-12-09T02:43:26Z by chianbaye
chianbaye
chianbaye
3 Posts
ACCEPTED ANSWER

Pinned topic why only insert one row,using ODBC bulk insert

‏2013-10-29T07:41:51Z |

I using ODBC API insert bulk , only insert one row , and all records corrrct

my cords:

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);

 

The result only insert one row into informix DB

Updated on 2013-10-30T03:01:29Z at 2013-10-30T03:01:29Z by chianbaye
  • chianbaye
    chianbaye
    3 Posts
    ACCEPTED ANSWER

    Re: why only insert one row,using ODBC bulk insert

    ‏2013-11-14T03:20:13Z  in response to chianbaye

    It is solve

  • Sathyanesh
    Sathyanesh
    11 Posts
    ACCEPTED ANSWER

    Re: why only insert one row,using ODBC bulk insert

    ‏2013-12-08T05:33:51Z  in response to chianbaye

    FYI:
    The Informix ODBC driver with true 64bit support has introduced with CSDK 4.10.
    You may need to use ODBC driver from CSDK 4.10 xC1 or higher.


    If you are on 64bit platform argument passed to SQLBindParameter() may break.
    Especially the last parameter to the function should be an address of SQLLEN type.
    SQLINTEGER is not a substitute for SQLLEN, if you do that you may lose portability of the code between 32bit and 64bit platform.
    On 32 bit both SQLINTEGER and SQLLEN are of same size (4 byte ).
    At the same time on 64bit platform SQLINTEGER remain 4byte but SQLLEN is 8byte.
    Unless used with right type it can cause memory corruption.


    Here is the right signature for SQLBindParameter()
    SQLRETURN SQLBindParameter(
          SQLHSTMT        StatementHandle,
          SQLUSMALLINT    ParameterNumber,
          SQLSMALLINT     InputOutputType,
          SQLSMALLINT     ValueType,
          SQLSMALLINT     ParameterType,
          SQLULEN         ColumnSize,
          SQLSMALLINT     DecimalDigits,
          SQLPOINTER      ParameterValuePtr,
          SQLLEN          BufferLength,
          SQLLEN *        StrLen_or_IndPtr);

     

    • chianbaye
      chianbaye
      3 Posts
      ACCEPTED ANSWER

      Re: why only insert one row,using ODBC bulk insert

      ‏2013-12-09T02:43:26Z  in response to Sathyanesh

      ok, thank you very much ,I will modify it.