-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataBaseIO.m
More file actions
executable file
·62 lines (53 loc) · 1.48 KB
/
DataBaseIO.m
File metadata and controls
executable file
·62 lines (53 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// DataBaseIO.m
// HTShuo
//
// Created by 陈少杰 on 12-9-25.
// Copyright (c) 2012年 华南理工大学. All rights reserved.
//
#import "DataBaseIO.h"
@implementation DataBaseIO
+(FMDatabase *)getDB{
return [FMDatabase databaseWithPath:[NSFileManager getFilePath:DATABASENAME]];
}
+(void)executeUpdate:(NSString*)sql{
FMDatabase *db=[self getDB];
[db open];
@try {
[db executeUpdate:sql];
}
@catch (NSException *exception) {
}
@finally {
[db close];
}
}
+(NSMutableArray*)executeQuery:(NSString*)sql{
FMDatabase *db;
NSMutableArray*result;
result=[[NSMutableArray alloc]init];
db=[self getDB];
[db open];
@try {
FMResultSet *rs =[db executeQuery:sql];
while ([rs next]) {
[result addObject:[rs resultDictionary]];
}
}
@catch (NSException *exception) {
}
@finally {
[db close];
}
return result;
}
+(void)backUp{
@autoreleasepool {
if ([NSFileManager isFileExists:DATABASENAME]) {
[NSFileManager copyFileFromFilePath:[NSFileManager getFilePath:DATABASENAME] toFilePath:[NSFileManager getFilePath:@"WorldInfo_2.db.bk"]];
}else if([NSFileManager isFileExists:@"WorldInfo_2.db.bk"]&&![NSFileManager isFileExists:DATABASENAME]){
[NSFileManager copyFileFromFilePath:[NSFileManager getFilePath:@"WorldInfo_2.db.bk"] toFilePath:[NSFileManager getFilePath:DATABASENAME]];
}
}
}
@end