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.