0

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

  1. Segmentation error
  2. 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.

  • Finding the cause of the segfault should be trivial by using your debugger. See [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Jesper Juhl Oct 13 '22 at 12:46
  • Please post your code in the form of a [SSCCE](http://www.sscce.org/), so other people can easily cut'n'paste and compile it to reproduce the problem. – Jesper Juhl Oct 13 '22 at 12:49
  • Always add a proper error handling. if the problem persists compile your code with debug option and debug it. What API do you use? mysql_execute_query or mysql_connection_setup aren't part of an official API. – Georg Richter Oct 13 '22 at 15:55

0 Answers0