Lecture 5: Storage: Saving Data Database, Files & Preferences

67 %
33 %
Information about Lecture 5: Storage: Saving Data Database, Files & Preferences
Education

Published on March 10, 2014

Author: androidstream

Source: slideshare.net

Description

This slide is made for Shikkhok.com Android course. To get the video lectures visit: http://www.shikkhok.com/%E0%A6%95%E0%A7%8B%E0%A6%B0%E0%A7%8D%E0%A6%B8-%E0%A6%A4%E0%A6%BE%E0%A6%B2%E0%A6%BF%E0%A6%95%E0%A6%BE/android-app-development/

Lecture 5: Storage: Saving Data Database, Files & Preferences [1] Ahsanul Karim karim.ahsanul@gmail.com http://droidtraining.wordpress.com Android Application Development 1. Storage Options 2. Saving Data into a Database a. Introduction to SQLite b. SQL Helper Database Creation c. CRUD [Create Read Update Delete] 3. Using a Pre-populated Database 4. Some optimizations

Saving Data Storage Options Options to save persistent application data: [1] Shared Preferences: Store private primitive data in key-value pairs. [2] Internal Storage: Store private data on the device memory. [3] External Storage: Store public data on the shared external storage. [4] SQLite Databases: Store structured data in a private database. [5] Network Connection: Store data on the web with your network server.

Saving Data Today We’ll Discuss... 1. Saving Data into Database a. Introduction to SQLite b. SQLiteOpenHelper: Database Creation c. CRUD [Create Read Update Delete] 2. Using a Pre-populated Database 3. Some optimizations

Saving Data into a Database Introduction to SQLite [1] SQLite is a software library that implements SQL database engine [1] Self-contained: Requires very minimal support from external libraries or from the operating system. (well suited for embedded devices) [2] Serverless: No separate server process like most SQL database implementations (MySql, Oracle etc.). The process that wants to access the database reads and writes directly from the database files on disk. [3] Zero-configuration: Does not need to be "installed". There is no "setup" procedure. There is no server process that needs to be started, stopped, or configured. No need for an administrator to create a new database instance or assign access permissions to users. [4] Transactional: All changes and queries appear to be Atomic, Consistent, Isolated, and Durable (ACID)

Saving Data into a Database Introduction to SQLite [2] Features: 1. Self-contained, Serverless, Zero-configuration and Transactional 2. A complete database is stored in a single cross-platform disk file. 3. Supports terabyte-sized databases and gigabyte-sized strings and blobs. 4. Small code footprint 5. Faster than popular client/server database engines for most operations. 6. Simple, easy to use API. 7. Written in ANSI-C. 8. Cross-platform: Unix (Linux, Mac OS-X, Android, iOS) and Windows (Win32, WinCE, WinRT) are supported out of the box. Easy to port to other systems. 9. Sources are in the public domain. Use for any purpose. 10. Comes with a standalone command-line interface (CLI) client that can be used to administer SQLite databases.

Saving Data into a Database Introduction to SQL [1] Basic database concepts: [1] What is SQL? SQL stands for Structured Query Language SQL lets you access and manipulate databases [2] What Can SQL do? SQL can execute queries against a database SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database SQL can create stored procedures in a database SQL can create views in a database SQL can set permissions on tables, procedures, and views http://www.w3schools.com/sql/sql_intro.asp

Saving Data into a Database Introduction to SQL [3] [3] Relational Database Management System (RDBMS) 1. RDBMS stands for Relational Database Management System. 2. RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL, Microsoft Access and SQLite. 3. The data in RDBMS is stored in database objects called tables. 4. A table is a collection of related data entries and it consists of columns and rows. http://www.w3schools.com/sql/sql_intro.asp Let’s have a quick look in SQL first...

Saving Data into a Database Introduction to SQL [4] [4] RDBMS Example

Saving Data into a Database Introduction to SQL [5] [4] RDBMS Example

Saving Data into a Database Introduction to SQL [6] [5] Database operations 1. Database creation 2. Table(s) creation 3. Insert Record(s) 4. Update Record(s) 5. Delete Record(s) 6. Query 7. Drop Table(s) 8. Alter Table(s) SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database CREATE DATABASE - creates a new database ALTER DATABASE - modifies a database CREATE TABLE - creates a new table ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index [6] SQL Commands

Saving Data into a Database Introduction to SQL [7] [7] Example SQL Commands CREATE TABLE IF NOT EXISTS `employee` ( `EmployeeID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(50) NOT NULL, `Address` varchar(100) NOT NULL, `PhoneNumber` varchar(11) NOT NULL, `Designation` varchar(50) NOT NULL, PRIMARY KEY (`EmployeeID`) ); [a] Table Creation

Saving Data into a Database Introduction to SQL [8] [7] Example SQL Commands INSERT INTO employee (EmployeeID, Name, Address, PhoneNumber, Designation) VALUES (NULL, 'Hasan', 'Mirpur, Dhaka', '01745534', 'Developer'); INSERT INTO employee (EmployeeID, Name, Address, PhoneNumber, Designation) VALUES (NULL, 'Rahim', 'Motijheel, Dhaka', '01956635', 'Designer'); [a] Insert Records

Saving Data into a Database Introduction to SQL [9] [7] Example SQL Commands SELECT * FROM employee; SELECT Name, Address FROM employee; SELECT * FROM employee WHERE EmployeeID = 1; SELECT * FROM employee WHERE Designation = ‘Developer’; [b] Query Records

Saving Data into a Database SQLite in Android

Saving Data into a Database Questions... Man who waits for roast duck to fly into mouth must wait very, very long time. -Chinese Proverb

Add a comment

Related presentations

Related pages

Storage Options | Android Developers

Store structured data in a private database. Network Connection Store data on the ... preferences files ... internal storage. Saving cache files.
Read more

Preferences storage SharedPreferences files

Persistent Data Storage ... preference file that belongs to the activity, you ... 5 • preference controls used to set the preferences
Read more

Client-Side Storage - HTML5 Rocks - A resource for open ...

... Web SQL Database, Indexed Database, and File ... "client-side storage" means data is passed to ... e.g. preferences and cache. Beyond saving data, ...
Read more

Android Persistence with preferences and files - Tutorial

It also explains how to read and write files in Android. ... Database and other private data will ... 5.1. Create preference file ...
Read more

Persistent Data Storage - Iowa State University

Persistent Data Storage ... preference file that belongs to the activity, you ... • Insert data into the database by passing ...
Read more

C#: How to save data during gameplay? - Unity Answers

... How to save data during gameplay? ... such as save files, settings and preferences, ... Storing data in a sqllite database.
Read more

Backup Policy - The Computer Technology Documentation Project

This policy defines the backup policy ... storage data back from the offline media and putting it on an online storage system such as a file server. 5 ...
Read more