andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.76k stars 520 forks source link

Pre populated database stuck in INIT and never opens #194

Open cstehreem opened 7 years ago

cstehreem commented 7 years ago

I am creating an update to my app which required significant changes in database and I created a new one. Now I am trying to migrate previous database's data to new one but my old database (injected into databases folder) is stuck in INIT state and never opens. If I try to open new database (created by the app) with same method in the same folder, it works just fine.

Here is my openDatabase call const databaseName = "food_cost_calculator_sqlite.db3"; const connection = SQLite.openDatabase( { name: databaseName, readOnly: true, createFromLocation: "/data/data/user/0/com.foodcostcalculator/databases/food_cost_calculator_sqlite.db3" }, successCallBack, errorCallBack );

If I swap food_cost_calculator_sqlite.db3 with FoodCostCalculator_DB.db it opens that database.

My app's file structure that I am monitoring through Android Device Monitor: image

Can anyone help me with this? Or suggest an alternate way may be.

Thanks

cstehreem commented 7 years ago

ok I was able to open the database through the simple open call: const databaseName = "Food_Cost_Calculator_SQLite.db3"; const connection = SQLite.openDatabase( { name: databaseName, readonly: false, location: "Documents" }, successCallBack, errorCallBack );

And all my previously stored data is available there. Can anyone explain what is happening?

Thanks

itinance commented 7 years ago

Just a hint @cstehreem : you can use attachDatabase to attach the old database to the new one (or vice versa) for being able to just do things like "INSERT INTO newDatabase.myTable SELEC * FROM oldDatabase.myTable" and so on

cstehreem commented 7 years ago

Doesn't attach database also require an open instance of both databases? Also is there anything wrong with the way i am opening it now? Your help is much appreciated.

On Sep 30, 2017 12:02 PM, "Hagen Hübel" notifications@github.com wrote:

Just a hint @cstehreem https://github.com/cstehreem : you can use attachDatabase https://github.com/andpor/react-native-sqlite-storage/#attaching-another-database to attach the old database to the new one (or vice versa) for being able to just do things like "INSERT INTO newDatabase.myTable SELEC * FROM oldDatabase.myTable" and so on

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/andpor/react-native-sqlite-storage/issues/194#issuecomment-333289221, or mute the thread https://github.com/notifications/unsubscribe-auth/AD9Yj6ataWocLyjMf5RuAb17VTgEQ3IMks5sneeDgaJpZM4Pnn0v .

itinance commented 7 years ago

Yes, both databases must be opened before to get an sqlite-file-handle under the hood. Can't see any issues on the way you do the openDatabase. Should work

itinance commented 7 years ago

have a look at this example: https://github.com/andpor/react-native-sqlite-storage/#attaching-another-database

cstehreem commented 7 years ago

Yeah that's where the problem is. I am unable to open the second instance through the method for prepopulated database which is given in docs. But it's opening fine now so I guess I will just keep using that method unless someone can point out anything might go wrong with it. Thanks though.

On Sep 30, 2017 12:06 PM, "Hagen Hübel" notifications@github.com wrote:

have a look at these example: https://github.com/andpor/ react-native-sqlite-storage/#attaching-another-database

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/andpor/react-native-sqlite-storage/issues/194#issuecomment-333289447, or mute the thread https://github.com/notifications/unsubscribe-auth/AD9Yj5i4F1Nt5XyOhBnjKEwJDAmh-tPoks5sneiKgaJpZM4Pnn0v .

itinance commented 7 years ago

You should debug the openDatabase under the hood with XCode or Android Studio, depending on the system that you are working on.

cstehreem commented 7 years ago

Okay I will try that.

On Sep 30, 2017 12:15 PM, "Hagen Hübel" notifications@github.com wrote:

You should debug the openDatabase under the hood with XCode or Android Studio, depending on the system that you are working on.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/andpor/react-native-sqlite-storage/issues/194#issuecomment-333289823, or mute the thread https://github.com/notifications/unsubscribe-auth/AD9Yj_S9-PIehT5gvY1xI7PXgsnayz4iks5sneqPgaJpZM4Pnn0v .

andpor commented 6 years ago

opening database - review the API calls and read the comments. The paths are not absolute...they usually refer to subdirectories of well known directories...