勇芳软件工作室.汉化:  SQLite3 API Functions > Database Connection >

sqlite3_db_readonly

Previous pageReturn to chapter overviewNext page

描述

 

如果指定的连接的指定数据库是只读的,则sqlite3_db_readonly函数返回1,如果读/写则为0,如果不是指定连接上的数据库的名称,则返回-1。

 

C / C ++语法

 

int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);

 

PB语法

 

FUNCTION sqlite3_db_readonly ( _

BYVAL hDbc AS DWORD, _

BYREF szDbName AS ASCIIZ _

) AS LONG

 

参数

 

pDb

 

[in]数据库连接句柄。

 

szDbName

 

[in]数据库名称。

 

返回值

 

如果指定的连接的指定数据库是只读的,则返回1,如果读/写则返回0,如果 不是指定连接上的数据库的名称,则返回-1。

 

C ++实现代码

 

/*

** Return the Btree pointer identified by zDbName.  Return NULL if not found.

*/

SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){

int i;

for(i=0; i<db->nDb; i++){

  if( db->aDb[i].pBt

   && (zDbName==0 || sqlite3StrICmp(zDbName, db->aDb[i].zName)==0)

  ){

    return db->aDb[i].pBt;

  }

}

return 0;

}

 

/*

** Return TRUE if the database file is opened read-only.  Return FALSE

** if the database is (in theory) writable.

*/

SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager *pPager){

return pPager->readOnly;

}

 

/*

** Return 1 if database is read-only or 0 if read/write.  Return -1 if

** no such database exists.

*/

SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){

Btree *pBt = sqlite3DbNameToBtree(db, zDbName);

return pBt ? sqlite3PagerIsreadonly(sqlite3BtreePager(pBt)) : -1;

}