-2

I am learning some concepts in the iOS database... I come to know that sqlite3 (open source ) is used for databases, but I was going through some of the github code...

and come across these two lines:

NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:@"banklist" 
        ofType:@"sqlite3"]

and

 NSString *databaseFilename =@"abc.db"
  1. can you please tell me where we will use the sqlite3 and where db?
  2. can you also provide me some good links to learn the database for the iOS (from the sample project when I open the db file in the textedit I can't understand it)?
  3. how can I open the db file and sqlite file?
  4. is there any free tool is available in iOS to read these database files?
Ali Ersöz
  • 15,860
  • 11
  • 50
  • 64
user2353519
  • 155
  • 2
  • 3
  • 9
  • 1
    The name of the file can be anything you want. It could be "Airplane.java" if that makes sense to you. – Hot Licks May 07 '13 at 10:53

4 Answers4

5

You asked:

can you please tell me where we will use the sqlite3 and where db

You can use either extension. It doesn't matter. Both sqlite (without the 3) and db are commonly used.

can you also provide me some good links to learn the database for the iOS

Google "ios sqlite tutorial"

I generally like Ray Wenderlich tutorials and his SQLite tutorial is here: SQLite 101 for iPhone Developers: Making Our App. My only criticism of that tutorial is that I don't like the fact that he's open a database from the bundle. You should always copy database from bundle to Documents folder first, before opening the database in the Documents folder.

how can i open the db file and sqlite file

You open databases (i.e., a file, conventionally with either db or sqlite extension) the same way. It's the same sort of file, just a different extension. The general process is either:

  • Create database on your mac and include it in the project and the resulting bundle. Then, programmatically you check to see if database already exists in the Documents folder and, if not, copy from the bundle to Documents folder (if you do this, you might want to use sqlite3_open_v2 with the SQLITE_OPEN_READWRITE option, but not the SQLITE_OPEN_CREATE option, so the database won't be created if it's not found); or

  • Create database programmatically by (a) check to see if it exists in Documents and if not, create database (with either sqlite3_open_v2 with the SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE options or just sqlite3_open (which uses those two options by default)) and then execute the SQL CREATE statements; or (b) if it already exists in the Documents folder, just use it.

If you go through the various tutorials you find, they'll walk you through or approach or the other. Both techniques are valid.

is there any free tool is available in iOS to read these database files

I don't think there are iOS tools (as apps keep their files (and a database is just a type of file) in their respective sandboxes and thus one app can't open a database in another app's Documents folder). But there are lots of Mac tools that you use during development.

  • The sqlite3 program available in the Terminal command line interface.

  • I use Base, an ok, fairly basic tool

  • I think a lot of people use a FireFox SQLite Manager tool


You didn't ask, but if you're starting SQLite development, using FMDB can greatly simplify your Objective-C code. And I'd be remiss if I didn't note the Core Data is the preferred database technology for iOS development. There can be compelling reasons to use SQLite (via FMDB, for example), but Apple engineered the rich Core Data framework that has some advantages for iOS-only apps. It's a little more complicated, but has some advantages.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • hey thanks for the info but one doubt how to install FireFox SQLite Manager tool ...bcz it is a .xpi file ?? – user2353519 May 07 '13 at 11:13
  • @user2353519 you install it on your Mac where you're doing your development (and, of course, only if you use Firefox). You don't install SQLite tools on the device, but rather on your development machine. – Rob May 07 '13 at 11:14
  • yes man I am trying to install in mac but i downloaded but its a .xpi format file ..which is not opening to install .. that i am asking to install – user2353519 May 07 '13 at 11:21
  • @user2353519 Yes. It is a FireFox add on. – Rob May 07 '13 at 11:27
  • Hi @Rob , why "should always copy database from bundle to Documents folder first"? Is this true even if I use a database just to read data and never modify it? – J.Williams May 18 '15 at 13:02
2

Let! me try to answer your all questions one by one

1.The below line

NSString *sqLiteDb = [[NSBundle mainBundle] pathForResource:@"banklist" 
        ofType:@"sqlite3"]

is saying we will create banklist.sqlite3 file for storing our database.


2.we use the sqlite database, whenever we need to store application's info locally, it can be your choice.


3.For learning sqlite I have created simple step by step Tutorial with sample code

SQLIte in iPhone Tutorial

I would suggest you please! read and do it by yourself complete, you will get all the answers of your questions.


4.for reading or editing I use one open source tool name "sqlite browser" you can download it from here


5.you can find your apps db file and open with the tool I mentioned. here is the db file path you can find in your system .

Note : This is just a reference for your app path will be different but in the same way

/Users/RDCMac/Library/Application Support/iPhone Simulator/6.1/Applications/0975F545-E4D2-40E8-97C6-0EA7F8995315/Documents/contacts.db

-----------------

Please! let me know if you need any help in this, glad to help!!

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • @user2353519 is that helpful for you :) , if you need I can explain you each and every step in that. let me know if you get any trouble – swiftBoy May 07 '13 at 12:05
  • ya still I have trouble with sqlite and db.. for both syntax will be different .. – user2353519 May 07 '13 at 12:16
  • @user2353519 we use the SQL query for sqlite database what we use for MySQL etc., could you clear when you say db? – swiftBoy May 07 '13 at 12:24
  • like in some cases i have seen we are using extension .db and some cases we are using .sqlite3 ..so where to use db and when – user2353519 May 07 '13 at 14:04
1

A.1. You can name the file whatever you like. but keep the extension to .sqlite3 is more reasonable. According to your above example, two things can happen. In the first case, For an iPhone app a database file can be already added in the project bundle and you use the database in your app. This database is read only.

Or, in 2nd case, you can store and modify data in your app. In that case you name an sqlite file, and later on database operation you manipulate that file. Usually this database file should be stored in the device's documents folder. Also, coredata can use a sqlite file store and do operation on the database file.

A useful technique to have a modifiable database in the bundle is to copy the database to document folder on the first run. remember that anything in the bundle is not modifiable.

A.3. You can use a firefox plugin to open, create and modify sqlite files. https://addons.mozilla.org/En-us/firefox/addon/sqlite-manager/

A.4. Not clear. Do you want something like the third question for iOS.

Anthon
  • 69,918
  • 32
  • 186
  • 246
karim
  • 15,408
  • 7
  • 58
  • 96
  • hey thanks for the info but one doubt how to install FireFox SQLite Manager tool ...bcz it is a .xpi file ?? – user2353519 May 07 '13 at 11:13
  • go firefox add ons, then search for sqlite manager. install from there. firefox will install automatically. – karim May 07 '13 at 11:48
0

1) sqlite3 is the extension used for sqlite database files. And db is generally used for database files. You can use either use sqlite3 or db. There is no issue with this.

Reference: SO

2) Tutorials:

3) For opening the db or sqlite file you can use any sqlite tools.

4) SQLite Manager is a free addon for firefox. Which is a handy tool for creating sqlite database

Cœur
  • 37,241
  • 25
  • 195
  • 267
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • hey thanks for the info but one doubt how to install FireFox SQLite Manager tool ...bcz it is a .xpi file ?? – user2353519 May 07 '13 at 11:14
  • @user2353519: open the Tools->Add ons option from firefox. Click on the settings button of that page Select Install Add-on from file option. Choose the xpi file – Midhun MP May 07 '13 at 11:16
  • there is no add on option in my tools ...do i need to install firefox browser – user2353519 May 07 '13 at 11:22
  • @user2353519: Yes. You need to install firefox first. And open it, then you'll see a tools menu for firefox. After that do like above – Midhun MP May 07 '13 at 11:24