FMDB 查询是否存在某个表,或某个数据


 //监测数据库中我要需要的表是否已经存在
	NSString *existsSql = [NSString stringWithFormat:@"select count(name) as countNum from sqlite_master where type = 'table' and name = '%@'", @"Member" ];
	FMResultSet *rs = [membersDB executeQuery:existsSql];
	
	if ([rs next]) {
		NSInteger count = [rs intForColumn:@"countNum"];
		NSLog(@"The table count: %li", count);
		if (count == 1) {
			NSLog(@"存在");
			return;
		}
}

 

//检测某个数据是否存在
FMResultSet *rs =[membersDB executeQuery:@"SELECT COUNT(Name) AS countNum FROM Member WHERE Name = ?",self.nameTextField.text]; while ([rs next]) { NSInteger count = [rs intForColumn:@"countNum"]; if (count > 0) { //存在 } else { //不存在 } }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM