3

I am building my first iPhone app with CSS, HTML, Javascript and PhoneGap. I want to use SQLite as the database, so i am using the following tutorial as inspiration:

http://coenraets.org/blog/2011/10/sample-app-using-the-phonegap-database-api/

The following code determines weather to use data from the database, or to populate the database with data first:

function onDeviceReady() {

    db = window.openDatabase("EmployeeDirectoryDB", "1.0", "PhoneGap Demo", 200000);
    if (dbCreated)
        db.transaction(getEmployees, transaction_error);
    else
        db.transaction(populateDB, transaction_error, populateDB_success);
}

After debugging, i found out that every time i run the app, it populates the database, so

if (dbCreated)

never executes.

I want to have a look at the SQLlite file, so i am using SQLite Database Browser to locate it, without luck. From the following question:

How to view the data in sqlite file running in iphone application?

I can see that the file should be located somewhere in this folder:

user/Library/Application Support/iPhone Simulator/

But the iPhone Simulator folder does not exist.

How do i make the simulator save the database to a local file?

Community
  • 1
  • 1
Kenci
  • 4,794
  • 15
  • 64
  • 108

1 Answers1

3

Each time you run your application on simulator, it creates a folder inside iphone simulator folder .Make sure your Library folder is visible and you are using the correct path.

To make library folder visible you can run the following command on terminal:

chflags nohidden ~/Library

Here`s the path for my iphone simulator folder to use as a reference:

/Users/alexandreoliveira/Library/Application Support/iPhone Simulator

Another thing to notice, usually the sqlite database get saved inside documents folders:

Users/alexandreoliveira/Library/Application Support/iPhone Simulator/5.1/Applications/some-weird-numbers/Documents/

alexandresoli
  • 918
  • 1
  • 9
  • 18
  • After running chflags nohidden ~/Library, i can see the folder in the terminal, but cannot see it in SQLite Database Browser. Is it possible to make the system show all hidden folders in all programs? – Kenci Oct 08 '12 at 16:27
  • I have tried looking in all the folders with the long numbers (there are two) - and in their Documents folder, but there are no .sqllitefiles. As i mentioned earlier, it seems that the application populates the DB every time. Perhaps because it is never saved? – Kenci Oct 08 '12 at 16:30
  • Since you are talking about phonegap, i think theres a bug on ios 5 that the db file get saved on a temp folder and get deleted whenever the system wants, so they released a new version that fixed that in 2012. What version of phonegap are you using? – alexandresoli Oct 08 '12 at 16:33
  • According to the VERSION file i am using 2.1.0 which is the newest on their website. Also, i am using the ios 6.0 simulator for xcode 4.5 – Kenci Oct 08 '12 at 16:39
  • Are there other alternatives? – Kenci Oct 10 '12 at 07:34