I am trying to use the data records present in my database (MariaDB) by connecting with C++ and using mysql_query to executeSQL query in C++, my goal is to use the data present in the database to my C++ code and perform operations and again push the operated data which is stored in the variable back to the database.
I am facing the problem of
- Segmentation error
- Query out of sync
I think this is happening because I am using a loop to take the data from the database and then update the records back to the database, and while updating the records I can update static data but I am not able to update the variable data which stores the operating values.
con = mysql_connection_setup(mysqlD); // connection using database id
resultRecord = mysql_execute_query(con, "SELECT Date FROM tableData LIMIT 1000;");
//take data from database into C++ code
cout << "Displaying 10 Database Records: \n"
for (int i = 0; i < 10; i++) // operation on first 10 values
{
databaseTable = mysql_fetch_row(resultRecord); // Fetch the particular data from database
char *DatePtr[i] = {databaseTable[0]}; // Date Column
string dateString = *DatePtr; // function uses string
cout << "Operated Date: ";
DateOperator(dateString); // Function for date operation which returns the operated date.
updateRecord = mysql_execute_query(con, "UPDATE tableData SET DataAge = (#variable value) WHERE Id < 0 ");
}
mysql_free_result(resultRecord); //Free Up the Query
mysql_close(con);
This is my first question on Stack Overflow so please let me know if any update is required in the question. Please help me out of this problem.
Thank you for your time and response.