0

我是 Sqlite3 的新手。我正在使用 C++ 接口,特别是合并。该数据库是在具有 rw 权限的 tmp 文件夹中创建的,特别是 0x644。当我去写表时,我得到错误 SQLITE_IOERR_LOCK (3850)。我在 QNX 操作系统上运行。我能做些什么来解决这个问题?

谢谢!

bool myApp::Start()
{
   bool retVal = false;
   int rc, ret;
   char sql [] = "CREATE TABLE IF NOT EXISTS ZPL_CMDS(" \
                 "id       INT PRIMARY KEY   NOT NULL," \
                 "myCount  INT               NOT NULL );" ;
   char *zErrMsg = 0;

   // initialize engine
   if (SQLITE_OK != (ret = sqlite3_initialize()))
   {
       printf("Failed to initialize library: %d\n", ret);
   } else {
   printf("SQLITE3 library Initialized!\n");
   }

   rc = sqlite3_open("/tmp/zplCmd.db", &db);

   if(!sqlite3_extended_result_codes(db, 1))
   {
  printf("SQLITE3: extended result codes turned ONs\n");
  }
  else
  {
     printf("SQLITE3: extended result codes turned OFF\n");
  }

  if( rc ){
      printf("Can't open database: %s\n", sqlite3_errmsg(db));
      return(0);
  }else{
  printf("Opened database successfully: %s\n", sqlite3_errmsg(db));
  }

   /* write tables */
   rc = sqlite3_exec(db, sql, NULL, 0, NULL); // <-- my code fails here

   if( rc != SQLITE_OK ){
   printf("SQL error: %s, %d\n", sqlite3_errmsg(db), rc);
   sqlite3_free(zErrMsg);
   } else {
     printf("Table created successfully\n");
   }

返回 retVal; }

4

1 回答 1

0

问题在于 QNX 下的锁定机制

rc = sqlite3_open_v2(path.c_str(), &database, SQLITE_OPEN_READWRITE,"unix-none") worked for me

VFS 选项“unix-none”禁用锁定机制。

更多详细信息:https ://www.sqlite.org/vfs.html

于 2021-09-16T08:35:33.757 回答