zoukankan      html  css  js  c++  java
  • Sqlite数据库完整性检测

    /*************************************************************************************************
    * 函数名称:  IntegrityCheck
    * 功能描述:  数据库完整性检测
    * 输入参数:  无 
    * 输出参数:  无
    * 返 回 值:  0:完整 / 1:损坏 
    * 其它说明:
    * 修改日期 版本号 修改人 修改内容
    * -----------------------------------------------
    * 
    **************************************************************************************************/
    #define		DB_OK					0	/* 完整 */
    #define		DB_ERROR				1	/* 损坏 */
    
    sqlite3 *obj_db;
    char g_objfile[255] = "DB.db3";
    
    int IntegrityCheck(void)
    {
    	/*打开数据库*/
    	sqlite3_open( g_objfile, &obj_db );
    
    	BOOL integrityVerified = DB_ERROR;
    	sqlite3_stmt *integrity = NULL;
    
    	// integrity_check检查包括:乱序的记录、缺页、错误的记录、丢失的索引、唯一性约束、非空约束
    	//if ( sqlite3_prepare_v2( obj_db, "PRAGMA integrity_check;", -1, &integrity, NULL ) == SQLITE_OK ) 
    	//quick_check不检查约束条件,耗时较短
    	if ( sqlite3_prepare_v2( obj_db, "PRAGMA quick_check;", -1, &integrity, NULL ) == SQLITE_OK )  
    	{
    		while ( sqlite3_step( integrity ) == SQLITE_ROW ) 
    		{
    			const unsigned char *result = sqlite3_column_text( integrity, 0 );
    			if ( result && strcmp( ( const char * )result, (const char *)"ok" ) == 0 ) 
    			{
    				integrityVerified = DB_OK;
    				break;
    			}
    		}
    
    		sqlite3_finalize( integrity );
    	}
    
    	/*关闭数据库*/
    	sqlite3_close( obj_db );
    
    	return integrityVerified;
    }
    

    更多内容请访问 www.uusystem.com

  • 相关阅读:
    Win10家庭版无法远程桌面连接的解决方法
    分分钟用上C#中的委托和事件之窗体篇
    分分钟用上C#中的委托和事件
    Fiddler工具使用介绍三
    Fiddler工具使用介绍二
    Fiddler工具使用介绍一
    Hexo主题开发
    IDEA 编译 Jmeter 4.0 ( 二次开发_1 )
    Pinpoint 安装部署
    接口测试总结
  • 原文地址:https://www.cnblogs.com/tianjifa/p/9273712.html
Copyright © 2011-2022 走看看