How to create sqlite3 database in mac for iOS App development - The Idle Coder

How to create sqlite3 database in mac for iOS App development

Hello guys,today i am here with iOS app development tutorial. The tutorial is about how to create sqlite3 database and table using mac terminal. Well there are lots of other ways to create sqlite3 database and tables. You can create sqlite3 database via firefox with sqlite3 manager tool. Even you can create database via programmatically in Xcode. But it requires some time and internet connection . Right? Sometimes in interview you will have to make tables with self. You can't use any other tools or internet. That time you have to create database either via Xcode or via terminal.




 So let's go with terminal . So you want to create sqlite3 database for your application.This database will contain sqlite3 tables and it will be stored in document directory of your iOS application. Document directory is the place where all the data of your application stored.It can not be visible directly.Though you can access it by getting path of it.

Create sqlite3 database in mac terminal


1. Open the terminal. ( command+space will open spotlight where you have to write terminal)
   You can also open it via application-> terminal.

2. When you open it you will find default path. change it by writing :  cd desktop 
     This will store the database on desktop

3.  Write sqlite3 database_name.sqlite  . Press enter

4. Now database is created. You can list all the database on file by writing .database command.

5. Now you have to create table. Write following command.
   create table table_name(column1 type,column2 type);

example: create table iOS(app_id int,app_name text);

6. Now you have to insert data into that table,write following code
   insert into tableName values(value1,value2);

example: insert into iOS(1,'candy crush');

7. All done now you can find that database on desktop and copy it into your app bundle.Then via programmatically you can add it into your document directory.


So this was the tutorial for creating sqlite3 database and sqlite3 table in mac via terminal for iOS application development. You will find iOS development tutorials soon here with demo programs. Thank you !
Previous
Next Post »