Skip to content

Android internal db path #28

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

Closed
Swarnamahesh opened this issue Nov 21, 2011 · 4 comments
Closed

Android internal db path #28

Swarnamahesh opened this issue Nov 21, 2011 · 4 comments

Comments

@Swarnamahesh
Copy link

Hi,

I am trying to create a database with path as default database path in android, with code as below. I get unable to open database file exception. If i give sdcard path it works perfectly, however i do not want my db available in sdcard. Is there a way to make this work internally? (I do not use dbhelper)

Code:

String dbPath = context.getDatabasePath(DATABASE_NAME).toString()
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(dbPath, "password", null);

Exception:

info.guardianproject.database.sqlcipher.SQLiteException: unable to open database file

Thanks & Regards,
Swarna

@n8fr8
Copy link
Collaborator

n8fr8 commented Nov 21, 2011

Just use the name of the db without any path, and it will be stored internally.

Swarnamahesh reply@reply.github.com wrote:

Hi,

I am trying to create a database with path as default database path in android, with code as below. I get unable to open database file exception. If i give sdcard path it works perfectly, however i do not want my db available in sdcard. Is there a way to make this work internally? (I do not use dbhelper)

Code:

String dbPath = context.getDatabasePath(DATABASE_NAME).toString()
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(dbPath, "password", null);

Exception:

info.guardianproject.database.sqlcipher.SQLiteException: unable to open database file

Thanks & Regards,
Swarna


Reply to this email directly or view it on GitHub:
https://github.com/guardianproject/android-database-sqlcipher/issues/28

@Swarnamahesh
Copy link
Author

Hi, Thanks for the reply, I tried the following code as well, it still gives the same exception:

Exception:
info.guardianproject.database.sqlcipher.SQLiteException: unable to open database file

Code 1:
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase("data", "password", null);

Code 2:
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase("data.db", "password", null);

@n8fr8
Copy link
Collaborator

n8fr8 commented Nov 21, 2011

Have you tried our sample code? The Notepadbot sample project? These all use internal storage.

Swarnamahesh reply@reply.github.com wrote:

Hi, Thanks for the reply, I tried the following code as well, it still gives the same exception:

Exception:
info.guardianproject.database.sqlcipher.SQLiteException: unable to open database file

Code 1:
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase("data", "password", null);

Code 2:
sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase("data.db", "password", null);


Reply to this email directly or view it on GitHub:
https://github.com/guardianproject/android-database-sqlcipher/issues/28#issuecomment-2814640

@Swarnamahesh
Copy link
Author

Thank you for replying. I fixed it by reviewing the code given for your helper class at :

https://github.com/developernotes/android-database-sqlcipher/blob/a6f071fd41190b76c42cee10d43c4c94b74eec10/src/info/guardianproject/database/sqlcipher/SQLiteOpenHelper.java

I modified my code accordingly. For future reference, here is the code I modified to make it work without helper class.

String dbPath = context.getDatabasePath(DATABASE_NAME).getPath();

File dbPathFile = new File (dbPath);
if (!dbPathFile.exists())
dbPathFile.getParentFile().mkdirs();

sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(dbPath, "password", null);

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

2 participants