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

  • 相关阅读:
    vcsa7.0可能不兼容esxi6.7
    使用livecd 更改root密码
    虚拟机初始化脚本
    一句话修改UUID
    vcsa 6.7 u1升级6.7 u2--6.7U3---6.7U3c
    【转载】:FreeRadius安装及与openldap的连接(centos 7 环境)
    freeradius 关联LDAP认证-按属性过滤LDAP目录中的用户
    使用包ldap3进行Python的LDAP操作
    2020年1月29日-学习flask第一天
    Python-xlwt库的基本使用
  • 原文地址:https://www.cnblogs.com/tianjifa/p/9273712.html
Copyright © 2011-2022 走看看