Q:

accessing sqlite with C program

Core dumped while running this program:
int main(void) {
   sqlite3 *conn;
   int     error = 0;

  error = sqlite3_open("cloud_db.sqlite3", &conn);
  if (error) {
          puts("Can not open database");
          exit(0);
  }

  error = sqlite3_exec(conn,
          "update server set servername=\'Laks\' where ipaddress=\'192.168.1.111\'",
        0, 0, 0);
  if (error) {
          puts("Can not update table");
          exit(0);
  }
  sqlite3_close(conn);

  return 0;
}

I have tried accessing (select query) sqlite using C and it shows the contents - that's fine. How can I use queries like update? Above I'm trying to execute a query like:
update server set servername="Laks" where ipaddress="192.168.1.111";

running this query with in sqlite> works fine. How to execute (update query) it from C program?

A:

Since you point out that the problem is there when the statement contains "servername=\'Laks\'" and leaves when you change that to "servername=Laks" I guess the backslashes cause the problem. You don't need backslashes to escape the apostrophe in string literals. Simply use "servername='Laks'". You escape quotes (") in string literals and apostrophes (') in character literals, but not vice versa.
You also need to add the semicolon (;) at the end of the query string: "whatever sql statement text;".

