Compiling app. using Sqlite

prpr

Well-Known Member
Consider this trivial code:
Code:
#include "sqlite3.h"
#include <stdio.h>

int main(void)
{
  const char *filename = "test.db";
  sqlite3 *db = NULL;

  printf("Opening\n");
  if (sqlite3_open_v2(filename, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK)
  {
  printf("Opened\n");
  }

  printf("Closing\n");
  sqlite3_close(db);
  printf("Closed\n");
  return 0;
}
compiled using "gcc -o testdb testdb.cpp -lsqlite3"

When I run it, I just get "Opening" printed and it hangs.
Running under strace I see the last few lines as:
Code:
write(1, "Opening\n", 8Opening
)  = 8
brk(0)  = 0x411000
brk(0x412000)  = 0x412000
futex(0x411010, FUTEX_WAIT, 2, NULL <unfinished ...>
Presumably this futex is what's blocking everything, but why, where does it come from and how do I stop it?
Comparing e.g. /mod/boot/xinit.d/chandel, there is no futex and it just goes on to open chandel.conf as expected.
 

af123

Administrator
Staff member
From chandel.c

Code:
sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);

if (sqlite3_open_v2(CHANNEL, &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_PRIVATECACHE, NULL)
!= SQLITE_OK)
{
printf("Failed: %s\n", sqlite3_errmsg(db));
return 0;
}

Could be the singlethread or privatecache that you need.

Edit: Forum's indentation not mine!
 
OP
prpr

prpr

Well-Known Member
I'd already tried all 4 combinations of privatecache and nomutex and they all did the same thing. I tried compiling on the spare HDR as well. Same result.
The key to it is the sqlite3_config call. Working now, thanks.
 

af123

Administrator
Staff member
Glad it's working, I don't recall why that is necessary. It's been a few years since I wrote the first C application that interfaces with sqlite3 - it was possibly chandel.
 
Top