I am trying to learn core data. after following few online tutorials I have created a sample iPhone app. the app is working fine. i can save data and search in the database.
The problem I am having is I can't browse the database in my mac. I am using 'SQLite Database Browser'. in the app folder there are three SQLite files (with extension .sqlite, .sqlite-shm and .sqlite-wal)
I can open the .sqlite file, but I don't see any table in the file. (I think the table is still in the temporary files. or is it?)
couldn't post the screenshot of the database folder, as i don't have enough reputation :-(
Here is the code I am using to save data:
NSEntityDescription *entitydesc = [NSEntityDescription entityForName:#"Person" inManagedObjectContext:context];
NSManagedObject *newPerson = [[NSManagedObject alloc]initWithEntity:entitydesc insertIntoManagedObjectContext:context];
[context hasChanges];
[newPerson setValue: self.firstName.text forKey:#"firstname"];
[newPerson setValue: self.lastName.text forKey:#"lastname"];
NSError *error;
[context hasChanges];
[context save:&error];
_displayLabel.text = [NSString stringWithFormat:#"person added"];
I have developed app with SQLite database before and I didn't have any issue browsing database.
Before I start implementing core data to my app, I wanted to know if this problem is going to cause me headeche down the track. or is it something i can ignore.
Your SQLite file is using WAL mode as Martin mentioned. You can vacuum the database to see the data or just let it perform as it is working as intended.
Further discussion on this topic can be found at CoreData database not showing in sqlite since moving to Xcode 5
Related
I'm using a sqlite database linked to my react-native app.
I've already done some queries in my app that work fine, so the query method is good.
Now, I've add new table to the database by adding a csv file in it (as I've already done before).
But when I make a call on the new table, the console tells me that there is 'no such table'.
If I put the sql query in my DB manager, the call do works.
Thanks for your help!
I did find the solution.
It is very simple, just create a new emulator and rerun your app. It seems that Android Studio works on a 'copy' of the project so it does not see the modification in the database.
I'm posting this to assist users who will be encountering the same thing I did when trying to locate a sqlite database being used on the iOS simulator when using Appcelerator.
xCode Version: 8.3.x
Appcelerator Studio: 4.8.x / SDK: 6.x
Issue/Test Case: I need to test several iterations of loading data from the sqlite database to a remote mySQL server. I want to place an existing sqlite database file in the folder and have the simulator recognize this file so I can use it for testing/development.
Question: Where is the sqlite database stored on the iOS simulator, can I place an existing sqlite database in this folder and have my app recognize it?
Answer: Yes
Steps to achieve:
This is what I did to locate where the simulator/device is looking for
1. Find out where your application is located in the filesystem by adding this code in your index.js (or another file of your choosing).
Ti.API.info("app directory: " + Ti.Filesystem.applicationDataDirectory);
This will give you the long filesystem directory location:
/Users/[username]/Library/Developer/CoreSimulator/Devices/96662E38-C659-4568-B53F-C32DC6B2B73D/data/Containers/Data/Application/96662E38-C659-4568-B53F-C32AB6B2C03D /Documents/
2. This was almost the correct location but the sqlite database is actually stored in the following location:
/Users/[username]/Library/Developer/CoreSimulator/Devices/96662E38-C659-4568-B53F-C32DC6B2B73D/data/Containers/Data/Application/96662E38-C659-4568-B53F-C32AB6B2C03D /Library/Private Documents/[filename].sql
3. You can use this location to put an existing sqlite database file and execute sql statements against it.
4. I'm sure you could reference another directory in your app but I was looking for the default storage directory since my app uses this location.
Hope this helps someone, as I was looking for this specific functionality for testing/development.
Happy Coding!
An easy way to get the database included is to simply add it to the resources folder, or a sub folder in the resources directory. Then you simply call the Ti.Database.install() method. This will copy the database into the simulator location you found. The upside with this method is that you don't have find the location for each iOS simulator (i.e. iPhone 5, 6, 6 plus, 7...).
I do use your method when I need to query the database externally with SQLite manager or another such program.
You can read more here http://docs.appcelerator.com/platform/latest/#!/guide/Working_with_a_SQLite_Database
I try to add core data's - with data already loaded - sqlite database to the project. I am running App on simulator, on device I get no problem. The goal to preload fresh launching app with data. In the document folder I have 3 database file:sqlite, sqlite-shm, sqlite-wal. I have chosen to copy to the project only the sqlite file. When I restarting App with preoloaded database, It seems that database is empty. Why? On device there would be only one database file, which would be not corrupted. Database connection was not closed on simulator, or what?
I found here the answer: How to preload data into an iOS app using sqlite files
In oder to get core data to behave in the old way (pre-iOS 7), and generate just the sqlite file, I had to add this argument to the addPersistentStoreWithType:configuration:URL:options:error: method call, in the options parameter. You can find it in AppDelegate.
#{ NSSQLitePragmasOption : #{ #"journal_mode" : #"DELETE" } }
I have a database from an existing android app that I need to import into my Windows Phone 8 app. Is the only way to do this to create some huge population script to be ran on the first loading of the app?
I am currently using the new sqlite-net-wp8 by Peter Huene as directed by this blog post. But the examples are all about creating the database, not using an existing one. Any help would be great.
This link shows how to copy an existing sqlite database in Windows 8. The ability to do it on a phone is the same.
1) Add the sqlite database into your project and set the type to content in its properties.
2) When your app loads, load the file into a storage file. Then write it back out using the localfolder as the destination.
WP8 only supports local (in local file) databases.
Check your solution and search for database file. If file does't exist then You can only copy by script.
I'm in need of some help in developing a desktop application with a pre-populated database. I have tried numerous ways to get this working including those mentioned on both Tidesdk's API here http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Database.DB and at Titanium Desktops old API here http://developer.appcelerator.com/apidoc/desktop/latest/Titanium.Database-module.
While the later (using Titanium not Ti) works in creating a database in the apps directory it does not install my pre-populated sqlite database which is located in the resources file of my app.
A couple of my attempts located below
var db = Titanium.Database.openFile('test_db.sqlite', 'test_db');
var db = Titanium.Database.openFile(Ti.Filesystem.getFile(
Ti.Filesystem.getApplicationDataDirectory(), 'test_db.sqlite'));
var db = Ti.Database.open('test_db');
As stated most of these manage to create a database with the name given but when trying to run something as simple as a db.execute(SELECT) of something I know would exist in my pre-populated db I receive an error stating
Exception executing: SELECT name, id FROM people ORDER BY name COLLATE NOCASE, Error was: SQL Statement invalid or database missing
I have searched high and low for something to answer this but everyone continues to refer to the aforementioned API's or to the Mobile API's Ti.database.install() which does not work either.
Is it possible with titanium desktop to use a pre-populated sqlite database or do I have to populate it after I create it? If so any direction would be helpful (where to place the .sqlite file in the app and what functions to call).
I am currently using Titanium Studio with a titanium desktop osx SDK of 1.2.0.RC4 as requested by tidesdk.org until they have released there open source sdk.
Thanks in advance
This is possible, I just used this feature in a recent desktop app, deployed it successfully to Windows and Mac.
In my experience, sometimes your database file can be corrupted, for example if you use the Titanium.Database.install command, and it cant find the file to preload from (maybe the first time you specified the path wrong for instance), it will create the file itself, any subsequent install commands will not work because it already thinks this database has been installed.
Have you tried clearing out the application data? This is where titanium installs the database. For Mac this is in your /User/Library/Application Support/APPNAME directory. Their is a directory for databases, delete this and try again.
Also, this answer on Titanium Q&A may help, it talks about the process with the Mobile SDK but the Database stuff is the same.
Hope this helps!