1

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?

2
  • 1
    The problem can be anywhere - maybe in some surrounding code. Which statement leads to the core dump? Commented Jan 13, 2010 at 7:16
  • I can say that problem is something to do with the part : servername=\'Laks\' How to update string values inside "update server set servername=something" ? using below part gave error --but didn't core dump error = sqlite3_exec(conn, "update server_pool set servername=Laks where ipaddress=192.168.1.111", 0, 0, 0); Commented Jan 13, 2010 at 7:56

2 Answers 2

1

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;".

Sign up to request clarification or add additional context in comments.

3 Comments

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
You need the semicolon at the end of the query.
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
0

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.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.