Persistence 2: SQLite CS 344 Mobile App Development Robert Muller.

Slides:



Advertisements
Similar presentations
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Advertisements

IOS/SQLite CS328 Dick Steflik. Embedded Databases SQLite is the embedded database of choice for both the iOS and Android mobile platforms SQLite is called.
Overview Relational Databases and SQL Pertemuan 1 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
CSC 2720 Building Web Applications Database and SQL.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
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.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
MS Access 2007 IT User Services - University of Delaware.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
SQLite and PHP Wez Furlong Marcus Boerger LinuxTag 2003 Karlsruhe.
Introduction to SQL Steve Perry
Python MySQL Database Access
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
Stored Procedures, Triggers, Program Access Dr Lisa Ball 2008.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Chapter 4 Introduction to MySQL. MySQL “the world’s most popular open-source database application” “commonly used with PHP”
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
CSC 2720 Building Web Applications Database and SQL.
SQLite Supported by BlackBerry OS 5.0 Using SQLite.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Most information comes from Chapter 3, MySQL Tutorial: 1 MySQL: Part.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
Database Basics BCIS 3680 Enterprise Programming.
Relational Databases: Basic Concepts BCHB Lecture 21 By Edwards & Li Slides:
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Introduction to Database Programming with Python Gary Stewart
Data Persistence Sisoft Technologies Pvt Ltd
Cosc 5/4730 Sqlite primer.
SQL – Python and Databases
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Database application MySQL Database and PhpMyAdmin
EEC-492/693/793 iPhone Application Development
Creating Tables & Inserting Values Using SQL
Introduction To Structured Query Language (SQL)
Intro to Relational Databases
Computer Science Projects Database Theory / Prototypes
CS3220 Web and Internet Programming SQL and MySQL
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Department of School of Computing and Engineering
SQLLite and Android.
Presentation transcript:

Persistence 2: SQLite CS 344 Mobile App Development Robert Muller

Today SQL Concepts Using SQLite Demo CS 344 Mobile App Development - Muller

SQL Concepts SQL == Structured Query Language; Query a front-end connected to a database; SQL – very widely used; SQLite : A light-weight version of SQL; fast with a small footprint SQL/SQLite APIs available for most major programming languages: C, Java, Python, Ruby, … CS 344 Mobile App Development - Muller

An SQL Database is a Collection of Named Tables CS 344 Mobile App Development - Muller

An SQL Table has Columns (aka Fields) & Rows CS 344 Mobile App Development - Muller CountryContinentCapitalPopulationArea MexicoNorth AmericaMexico City106,000,0001,923,039 GhanaAfricaAccra23,000,000238,540 BoliviaSouth AmericaLa Paz9,000,0001,083,000 ItalyEuropeRome60,000,000301,230 FranceEuropeParis62,000,000545,630 Countries

Each column has a given Name and Datatype CS 344 Mobile App Development - Muller CountryContinentCapitalPopulationArea MexicoNorth AmericaMexico City106,000,0001,923,039 GhanaAfricaAccra23,000,000238,540 BoliviaSouth AmericaLa Paz9,000,0001,083,000 ItalyEuropeRome60,000,000301,230 FranceEuropeParis62,000,000545,630 Countries Continent : string Population : int

SQL Queries A client (human or software) can issue queries that can: – retrieve information from the database; – create new tables; – can modify one or more of the tables in the database. CS 344 Mobile App Development - Muller

CountryContinentCapitalPopulationArea MexicoNorth AmericaMexico City106,000,0001,923,039 GhanaAfricaAccra23,000,000238,540 BoliviaSouth AmericaLa Paz9,000,0001,083,000 ItalyEuropeRome60,000,000301,230 FranceEuropeParis62,000,000545,630 Countries sqlite> SELECT Country, Capital FROM Countries CountryCapital MexicoMexico City GhanaAccra BoliviaLa Paz ItalyRome FranceParis

CS 344 Mobile App Development - Muller

SQL Options Sql Framework must be linked into project DB made off-line and is read-only: – Can be made with sqlite3 command interface – Dropped into application bundle Read/write DB: – Can be made off-line, stashed in bundle and then copied to Documents – Can be made and modified in Documents DB is off-device CS 344 Mobile App Development - Muller

