Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command to create database #624

Closed
openmotion opened this issue Mar 31, 2017 · 1 comment
Closed

command to create database #624

openmotion opened this issue Mar 31, 2017 · 1 comment

Comments

@openmotion
Copy link

openmotion commented Mar 31, 2017

hello
what is the command to create database file ?
because i have the error : unable to open database file (code 14)
thanks

@yasinkavakliat
Copy link

yasinkavakliat commented Apr 5, 2017

I've worked a while on that and solved it with the following code:

    // MARK: FIRST INITIALIZER
    func firstInitialization() {
        //print(Constants.Database.databaseFilePath)
        let fileManager = FileManager.default
        if fileManager.fileExists(atPath: Constants.Database.databaseFilePath) {
            //print("database file exists")
        } else {
            //print("database file doesnt exist. creating now")
            try! database.prepare(createSystemTableStatement).run()
        }
    }

After running the createSystemTableStatement the database file is created.

The databaseFilePath is

static let databaseFilePath = "\(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])/\(databaseFileName)"

databaseFileName is like "mydatabase.db".

Don't know if it's the correct solution, that's how it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants