+ (Sqlite3 *) opendb;
{
if (db = = nil) {
Get the path to the document file
Parameter 1: folder name parameter 2. Find domain Parameter 3. Whether to use absolute path
NSString * DocPath = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES). FirstObject;
Path to the database file
NSString * DbPath = [DocPath stringbyappendingpathcomponent:file_name];
Classes for managing files in IOS
Nsfilemanager is responsible for assigning files, deleting files, moving files
NSFILEMANAGER * fm = [Nsfilemanager Defaultmanager];
Determine if there are sqlite files in the document, and no copy files from the app to document
if (![ FM Fileexistsatpath:dbpath]) {
Get. SQLite file path in APP
NSString * Bundlepath = [[NSBundle mainbundle] pathforresource:@ "DataBase" oftype:@ "SQLite"];
Nserror * error = NIL;
Copy
BOOL result = [FM copyitematpath:bundlepath topath:dbpath error:&error];
if (!result) {
NSLog (@ "%@", error);
}
}
Open the database. Parameter 1 file path parameter 2, pointer to receive database
Sqlite3_open ([DbPath utf8string], &db);
}
return DB;
}
SQLite Open Database