Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight.

Similar presentations


Presentation on theme: "SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight."— Presentation transcript:

1 SQLite 1 CS440

2 What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight  More info at: http://www.sqlite.orghttp://www.sqlite.org CS440 2

3 Types in SQLite  TEXT (similar to String in Java)  INTEGER (similar to long in Java)  REAL (similar to double in Java) CS440 3

4 Getting started  Download SQLite: http://www.sqlite.org/download.html http://www.sqlite.org/download.html  Open a command prompt  Create your first db:  sqlite3 myDB.db  create table tbl1(one varchar(10), two smallint);  insert into tbl1 values('hello!',10);  insert into tbl1 values('goodbye', 20);  select * from tbl1; CS440 4

5 CREATE  Create a new table to add your data  Tables in databases are like excel spreadsheets CS440 5 CREATE TABLE employers ( _id INTEGER PRIMARY KEY, company_name TEXT); CREATE TABLE employees ( name TEXT, annual_salary REAL NOT NULL CHECK, employer_id REFERENCES employers(_id));

6 SQLite Types  TEXT  REAL  BLOB  INTEGER CS440 6

7 INSERT  Adds a new data row CS440 7 INSERT INTO contacts(first_name) VALUES(“Thomas”); INSERT INTO employers VALUES(1, “Acme Balloons”); INSERT INTO employees VALUES(“Wile E. Coyote”, 1000000.000, 1);

8 SELECT  Querying a database  Returns one or multiple rows of results CS440 8 SELECT * FROM contacts; SELECT first_name, height_in_meters FROM contacts WHERE last_name = “Smith”; SELECT employees.name, employers.name FROM employees, employers WHERE employee.employer_id = employer._id ORDER BY employer.company_name ASC;

9 References  http://www.vogella.de/articles/AndroidSQLite/arti cle.html#overview http://www.vogella.de/articles/AndroidSQLite/arti cle.html#overview CS440 9


Download ppt "SQLite 1 CS440. What is SQLite?  Open Source Database embedded in Android  SQL syntax  Requires small memory at runtime (250 Kbytes)  Lightweight."

Similar presentations


Ads by Google