|
@@ -46,7 +46,8 @@
|
|
|
{
|
|
{
|
|
|
sqlite3* db = nil;
|
|
sqlite3* db = nil;
|
|
|
|
|
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
|
|
+// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
NSString *documents = [paths objectAtIndex:0];
|
|
NSString *documents = [paths objectAtIndex:0];
|
|
|
NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
DebugLog(@"home path %@",documents);
|
|
DebugLog(@"home path %@",documents);
|
|
@@ -56,19 +57,19 @@
|
|
|
sqlite3_close(db);
|
|
sqlite3_close(db);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#ifdef DEBUG_DB
|
|
|
|
|
- NSFileManager *manager = [NSFileManager defaultManager];
|
|
|
|
|
-
|
|
|
|
|
- NSString *copyPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
|
|
|
|
- copyPath = [copyPath stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
- [manager removeItemAtPath:copyPath error:nil];
|
|
|
|
|
- BOOL isCopy = [manager copyItemAtPath:database_path toPath:copyPath error:nil];
|
|
|
|
|
- if (isCopy) {
|
|
|
|
|
- NSLog(@"拷贝成功");
|
|
|
|
|
- } else {
|
|
|
|
|
- NSLog(@"拷贝失败");
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+//#ifdef DEBUG_DB
|
|
|
|
|
+// NSFileManager *manager = [NSFileManager defaultManager];
|
|
|
|
|
+//
|
|
|
|
|
+// NSString *copyPath =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
|
|
|
|
+// copyPath = [copyPath stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
+// [manager removeItemAtPath:copyPath error:nil];
|
|
|
|
|
+// BOOL isCopy = [manager copyItemAtPath:database_path toPath:copyPath error:nil];
|
|
|
|
|
+// if (isCopy) {
|
|
|
|
|
+// NSLog(@"拷贝成功");
|
|
|
|
|
+// } else {
|
|
|
|
|
+// NSLog(@"拷贝失败");
|
|
|
|
|
+// }
|
|
|
|
|
+//#endif
|
|
|
return db;
|
|
return db;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -209,27 +210,38 @@
|
|
|
+ (BOOL) initializeDb {
|
|
+ (BOOL) initializeDb {
|
|
|
DebugLog (@"initializeDB");
|
|
DebugLog (@"initializeDB");
|
|
|
|
|
|
|
|
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
- NSString *documents = [paths objectAtIndex:0];
|
|
|
|
|
- NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // move db file from document to cache ;
|
|
|
|
|
- NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
|
- NSString *documentFolderPath = [searchPaths objectAtIndex: 0];
|
|
|
|
|
- NSString* dbFilePath = [documentFolderPath stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath: dbFilePath])
|
|
|
|
|
- {
|
|
|
|
|
- [[NSFileManager defaultManager] moveItemAtPath:dbFilePath toPath:database_path error:nil];
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+// NSString *documents = [paths objectAtIndex:0];
|
|
|
|
|
+// NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// // move db file from document to cache ;
|
|
|
|
|
+// NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+// NSString *documentFolderPath = [searchPaths objectAtIndex: 0];
|
|
|
|
|
+// NSString* dbFilePath = [documentFolderPath stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
+// if ([[NSFileManager defaultManager] fileExistsAtPath: dbFilePath])
|
|
|
|
|
+// {
|
|
|
|
|
+// [[NSFileManager defaultManager] moveItemAtPath:dbFilePath toPath:database_path error:nil];
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
// end move;
|
|
// end move;
|
|
|
|
|
|
|
|
|
|
+ // 2019.1.11 move db from cache to document
|
|
|
|
|
+ NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
|
|
|
|
|
+ NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *db_cache = [cacheDir stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
+ NSString *db_doc = [docDir stringByAppendingPathComponent:DBNAME];
|
|
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:db_cache]) {
|
|
|
|
|
+ NSError *err;
|
|
|
|
|
+ [[NSFileManager defaultManager] moveItemAtPath:db_cache toPath:db_doc error:&err];
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ NSLog(@"move database error: %@",err);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
if (true)//! [[NSFileManager defaultManager] fileExistsAtPath: database_path])
|
|
if (true)//! [[NSFileManager defaultManager] fileExistsAtPath: database_path])
|
|
|
{
|
|
{
|
|
|
sqlite3 *db = [self get_db];
|
|
sqlite3 *db = [self get_db];
|