Link to home
Start Free TrialLog in
Avatar of luckie
luckie

asked on

Add C++ Variables into mySQL

What is the syntax of adding C++ variables into mySQL?
Could anyone raise an example?
I've tried
insert into aTable (field1, field2) values (variable1, variable2)
But mySQL throws error messages at me saying varible1 is not in the field list.
Thanks for your attention
Jack
Avatar of madwax
madwax

INSERT INTO myTable(field1,field2) VALUES('var2','var2')

//madwax
Avatar of luckie

ASKER

Hi madwax,
Are you sure? :)
'var2' inserts the string 'var2' into the database, not the its variable representation
It returns duplicate entry right after the second insert.... :)
Thanks
Jack
Avatar of luckie

ASKER

int var2 = 3;

Insert into table1 (field1, field2) values (var2, 'hello')
ASKER CERTIFIED SOLUTION
Avatar of ikework
ikework
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of luckie

ASKER

Okay. Thanks a lot :)
Avatar of luckie

ASKER

Wait a minute... I've got a question...:O
How come when the field and the variables are both of type integer, why do you need to convert them into varchars. As in my database, they are of integer types.
Thanks for any attempt for solving my question
Jack
Avatar of luckie

ASKER

rc = SQLExecDirect (hstmt, (SQLCHAR *) "INSERT INTO aTable (a,b,...  )  values (var1, '10',  '', '', '', '', '', '', '', '','', '', c);", SQL_NTS);
mystmt (hstmt, rc);


where var1 is already a character pointer (C String)
and c is a stored procedure containing binary data.
Thanks