SQLite Interfaces Command Line/Shell APIs CS 344 Mobile App Development - Muller

SQL Command Line > sqlite3./mydatbase.db SQLite version Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> sqlite> create table contacts (id integer primary key autoincrement, name text, address text, phone text); sqlite>.tables contacts CS 344 Mobile App Development - Muller

SQL Command Line sqlite> insert into contacts (name, address, phone) values ("Michael Blair", "12 A Street, Berkeley CA", " "); sqlite> insert into contacts (name, address, phone) values ("Mike Parks", "10 Upping Street, Boise ID", “ "); sqlite> select * from contacts; 1|Michael Blair|12 A Street, Berkeley CA| |Mike Parks|10 Upping Street, Boise ID| sqlite> select * from contacts where name="Mike Parks"; 2|Mike Parks|10 Upping Street, Idaho| sqlite>.exit CS 344 Mobile App Development - Muller

Command Line Interface Populating the Countries Table /> sqlite3 sqlite> CREATE TABLE Countries (Country TEXT, Continent TEXT, Capital TEXT, Population integer, Area integer); sqlite> INSERT INTO Countries (Country, …, Area) VALUES (’Mexico’, …, ); sqlite> … CS 344 Mobile App Development - Muller

Linking the SQL Framework CS 344 Mobile App Development - Muller

Marshalling String Representations NSString *querySQL COURSE_NUMBER, TITLE FROM COURSE"; const char *query_stmt = [querySQL UTF8String]; CS 344 Mobile App Development - Muller

sqlite API sqlite3_open() - Opens specified database file. If the database file does not already exist, it is created. sqlite3_close() - Closes a previously opened database file. sqlite3_prepare_v2() - Prepares a SQL statement ready for execution. sqlite3_step() - Executes a SQL statement previously prepared by the sqlite3_prepare_v2() function. CS 344 Mobile App Development - Muller

sqlite API sqlite3_column_ () - Returns a data field from the results of a SQL retrieval operation where is replaced by the data type of the data to be extracted (text, blob, bytes, int, int16 etc). sqlite3_finalize() - Deletes a previously prepared SQL statement from memory. sqlite3_exec() - Combines the functionality of sqlite3_prepare_v2(), sqlite3_step() and sqlite3_finalize() into a single function call. CS 344 Mobile App Development - Muller

SQLite3 API for C : sqlite3.h int sqlite3_open(const char *filename, /* db filename */ sqlite3 **ppDb /* OUT: db handle */ ); CS 344 Mobile App Development - Muller

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = …); CS 344 Mobile App Development - Muller Problem: sqlite3_open wants to “return” 2 values: 1. a handle for an opened database, 2. a status indicator telling the caller what happened.

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = myDB); CS 344 Mobile App Development - Muller Stack Frame myDB 1000 “myFIle.db”

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = myDB); CS 344 Mobile App Development - Muller Stack Frame myDB 1000 “myFIle.db”

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = &myDB); CS 344 Mobile App Development - Muller Stack Frame myDB 1000 “myFIle.db”

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = &myDB); CS 344 Mobile App Development - Muller Stack Frame myDB 1000 “myFIle.db” 1000

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = &myDB); CS 344 Mobile App Development - Muller Stack Frame myDB 1000 “myFIle.db”

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = &myDB); CS 344 Mobile App Development - Muller Stack Frame myDB 1000 “myFIle.db” An Actual DB An Actual DB

Digression : Pass-by-reference in C sqlite3 *myDB = NULL; int stat = &myDB); CS 344 Mobile App Development - Muller myDB 1000 An Actual DB An Actual DB

SQLite3 API for C : exec int sqlite3_exec( sqlite3 *, /* An open db */ const char *sql, /* SQL cmd */ int (*callback)(void*, int, char**,char**), /* Callback function */ void *, /* 1st arg to callback */ char **errmsg /* Error msg */ ); CS 344 Mobile App Development - Muller

exec callbacks int sqlite3_exec(sqlite3 *,const char *sql, int (*callback)(void *, int, char**, char**), void *, char **errmsg); CS 344 Mobile App Development - Muller The callback is a function that will be executed once For each row in the relation resulting from the query.

Demo CS 344 Mobile App Development - Muller

Documentation & Tutorials See e.g., e_tutorial.html CS 344 Mobile App Development - Muller