Closed Stophface closed 2 years ago
@Stophface, did you make any progress with this?
The same issue...
I have the same problem and have been looking for a solution for about a week. I'm downloading a database from the web service, for example, let's say hello.db. After moving it to the databases folder on the android side very comfortably, I took care of all my problems with the explanations in the documentation, it is superb, but I faced a complete disaster on the ios side. There is neither a databases folder that needs to be moved nor the opendatabase command can not read the database file I have. object {code 5, message: no such table table_name}
edit: one week later I found solution. "https://github.com/andpor/react-native-sqlite-storage/issues/164" mike-niemand commented on 17 May 2017 answer helped me. Mike says db and location don't work with the same name, but for me it's just the opposite. It worked when db and location have the same name.
When you want pre-populate database then every time you have to create a new database file and delete previous database or re build application.
check out below documentation
https://infinitbility.com/react-native-sqlite-storage-examples-of-query
For me, there was a little bit of subtlety getting this to work on iOS as I kept experiencing the infamous "no such table found" error. I assumed that all I had to do was create a www directory under my project through the file system and it would all work. I created the directory and placed my sqlite db there and verified it in the project viewer in Xcode. However, it did not copy my database into /Users..../Library/Developer/CoreSimulator/Devices/MyApp.app/HASH-ID/Library/LocalDatabase/my-sqlite-db.db
I only discovered the source of this issue when I used Xcode to step through the source code of react-native-sqlite-storage/platforms/ios/SQLite.m around line #159 which starts with
RCT_EXPORT_METHOD(open: (NSDictionary *) options success:(RCTResponseSenderBlock)success error:(RCTResponseSenderBlock)error)
"Step 3 - Add file to project in XCode, right click on the main folder and select Add Files to 'your project name"
in https://github.com/andpor/react-native-sqlite-storage is very important. Use Xcode to add the folder.
Good luck. Osupa.
Following SnehalAgrawal comment in this Issue solved my Problem on iOS and Android https://github.com/andpor/react-native-sqlite-storage/issues/164
Expected Behavior
I expect the database to be moved and have the table in it
Current Behavior
I move the database and try to
SELECT
something from the table, but it returns that the table does not exist.Possible Solution
I suspect the moving of the
database
has not worked.SQLite
rather creates a completly newdatabase
onSQLite.openDatabase({ name: 'foo', location: 'default' }...
, and of course, that has notable: bar
yet.Steps to Reproduce (for bugs)
I have a pre-populated
database
namedfoo.db
located inwww/sqlite/
. I move this database to the internal storage like thisThis logs me
Database successfully moved.
so I suspect it worked. Then I try to open the database like this.This logs me
Successfully opened Database
with thisThat looks like a
Database Object
to me. But then returns me ontx.executeSql('SELECT * FROM bar'...
thisYour Environment