SQLite: Difference between revisions

Jump to navigation Jump to search
221 bytes removed ,  4 years ago
Line 49: Line 49:
# A parameterized query
# A parameterized query
paste(c("INSERT INTO employee(name,age) VALUES(\"John Smith\",",toString(age),");",query),collapse='')
paste(c("INSERT INTO employee(name,age) VALUES(\"John Smith\",",toString(age),");",query),collapse='')
ierr <- dbExecute(dbase,query)
dbExecute(dbase,query)


# Close the database connection
# Close the database connection
Line 63: Line 63:
int main(int argc,char** argv)
int main(int argc,char** argv)
{
{
   int ierr,age = 34;
   int age = 34;
   std::string query;
   std::string query;
   sqlite3* dbase;
   sqlite3* dbase;


   ierr = sqlite3_open("foo.sqlite",&dbase);
   sqlite3_open("foo.sqlite",&dbase);
  if (ierr) {
    std::cerr << "Unable to open database!" << std::endl;
    return 1;
  }


   query = "INSERT INTO employee(name,age) VALUES(\"John Smith\"," + std::to_string(age) + ");";
   query = "INSERT INTO employee(name,age) VALUES(\"John Smith\"," + std::to_string(age) + ");";
   ierr = sqlite3_exec(dbase,query.c_str(),nullptr,nullptr,nullptr);
   sqlite3_exec(dbase,query.c_str(),nullptr,nullptr,nullptr);
  if (ierr != SQLITE_OK) {
    std::cerr << "Error in executing query!" << std::endl;
    return 2;
  }


   sqlite3_close(dbase);
   sqlite3_close(dbase);
Bureaucrats, cc_docs_admin, cc_staff
2,318

edits

Navigation menu