Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sqlite3.h>
- //g++ -o test2 test2.cpp -lsqlite3
- using namespace std;
- int main()
- {
- int counter = 0;
- sqlite3 *db;
- sqlite3_stmt * stmt;
- string username = "panda";
- string name = "Kungfu Panda";
- string department = "normal";
- string password = "hellopassword";
- string sqlstatement = "INSERT INTO abe_account (" + username + "," + name + "," + department + "," + password + ");";
- if (sqlite3_open("abeserver.db", &db) == SQLITE_OK)
- {
- sqlite3_prepare( db, sqlstatement.c_str(), -1, &stmt, NULL );//preparing the statement
- sqlite3_step( stmt );//executing the statement
- }
- else
- {
- cout << "Failed to open dbn";
- }
- sqlite3_finalize(stmt);
- sqlite3_close(db);
- return 0;
- }
- INSERT INTO tablename (field1, field2, field3) VALUES (value1, value2, value3);
- INSERT INTO tablename VALUES (value1, value2, value3)
- "('" + username + "','" + name + "','" + department + "','" + password + "');"
- string quotesql( const string& s ) {
- return string("'") + s + string("'");
- }
- "(" + quotesql(username) + "," + quotesql(name) + ...
- string sqlstatement =
- "INSERT INTO abe_account (username, name, department, password) VALUES ("
- + quotesql(username) + ","
- + quotesql(name) + ","
- + quotesql(department) + ","
- + quotesql(password) + ");";
- string sqlstatement = "INSERT INTO abe_account ('" + username + "','" + name + "','" + department + "','" + password + ");";
- string sqlstatement = "INSERT INTO abe_account (ColumnName1, ColumnName2, ColumnName3, ColumnName4) VALUES ('" + username + "','" + name + "','" + department + "','" + password + "');";
- int m = sqlite3_step(stmt);
- if(m == SQLITE_BUSY)
- {
- if(m == SQLITE_ERROR)
- std::cout(sqlite3_sql(stmt), sqlite3_errmsg(db));
- if(m == SQLITE_MISUSE)
- std::cout(sqlite3_sql(stmt), sqlite3_errmsg(db));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement