I'm new to C++ (limited SQL knowledge) and I'm having a difficult time inserting data into a postgresql.
char test1 = 'C'
w.exec("CREATE TABLE IF NOT EXISTS binary (id INT PRIMARY KEY, meta TEXT)");
w.exec("INSERT INTO binary (id,meta) VALUES (5, 'A')");
w.exec(std::string("INSERT INTO binary (id,meta) VALUES (6, ") + test1 + ")");
w.exec("INSERT INTO binary (id,meta) VALUES (7, "+readFile2("/home/test/cpp_db/rdb_test/test.txt")+")");
The first insert statement works fine. However the second statement results in the error:
ERROR: column "c" does not exist
While the third insert statement results in the error:
ERROR: column "thisisatest123" does not exist
I should mention that thisisatest123
is the content of the file. Why is it that the first insert statement saves the character A
fine but the other two sql statements fail? I've looked into INSERT COMMAND :: ERROR: column "value" does not exist hence I made sure test1
is enclosed by single quotes but it doesn't seem to make a difference.
What do I need to do such that I can insert the content of a file into the database? Ie, the third insert statement.