How do I access SQLite database instance on iPhone?

前端 未结 8 615
予麋鹿
予麋鹿 2021-01-30 05:19

I\'m developing an iPhone app that uses the built-in SQLite database. I\'m trying to view and open the database via the sqlite3 command line tool so I can execute a

相关标签:
8条回答
  • 2021-01-30 05:51

    Your question remains a little vague. "See" in what sense? Do you create the SQLite database? How? Have you placed it manually in the Simulator's filesystem area? Are you perhaps asking how to do that on the iPhone?

    The easiest way is to precreate an empty database with the sqlite3 command-line tool, have it as a resource in your application, then copy it in your application sandbox's documents folder. You can get the path to your resources folder via NSBundle's pathForResource:ofType: method, then grab the path to your Documents folder via NSSearchPathForDirectoriesInDomains() for the NSDocumentsDirectory folder in the NSUserDomainMask, then copy the file via NSFileManager's methods.

    Otherwise, you can use SQLite's functions to create a new database from scratch by supplying appropriate SQL commands to define its schema.

    0 讨论(0)
  • 2021-01-30 05:51

    The Easiest way to do it by far is using iExplorer to download the file from your app. and then use SQLite Professional read-only to read the file. Even thought it is not realtime but at least it is free. :-)

    0 讨论(0)
  • 2021-01-30 05:52

    In Xcode select window->organizer and expand the node next to your application in the applications section on your phone. Select the black downward pointing arrow next to application data and save the file anywhere on your desktop. Your sqlite database should be in there somewhere.

    As for how to go about getting it back on the phone once your done i have no clue.

    0 讨论(0)
  • 2021-01-30 05:52

    The Download Container method is the one I found to be the best. However, you have to be careful that some times, if you try to e-mail it or attach it from within the app then the file that is sent out would be empty.

    0 讨论(0)
  • 2021-01-30 05:54

    Instructions for Xcode 6.0.1

    1. Xcode > Open > YourProject
    2. Xcode > Product > Run
    3. Xcode > Window > Devices
    4. (Column 1 - select) Devices > YourDeviceName
    5. (Column 2 - select) Installed Apps > YourAppName
    6. (Column 2 - select) Cog under 'Installed Apps' list
    7. (Pop-Up - select) Download Container...
    8. Save to location
    9. Right click on 'YourAppName.xcappdata'
    10. Select 'Show Package Contents'
    11. AppData > Documents > YourDatabase.sqlite

    enter image description here

    0 讨论(0)
  • 2021-01-30 05:54

    This one works if you jailbreak your iPhone.. I don't know why anyone would have any issues with jailbreaking their phone as I've been using it for development for quite some time and found no problems, also it is not uncommon for sqlite to perform differently on the device vs simulator:

    1. Jail break your phone (there tutorials all over the web)
    2. Set your cydia user level to developer
    3. Install sqlite3 into your phone: go to cydia > manage > sources > cydia/telesphoreo > sqlite3
    4. ssh into your phone using iphone tunnel root ssh password: "alpine"
    5. Type which sqlite3 to ensure you have it installed
    6. browse to the location of your db.. a breakpoint in your code should tell you where it is located.. in my code it looks something like this

      NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); 
      NSString *documentsDirectory = [paths objectAtIndex: 0]; 
      NSString *pathName = [documentsDirectory stringByAppendingPathComponent:filename];
      return pathName;
      

      Notice that if you run this on the simulator.. you'll get a location like the following: /Users/admin/Library/Application Support/iPhone Simulator/6.0/Applications/42302574-7722-48C1-BE00-91800443DA7C/Documents/email-524200.edb

    On the device it will look like this: /var/mobile/Applications/FB73857F-A822-497D-A4B8-FBFB269A8699/Documents/email-523600.edb

    Then just type sqlite3 %dbname% and you can execute sql statements right on your phone.. without copying it over or whatever.

    0 讨论(0)
提交回复
热议问题