Insert variables in a table of a sqlite-database

 
If we want to insert some values in a table COMPANY of a database, it should be written as below:


//--- enter data to the table    if(!DatabaseExecute(db, "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1,'Paul',32,'California',25000.00); " ))      {       Print("DB: ", filename, " insert failed with code ", GetLastError());       DatabaseClose(db);       return;      }


Now if we want to insert a variable x=1 instead of 1, how can we do it?

I tried the following but it didn't  worked:
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES(?,?,?,?,?), (x,'Paul',32,'California',25000.00); "

 
Try something like this:
int x = 1;
string name = "Paul";
int age = 32;
string address = "California";
double salary = 25000.00;

DatabaseBind(db,
   "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (?,?,?,?,?)",
   x, name, age, address, salary);
I think this is more like an SQL problem than a mql5.
 
No it did not work again
 
Simplifying Databases in MQL5 (Part 1): Introduction to Databases and SQL
Simplifying Databases in MQL5 (Part 1): Introduction to Databases and SQL
  • 2025.08.27
  • www.mql5.com
We explore how to manipulate databases in MQL5 using the language's native functions. We cover everything from table creation, insertion, updating, and deletion to data import and export, all with sample code. The content serves as a solid foundation for understanding the internal mechanics of data access, paving the way for the discussion of ORM, where we'll build one in MQL5.