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

fix db opening error with absolute path on windows #283

Merged

Conversation

recursivecurry
Copy link
Contributor

fix #282 (SQLITE_CANTOPEN error when cached.Database is called with absolute path on windows).


Creating db using cached.Database with absolute path has error on windows.
below is my code and error message

code

var sqlite = require('sqlite3');
var current_db = new sqlite.cached.Database('current.db');    // OK
var relative_db = new sqlite.cached.Database('folder\\current.db');    // OK
var absolute_db = new sqlite.cached.Database('C:\\current.db');    // ERROR!!!

error message

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: SQLITE_CANTOPEN: unable to open database file

fix SQLITE_CANTOPEN error when cached.Database is called with absolute path on windows
use path.resolve for getting absolute path
@recursivecurry
Copy link
Contributor Author

No feedback? I add some comment to explain my fix.

Previous cached.Database code classify the path string by checking first character of path is '/'. However, Windows absolute path doesn't start with '/'. In Windows, absolute starts with drive character like 'C', 'D'. So I use node.js's path.resolve function which resolve the input path to an absolute path. I verified my code on windows 7(64bit) and ubuntu 12.04(64bit).

@springmeyer
Copy link
Contributor

Sorry for the delay in commenting @everyevery - this fix looks great. I'll merge and test myself when I have a chance. Thanks!

springmeyer pushed a commit that referenced this pull request Apr 30, 2014
fix db opening error with absolute path on windows
@springmeyer springmeyer merged commit 07ba0d3 into TryGhost:master Apr 30, 2014
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

Successfully merging this pull request may close these issues.

absoluete path handling error on windows
2 participants