I have a .dll that I made to read data from flexsim and send it to a sqlite database while a simulation is running. This is the function that i call in a flexsim trigger:
- __declspec(dllexport) int InsertDb(int runNumber, double time, const char* dataKey, const char* dataValue) {
- sqlite3* db;
- char* errMsg = 0;
- char sql[1000];
- int rc = sqlite3_open("path/to/database.db", &db);
- if (rc != SQLITE_OK) {
- fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
- return rc;
- }
- snprintf(sql, sizeof(sql),
- "INSERT INTO SimulationData (RunNumber, Time, DataKey, DataValue) VALUES (%d, %f, '%s', '%s');",
- runNumber, time, dataKey, dataValue);
- rc = sqlite3_exec(db, sql, NULL, NULL, &errMsg);
- if (rc != SQLITE_OK) {
- fprintf(stderr, "SQL error: %s\n", errMsg);
- sqlite3_free(errMsg);
- }
- sqlite3_close(db);
- return rc;
- }
When i run the simulation everything works, but, as you can imagine, the records inside the database are all empty. Thats because im struggling to find a way to fill these parameters:
- (RunNumber, Time, DataKey, DataValue)
- RunNumber
- The number of the simulation running
- Time
- Timestamp of when the simulation started
- DataKey
- The name of the current component where the box is
- DataValue
- The trigger event thats happening (like a short description, eg. "Item entered on Processor")
I want to fill those values dinamically but i cant find a way to make it.