1. 首先导入SQL处理库FMDB,使用FMDB来处理
2. 在导入需要处理的文件,如file.db
3. 实例代码
//从NSBundle目录读取
NSString* dbPath = [[NSBundle mainBundle]pathForResource:@"file.db" ofType:@""];
FMDatabase* database = [ FMDatabase databaseWithPath: dbPath ];
if ( ![ database open ] )
{
return;
}
// 查找表 AllTheQustions
FMResultSet* resultSet = [ database executeQuery: @"select * from table" ];
resultSet = [database executeQuery:@"select * from table"];
//读取table表中所有字段
NSMutableDictionary *dict = resultSet.columnNameToIndexMap;
NSLog(@"========dic= %@",para);
// 循环逐行读取数据resultSet next
while ( [ resultSet next ] )
{
// 对应字段来取数据
NSString* fileid = [ resultSet stringForColumn: @"id" ];
NSString* fileName = [ resultSet stringForColumn: @"name" ];
// 读取完之后关闭数据库
[ database close ];
}