tags:

views:

103

answers:

2

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: 

sharptooth is right on when he asks which statement leads to the core dump. Since you haven't answered, I'm thinking you may not know how to do that.

First off, make sure your program is compiled with debug symbols. Assuming you're using gcc, you do that by having -g on the command line.

Next, make sure your environment will write core files. Do this with the shell command ulimit -c unlimited (when running in sh, bash, etc.) or limit core unlimited (when running in csh).

Run the program and let it crash.

Next, bring up the core in gdb with gdb programname corename.

Finally, run the backtrace command in gdb to see where the crash was.

R Samuel Klatchko
i followed the steps ,but it core dumped file is not present in current directory??? any location like /tmp i need to check for core file?
lakshmipathi
+1  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;".

sharptooth
yes,Once issue solved now its working fine after removing \ . error = sqlite3_exec(conn, "update server_pool set servername='Laks' where ipaddress='192.168.1.111'", 0, 0, 0);tables is updated Laks. :) but still it says core-dumped ..where to find core-dumped file? it's not found in existing directory
lakshmipathi
You need the semicolon at the end of the query.
sharptooth
even after adding semi-colon -it core dumps !! actually I had a code part which uses select query..that causes core-dump ---anyway update is working properly ...thank you all
lakshmipathi