How do I access SQLite database instance on iPhone?

前端 未结 8 618
予麋鹿
予麋鹿 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.

提交回复
热议问题