MonetDB Mapi Library Data Insertion

66 Views Asked by At
void * Data [NUM_ROW][NUM_COLS];   

string insertTablePrepare = "INSERT INTO temp VALUES(";
      for (size_t k = 0; k < NUM_COLS; k++) {
          insertTablePrepare += "?";
          if (k==NUM_COLS-1) continue;
          insertTablePrepare += ",";
      }
      insertTablePrepare += ")";

hdl = mapi_prepare(dbh,insertTablePrepare.c_str());

for (size_t j = 0; j < NUM_ROW; j++) {
         for (size_t k = 0; k < NUM_COLS; k++) {
              switch (ColumnDataType[k]) {
                       case VARCHAR:
                          ret = mapi_param_type(hdl, k, MAPI_VARCHAR, MAPI_VARCHAR, Data[j][k]);
                       break;
                       case SMALLINT:
                          ret = mapi_param_type(hdl, k, MAPI_SHORT, MAPI_SHORT, Data[j][k]);
                       break;
                       case INT:
                          ret = mapi_param_type(hdl, k, MAPI_INT, MAPI_INT, Data[j][k]);
                       break;
                       case BIGINT:
                          ret = mapi_param_type(hdl, k, MAPI_LONG, MAPI_LONG, Data[j][k]);
                       break;
                       case DECIMAL:
                          ret = mapi_param_type(hdl, k, MAPI_FLOAT, MAPI_FLOAT, Data[j][k]);
                       break;
                       case DOUBLE:
                          ret = mapi_param_type(hdl, k, MAPI_DOUBLE, MAPI_DOUBLE, Data[j][k]);
                       break;
                       case REAL:
                          ret = mapi_param_type(hdl, k, MAPI_DOUBLE, MAPI_DOUBLE, Data[j][k]);
                       break;
                       case DATE:
                          ret = mapi_param_type(hdl, k, MAPI_DATE, MAPI_DATE, Data[j][k]);
                       break;
                       default:
                          printf("Unknow data type %d\n",ColumnDataType[k]);
                   }
          }
          ret=mapi_execute(hdl);
}

I created a data set, and I put it in a two dimensional void-pointer array. When I was trying to insert all the records into MonetDB by using mapi_prepare() and mapi_execute(), The above code doesn't work as expected. For only one record, it could be successfully inserted. However, when the number of records is more than one. the program reports

realloc(): invalid next size
Aborted (core dumped)

Has anyone use the mapi_execute() in a for loop to iterate through all the inserting records. Thanks in advance for the help.

0

There are 0 best solutions below