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