0
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.

ccm
  • 25
  • 4
  • Can you please provide more information to help the MonetDB team to investigate: 1. Where exactly was the error reported? I.e. can you provide the full stack trace with "thread apply all bt full"? 2. what is the exact string you tried to execute? 3. does the error immediately happen when you try to insert 2 records? Or does it only happen with a much larger number of records? 4. Can you provide a small programme with which your problem can be reproduced? 5. Which MonetDB version are you using? On which OS? – Jennie Oct 05 '20 at 13:26
  • The error immediately reports when loop is going through second ret=mapi_execute(hdl); and the first loop of ret=mapi_execute(hdl); is abandoned. My MonetDB version is v11.37.11, and it's running on Ubuntu 18.04 – ccm Oct 05 '20 at 15:12
  • There are some realloc's in the prepare code of the mapi library. But it is hard to tell up front if there is anything problematic about them. Like @Jennie says, you need to have a fully reproducible example. Otherwise we cannot help you to debug it. – Yunus King Oct 07 '20 at 07:46
  • What do you mean with "the first loop of ret=mapi_execute(hdl); is abandoned"? Following up Aris comment, I'd recommend you to put your programme through GDB first. That can help you identify the exact place where the error is given and the full GDB stack trace might tell us the value of the parameter that has cause this error. – Jennie Oct 07 '20 at 08:05

0 Answers0