SQLite Open Database

Source: Internet
Author: User
Tags sqlite



+ (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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.