Lecture 8: Database Topics: Basic SQLite Operations.

Slides:



Advertisements
Similar presentations
Programming with Android: Data management
Advertisements

DB glossary (focus on typical SQL RDBMS, not XQuery or SPARQL)
CE881: Mobile and Social Application Programming Flexible Data Handling with Integrity: SQLite Simon M. Lucas.
Query Methods (SQL). What is SQL A programming language for databases. SQL (structured Query Language) It allows you add, edit, delete and run queries.
SQL Data Definition II Stanislava Armstrong 1SQL Data Definition II.
CSC 2720 Building Web Applications Database and SQL.
Android course Database dr Milan Vidaković Chair of Informatics Faculty of Technical Sciences University of Novi Sad.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
SQLLite and Java CS-328 Dick Steflik. SQLLite Embedded RDBMS ACID Compliant Size – about 257 Kbytes Not a client/server architecture –Accessed via function.
SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight.
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Data Persistence in Android
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Database Rung-Hung Gau Department of Computer Science and Engineering
Agenda Journalling More Embedded SQL. Journalling.
Cosc 5/4730 Android Content Providers and Intents.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
Purdue Pride Joe Gutierrez Tung Ho Janam Jhaveri 4/7/2010Purdue Pride1.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
SQLite (part deux) 1 CS440. Traditional Model View Controller (MVC) CS440 2.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
1. Playing with SQLite Database  SQLite : Database specific name for Android Application  For windows there are several kind of database name : Mysql,
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Introduction to Database Programming with Python Gary Stewart
Relational Databases and SQL The relational model and the most common SQL commands.
Database Programming Code Dissection. Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java.
CS371m - Mobile Computing Persistence - SQLite. 2 In case you have not taken 347: Data Management or worked with databases as part of a job, internship,
Content Providers.
CS499 – Mobile Application Development
Making content providers
Data Storage: Part 3 (SQLite)
Database Access with SQL
Cosc 5/4730 Sqlite primer.
SQL – Python and Databases
SQLite in Android Landon Cox March 2, 2017.
Mobile Software Development for Android - I397
Insert, Update and the rest…
Mobile Applications (Android Programming)
Android Application SQLite 1.
SQL – More Table Constraints
Lecture 8: Database Topics: Basic SQLite Operations.
Mobile Computing With Android ACST Android Database Storage Part 2
CMPE419 Mobile Application Development
CS371m - Mobile Computing Persistence - SQLite.
CREATE, INSERT, SELECT.
Data Management Innovations 2017 High level overview of DB
SQL Application Persistence Design Patterns
Android Developer Fundamentals V2
Chapter 4 Introduction to MySQL.
ListView A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view. ListAdapter is used to.
Department of School of Computing and Engineering
SQLLite and Android.
Mobile Programming Dr. Mohsin Ali Memon.
SQL – Application Persistence Design Patterns
Database Instructor: Bei Kang.
SQL (Structured Query Language)
Presentation transcript:

Lecture 8: Database Topics: Basic SQLite Operations

Today’s class: Concepts Database, Table, Primary Key (Lecture) SQL Commands Android (code) Example of “Characters” database Create, Insert, Delete, Query

Database Bunch of tables having column headers where you store data—one datum in each row. Table: Characters Table: Appearance ID Name Home 1 John Winterfell 2 Tyrion Casterly Rock 3 Daenerys Dragon Stone Episode CharacterID Appeared 1 10 2 5 3 7 9 Power manage: wake lock, reboot.

1. Create and Drop Tables SQL: CREATE TABLE Characters ( ID INT PRIMARY KEY, NAME TEXT, HOME TEXT ); Table: Characters ID Name Home SQL: Power manage: wake lock, reboot. DROP TABLE IF EXISTS Characters;

2. Insert and Delete Rows DELETE FROM Characters SQL: Table: Characters INSERT INTO Characters VALUES (1, ‘John’, ‘Winterfell’); VALUES (2, ‘Tyrion’, ‘Casterly Rock’); VALUES (3, ‘Daenerys’, ‘Dragon Stone’); ID Name Home 1 John Winterfell 2 Tyrion Casterly Rock 3 Daenerys Dragon Stone Power manage: wake lock, reboot. SQL: Table: Characters DELETE FROM Characters WHERE Name = ‘John’ OR ID = 3; ID Name Home 2 Tyrion Casterly Rock

3. Query (single table) SQL: Output: SELECT ID, Name FROM Characters WHERE ID < 3; ID Name 1 John 2 Tyrion SQL: Output: SELECT * FROM Characters WHERE ID < 3; ID Name Home 1 John Winterfell 2 Tyrion Casterly Rock Power manage: wake lock, reboot.

3. Query (multiple table joined) Table: Characters SQL: ID Name Home 1 John Winterfell 2 Tyrion Casterly Rock 3 Daenerys Dragon Stone SELECT Name, Episode, Appeared FROM Characters, Appearance WHERE ID = CharacterID AND Episode = 1 AND Appeared < 10 Table: Appearance Episode CharacterID Appeared 1 10 2 5 3 7 9 Output: Power manage: wake lock, reboot. Name Episode Appeared Tyrion 1 5 Daenerys 7

Cursor Points to a row of the result of a query. Used to iterate over the rows: moveToFirst(), moveToNext() Used to get the value of a specific column: getString(column_index), getInt(column_index), etc. Output: ID Name Home 1 John Winterfell 2 Tyrion Casterly Rock 3 Daenerys Dragon Stone Power manage: wake lock, reboot.

Android SQLite (in 4 lines) SQL Operation Android Programming Open/Create Database SQLiteDatabase db = this.openOrCreateDatabase (“SomeDB", Context.MODE_PRIVATE, null); Create/Drop Table Insert/Delete Row db.execSQL(“ANY SQL COMMAND;”); Insert Row (using KEY/VAL pairs) ContentValues cv = new ContentValues(); cv.Put(KEY, VAL); db.insert(TABLE, null, cv); Select Cursor c = db.rawQuery(“SELECT ….;”, null); c.moveToFirst(); String s = c.getString(index); int n = c.getInt(index); byte[] ba = c.getBlob(index); c.moveToNext(); Power manage: wake lock, reboot.

Working with Blobs (e.g., image) SQL Operation Android Programming Bitmap to byte[] ByteArrayOutputStream stream = new ByteArrayOutputStream(); b.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] ba = stream.toByteArray(); byte[] to Bitmap Bitmap b = BitmapFactory.decodeByteArray(ba, 0, ba.length); Insert Row (using KEY/VAL pairs) ContentValues cv = new ContentValues(); cv.put(“Name”, “John Doe”); cv.put(“Photo”, ba); db.insert(TABLE_NAME, null, cv); Select Cursor c = db.rawQuery(“SELECT ….;”, null); c.moveToFirst(); String name = c.getString(0); Byte[] ba = c.getBlob(1); c.moveToNext(); Power manage: wake lock, reboot.

References (study these) https://developer.android.com/training/basics/data-storage/databases.html