Search code examples
anylogic

How can I insert multiple lists as values into an AnyLogic database table?


In order to record part IDs and process times for each agent, I created individual database tables where these values are recorded. I wanted to create a results database table to summarize all times and IDs in a single table. I tried writing the following code on model destroy to input the values on the individual tables into the results table:

List<String> list1 = selectFrom(identifiers).list(identifiers.part_id);
List<Double> list2 = selectFrom(cfs_time).list(cfs_time.cfs_time);
List<Double> list3 = selectFrom(deburr_time).list(deburr_time.deburr_time);
List<Double> list4 = selectFrom(drill_time).list(drill_time.drill_time);

insertInto( results )
.columns( results.part_id, results.cfs_time, results.deburr_time, results.drill_time) 
.values( list1, list2, list3, list4 )
.execute();

However when I run the model I get a "row column count mismatch" error on model destroy. When I try to input a single list (such as list1) with the following code:

insertInto( results )
.columns( results.part_id)
.values(list1)
.execute();

it works without any issue but obviously only adds a single column. This tells me that I am having a problem when I try to add multiple list like on the first code above. I wanted to ask what I am doing wrong with that code and what should I do differently to be able to input multiple lists into individual columns.

Thank you in advance for your assistance.


Solution

  • Your 4 lists have a different number of entries. Ensure they have the same .size() for the lists before writing them into the summary dbase table.

    (this is what the error is trying to say as well :) )