SlideShare a Scribd company logo
1 of 152
Programming with SQLite ,[object Object],[object Object],[object Object]
Purpose of this Session ,[object Object],[object Object],[object Object]
Outline ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Outline ,[object Object]
I. Introducing SQLite
What is SQLite? ,[object Object],[object Object],[object Object]
What is SQLite? ,[object Object],[object Object],[object Object]
What is SQLite? ,[object Object],[object Object],[object Object]
History ,[object Object],[object Object]
History ,[object Object],[object Object]
History ,[object Object],[object Object],[object Object]
History ,[object Object],[object Object],[object Object],[object Object]
Who Uses SQLite? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQLite's Design Philosophy ,[object Object],[object Object]
SQLite's Design Philosophy ,[object Object],[object Object],[object Object]
How Flexible? ,[object Object],[object Object],[object Object],[object Object]
How Flexible? ,[object Object],[object Object]
How Compact? ,[object Object],[object Object],[object Object]
How Reliable? ,[object Object],[object Object],[object Object],[object Object]
How Portable? ,[object Object],[object Object],[object Object]
How Portable? ,[object Object],[object Object]
#define sqlite3OsEnterMutex #define sqlite3OsLeaveMutex  #define sqlite3OsInMutex #define sqlite3OsThreadSpecificData #define sqlite3OsMalloc #define sqlite3OsRealloc #define sqlite3OsFree #define sqlite3OsAllocationSize #define sqlite3OsDlopen  #define sqlite3OsDlsym #define sqlite3OsDlclose How Portable? #define sqlite3OsOpenReadWrite #define sqlite3OsOpenExclusive #define sqlite3OsOpenReadOnly #define sqlite3OsDelete #define sqlite3OsFileExists #define sqlite3OsFullPathname #define sqlite3OsIsDirWritable #define sqlite3OsSyncDirectory #define sqlite3OsTempFileName #define sqlite3OsRandomSeed #define sqlite3OsSleep #define sqlite3OsCurrentTime ,[object Object]
And ... ,[object Object]
II. Architecture
Subsystems ,[object Object],[object Object],[object Object],[object Object]
Subsystems ,[object Object]
 
The Virtual Database Engine ,[object Object],[object Object],[object Object],[object Object]
sqlite> CREATE TABLE x (a,b,c); sqlite> INSERT INTO x VALUES (1,2,3); sqlite> EXPLAIN SELECT * FROM x; addr  opcode  p1  p2  p3  ----  ---------------  ----  ----  ------- 0  Goto  0  12  1  Integer  0  0  # x  2  OpenRead  0  2  3  SetNumColumns  0  3  4  Rewind  0  10  5  Column  0  0  # x.a  6  Column  0  1  # x.b  7  Column  0  2  # x.c  8  Callback  3  0  9  Next  0  5  10  Close  0  0  11  Halt  0  0  12  Transaction  0  0  13  VerifyCookie  0  1  14  Goto  0  1  15  Noop  0  0
The Virtual Database Engine ,[object Object],[object Object],[object Object]
III. The API
Functions ,[object Object],[object Object],[object Object],[object Object]
Query Processing: Round 1 ,[object Object],[object Object],[object Object]
Query Processing: Round 1 ,[object Object],[object Object]
Example: Pseudocode # Open connection c1 = open('foods.db')‏ # Compile a statement stmt = c1.prepare('SELECT * FROM episodes')‏ # Execute and iterate over results while stmt.step()  print stmt.column('name')‏ end # Finalize statement stmt.finalize()‏ c1.close()‏
Example: C #include <sqlite3.h> int main(int argc, char **argv)‏ { int rc, i, ncols; sqlite3 *cnx; sqlite3_stmt *stmt; char *sql; const char *tail; /* Connect to database*/ sqlite3_open(&quot;db&quot;, &cnx); /* Prepare statement */ sql = &quot;SELECT * FROM x&quot;; sqlite3_prepare(cnx, sql, (int)strlen(sql), &stmt, &tail); /* Get the number of columns in statement */ ncols = sqlite3_column_count(stmt);
A Simple Example: C (cont.)‏ /* Iterate over result set. */ while(sqlite3_step(stmt) == SQLITE_ROW) { for(i=0; i < ncols; i++) { fprintf(stderr, &quot;'%s' &quot;, sqlite3_column_text(stmt, i)); } } /* Finalize */ sqlite3_finalize(stmt); /* Close database */ sqlite3_close(cnx); return 0;  }
Query Processing: Round 2 ,[object Object],[object Object],[object Object]
Query Processing: Round 2 ,[object Object],[object Object],[object Object]
Data Structures, Locks, and Storage c1 = open('foods.db')‏ c2 = open('foods.db')‏ stmt1 = c1.prepare('SELECT * FROM episodes')‏ stmt2 = c1.prepare('SELECT * FROM episodes')‏ stmt3 = c2.prepare('INSERT INTO episodes...')‏ stmt4 = c2.prepare('UPDATE episodes ...')‏ while stmt1.step()  print stmt1.column('name')‏ stmt4.step()‏ end ...
 
B-Tree and Pager ,[object Object],[object Object],[object Object]
B-Tree and Pager ,[object Object],[object Object],[object Object]
B-Tree and Pager ,[object Object],[object Object]
B-Tree and Pager ,[object Object],[object Object],[object Object]
Query Processing: Round 3 ,[object Object],[object Object],[object Object]
Query Processing: Round 3 /* Stripped down: */ /* The gist of executing a query. */ sqlite3_open(&quot;db&quot;, &cnx); sqlite3_prepare(cnx, SQL, sqllen, &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { /* Do something with row. */ } sqlite3_finalize(stmt);
 
sqlite> EXPLAIN SELECT * FROM x; addr  opcode  p1  p2  p3  ----  ---------------  ----  ----  ------- 0  Goto  0  12  1  Integer  0  0  # x  2  OpenRead  0  2  3  SetNumColumns  0  3  4  Rewind  0  10  5  Column  0  0  # x.a  6  Column  0  1  # x.b  7  Column  0  2  # x.c  8  Callback  3  0  9  Next  0  5  10  Close  0  0  11  Halt  0  0  12  Transaction  0  0  13  VerifyCookie  0  1  14  Goto  0  1  15  Noop  0  0
sqlite> EXPLAIN SELECT * FROM x; addr  opcode  p1  p2  p3  ----  ---------------  ----  ----  ------- 0  Goto  0  12  1  Integer  0  0  # x  2  OpenRead  0  2  3  SetNumColumns  0  3  4  Rewind  0  10  5  Column  0  0  # x.a  6  Column  0  1  # x.b  7  Column  0  2  # x.c  8  Callback  3  0  9  Next  0  5  10  Close  0  0  11  Halt  0  0  12  Transaction  0  0  13  VerifyCookie  0  1  14  Goto  0  1  15  Noop  0  0 Open a read-only cursor on table whose root page is 2. Load cols from  B-Tree row. Move cursor, start over or end Start transaction Return SQLITE_ROW Close cursor and end Start. Goto instruction 12 Goto instruction 1 Sanity check(s)‏ sqlite3_step()‏ Position cursor to first row. Return SQLITE_DONE
VDBE Instruction Cheat Sheet ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
 
Query Processing: Round 3 ,[object Object],[object Object],[object Object]
Query Processing: Round 3 ,[object Object],[object Object]
Query Processing: Round 3 ,[object Object]
Query Processing: Round 3 ,[object Object],[object Object]
Query Processing: Round 3 ,[object Object],[object Object]
Query Processing: Round 3 ,[object Object],[object Object]
Query Processing: Round 3 ,[object Object],[object Object]
IV. Transactions, Locks, and Cursors
Concurrency ,[object Object],[object Object],[object Object],[object Object]
Locking ,[object Object],[object Object],[object Object],[object Object]
 
Think in Pages ,[object Object],[object Object],[object Object],[object Object],[object Object]
Think in Pages ,[object Object],[object Object],[object Object],[object Object]
UNLOCKED ,[object Object],[object Object],[object Object],[object Object]
SHARED ,[object Object],[object Object],[object Object],[object Object]
RESERVED ,[object Object],[object Object],[object Object]
RESERVED ,[object Object],[object Object],[object Object],[object Object]
RESERVED ,[object Object],[object Object],[object Object]
RESERVED owens@linux $ sqlite3 foods.db SQLite version 3.3.17 Enter &quot;.help&quot; for instructions sqlite> begin; sqlite> update foods set type_id=0; sqlite>  ,[object Object],[object Object]
EXCLUSIVE ,[object Object],[object Object]
RESERVED vs. Exclusive ,[object Object],[object Object],[object Object],[object Object]
Read Scenario db = open('foods.db')‏ db.exec('BEGIN')‏ db.exec('SELECT * FROM episodes')‏ db.exec('SELECT * FROM episodes')‏ db.exec('COMMIT')‏ db.close()‏ ,[object Object]
Write Scenario db = open('foods.db')‏ db.exec('BEGIN')‏ db.exec('UPDATE episodes set ...')‏ db.exec('COMMIT')‏ db.close()‏ ,[object Object]
Auto-commit mode ,[object Object],[object Object],[object Object],[object Object]
Auto-commit mode ,[object Object],[object Object]
Auto-commit mode ,[object Object],[object Object]
SELECT-UPDATE Loops ,[object Object],[object Object],[object Object],[object Object]
SELECT-UPDATE Loops ,[object Object]
This Won't Work c1 = open('foods.db')‏ c2 = open('foods.db')‏ stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()  c2.exec('UPDATE episodes SET …)‏ end stmt.finalize()‏ c1.close()‏ c2.close()‏
Why Not? ,[object Object],[object Object],[object Object],[object Object]
Solution: Single Connection c1 = open('foods.db')‏ stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()  sql = 'UPDATE episodes SET …' c1.exec(sql)‏ end stmt.finalize()‏ c1.exec('COMMIT')‏ c1.close()‏
We Still Have Problems ,[object Object],[object Object],[object Object]
Brute Force stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()  sql = 'UPDATE episodes SET …' while c1.exec(sql) != SQLITE_OK # Keep trying until it works‏ end end
Actual Example #!/usr/bin/env lua require &quot;sqlite3&quot; db  = sqlite3.new()‏ stmt = sqlite3_stmt.new()‏ -- Connect to database sqlite3.open(db, &quot;foods.db&quot;)‏ -- Start a transaction if sqlite3.exec(db, &quot;BEGIN&quot;) ~= SQLITE_OK then print('BEGIN FAILED: ' .. sqlite3.errmsg(db))‏ return false end -- Compile a SELECT statement sql = 'SELECT id, type_id, name FROM foods ORDER BY id LIMIT 1' sqlite3.prepare(db, sql, stmt); -- Execute it. This is where an EXCLUSIVE lock will stop us local rc = sqlite3.step(stmt)‏ -- Check the value. If not SQLITE_ROW, we have a problem. if rc ~= SQLITE_ROW then print(&quot;SELECT FAILED: &quot; .. sqlite3.errmsg(db))‏ os.exit(1)‏ end
-- Iterate over result set while rc == SQLITE_ROW do -- Get the record id local id = sqlite3.column_int(stmt, 0)‏ print(&quot;Fetched row: id=&quot;..id)‏ -- Update the row. Keep trying until it goes through sql = 'UPDATE foods SET type_id = 100 WHERE id=' .. id while sqlite3.exec(db, sql) ~= SQLITE_OK do print('UPDATE FAILED: ' .. sqlite3.errmsg(db))‏ os.execute(&quot;sleep 1&quot;)‏ end -- Next row rc = sqlite3.step(stmt)‏ end -- Finalize sqlite3.finalize(stmt); -- Commit transaction if sqlite3.exec(db, &quot;COMMIT&quot;) ~= SQLITE_OK then print('COMMIT FAILED: ' .. sqlite3.errmsg(db))‏ return false end sqlite3.close(db)‏
Result: Deadlock ,[object Object],[object Object],[object Object]
Result: Deadlock ,[object Object],[object Object],[object Object],[object Object]
Resolution ,[object Object],[object Object],[object Object],[object Object]
Transaction Entry Points ,[object Object],[object Object],[object Object]
Suggested Approach c1 = open('foods.db')‏ while c1.exec('BEGIN IMMEDIATE') != SQLITE_SUCCESS end stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()‏ # Will always work because we're in RESERVED  c1.exec('UPDATE episodes SET …)‏ end stmt.finalize()‏ c1.exec('COMMIT')‏ c1.close()‏
SELECT-UPDATE Loop Rules ,[object Object],[object Object]
Pop Quiz sql = 'UPDATE ...' stmt = c1.prepare(sql)‏ while stmt.step() != SQLITE_DONE  # Keep trying end stmt.finalize()‏ ,[object Object],[object Object]
Pop Quiz ,[object Object],[object Object],[object Object],[object Object]
Pop Quiz # The correct place to apply brute force. while c1.exec('BEGIN IMMEDIATE') != SQLITE_OK end sql = 'UPDATE ...' stmt = c1.prepare(sql)‏ while stmt.step() != SQLITE_DONE  # Keep trying end stmt.finalize()‏ c1.exec('COMMIT')‏
Read Consistency ,[object Object],[object Object],[object Object],[object Object]
Example select_sql = 'SELECT * from foods where type_id > 0' ORDER BY type_id; update_sql = 'UPDATE foods set type_id=type_id+1 where' stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()‏ id = sqlite3_column_int(stmt, 0)‏ c1.exec(update_sql + 'id=' + id)‏ end
Cursor Sensitivity ,[object Object],[object Object],[object Object],[object Object],[object Object]
Actual Example #!/usr/bin/env lua require &quot;sqlite3&quot; [==[ Assumes the following in database: CREATE TABLE discounts ( product_id INTEGER PRIMARY KEY value INT ); INSERT INTO discounts (value) VALUES (1); ]==] function print_value(db)‏ local sql  = &quot;SELECT value FROM discounts&quot; local stmt = sqlite3_stmt.new()‏ local rc  = sqlite3.prepare(db, sql, stmt); if rc ~= SQLITE_OK then error(sqlite3.errmsg(db))‏ end sqlite3.step(stmt)‏ print(string.format( &quot;RESULT: value = %i&quot;,  sqlite3.column_int(stmt, 0)))‏ sqlite3.finalize(stmt); end
-- Connect to database db  = sqlite3.new()‏ stmt = sqlite3_stmt.new()‏ sqlite3.open(db, &quot;test.db&quot;)‏ -- Drop/recreat discounts table, if exists clear_table(db)‏ -- Create an index on the discount column sqlite3.exec(db, &quot;CREATE INDEX discounts_value_idx ON discounts(value)&quot;)‏ sql = &quot;SELECT * FROM discounts WHERE value > 0&quot; rc  = sqlite3.prepare(db, sql, stmt); if rc ~= SQLITE_OK then print('SQL ERROR: ' .. sqlite3.errmsg(db))‏ print(rc)‏ os.exit(1)‏ end -- Iterate through result set while sqlite3.step(stmt) == SQLITE_ROW do local id = sqlite3.column_int(stmt, 0)‏ local type_id = sqlite3.column_int(stmt, 1)‏ print(string.format(&quot;SQLITE_ROW: id=%-2i x=%-2i&quot;, id, type_id))‏ -- Increment value by 1 sqlite3.exec( db, &quot;UPDATE discounts SET value=value+1 &quot; .. &quot;  WHERE product_id=&quot; .. id )‏ end
-- Close statement handle sqlite3.finalize(stmt); -- Print the current value print_value(db)‏ -- Close database sqlite3.close(db)‏
Cursor Sensitivity ,[object Object],[object Object]
Cursor Sensitivity ,[object Object],[object Object]
Read Consistency ,[object Object],[object Object]
Read Consistency ,[object Object],[object Object],[object Object]
Consider Temporary Tables ,[object Object],[object Object],[object Object],[object Object]
Example c1 = open('foods.db')‏ c2 = open('foods.db')‏ c2.exec('CREATE TEMPORARY TABLE temp_epsidodes AS SELECT * from episodes')‏ stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()  print stmt.column('name')‏ c2.exec('UPDATE temp_episodes SET …')‏ end stmt.finalize()‏
c2.exec('BEGIN IMMEDIATE')‏ # Use conflict resolution to do the update in # in a single step c2.exec('REPLACE INTO episodes  SELECT * FROM temp_episodes')‏ c2.exec('COMMIT')‏ c1.close()‏ c2.close()‏
Page Cache 101 ,[object Object],[object Object],[object Object]
Page Cache 101 ,[object Object],[object Object],[object Object]
 
Page Cache 101: Page States ,[object Object],[object Object],[object Object]
Page Cache 101: Page Lists ,[object Object],[object Object],[object Object]
Page Cache 101: Cache Growth ,[object Object],[object Object],[object Object]
Page Cache 101: Allocation ,[object Object],[object Object],[object Object],[object Object]
Page Cache 101: Overhead ,[object Object],[object Object],[object Object]
Page Cache 101: Overhead ,[object Object],[object Object],[object Object]
Page Cache 101: Cache Sizing ,[object Object],[object Object],[object Object]
Page Cache 101: Cache Sizing *** Table FOODS w/o any indices ************************************** Percentage of total database..........  27.5%  Number of entries..................... 412  Bytes of storage consumed............. 11264  Bytes of payload...................... 7245  64.3%  Average payload per entry............. 17.58  Average unused bytes per entry........ 4.67  Average fanout........................ 10.00  Fragmentation......................... 60.0%  Maximum payload per entry............. 49  Entries that use overflow............. 0  0.0%  Index pages used...................... 1  Primary pages used.................... 10  Overflow pages used................... 0  Total pages used...................... 11  Unused bytes on index pages........... 942  92.0%  Unused bytes on primary pages......... 982  9.6%  Unused bytes on overflow pages........ 0  Unused bytes on all pages............. 1924  17.1%
Summary ,[object Object],[object Object]
Summary ,[object Object],[object Object],[object Object]
V. Features
Unique Features ,[object Object],[object Object]
Unique Features ,[object Object],[object Object]
Unique Features ,[object Object]
Interesting Features ,[object Object],[object Object]
#include <sqlite3ext.h> SQLITE_EXTENSION_INIT1 static void hello_newman( sqlite3_context *context, int argc, sqlite3_value **argv)‏ { sqlite3_result_text(context, &quot;Hello Jerry&quot;); } int newman_init( sqlite3 *db,  char **pzErrMsg,  const sqlite3_api_routines *pApi )‏ { SQLITE_EXTENSION_INIT2(pApi); sqlite3_create_function( db, &quot;hello_newman&quot;, 1,  SQLITE_ANY, 0,  hello_newman, 0, 0 ); return 0; }
owensmk $ gcc --shared examples/newman.c -o newman.so owensmk $ ./sqlite3 SQLite version 3.4.0 Enter &quot;.help&quot; for instructions sqlite> .load newman.so extension_init sqlite> select hello_newman(); Hello Jerry sqlite>
Interesting Features ,[object Object],[object Object]
VII. Limitations
Query Optimization ,[object Object],[object Object],SELECT * FROM foods WHERE rowid IN (SELECT rowid FROM foods WHERE name='Bagels' INTERSECT SELECT rowid FROM foods WHERE type_id=1);
Concurrency ,[object Object],[object Object],[object Object]
Network File Systems ,[object Object],[object Object],[object Object]
SQL Implementation ,[object Object],[object Object]
Database Size ,[object Object],[object Object],[object Object]
VI. Optimizations (and other dirty hacks)‏
Improving Concurrency ,[object Object],[object Object],[object Object]
Improving Speed ,[object Object],[object Object]
Improving Speed ,[object Object]
VIII. Review
Where SQLite Works ,[object Object],[object Object]
Where SQLite Works ,[object Object],[object Object],[object Object]
Where SQLite Works ,[object Object],[object Object]
Where SQLite Works ,[object Object],[object Object],[object Object]
Where SQLite Works ,[object Object],[object Object]
Where SQLite Works ,[object Object],[object Object],[object Object]
Where SQLite Doesn't Work ,[object Object],[object Object]
Where SQLite Doesn't Work ,[object Object],[object Object]
 
 

More Related Content

What's hot

javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.pptsentayehu
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)Laura Folgado Galache
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Intro ProxySQL
Intro ProxySQLIntro ProxySQL
Intro ProxySQLI Goo Lee
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorAlmost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorJean-François Gagné
 
Asp.net mvc 概觀介紹
Asp.net mvc 概觀介紹Asp.net mvc 概觀介紹
Asp.net mvc 概觀介紹Alan Tsai
 
GitFlow, SourceTree and GitLab
GitFlow, SourceTree and GitLabGitFlow, SourceTree and GitLab
GitFlow, SourceTree and GitLabShinu Suresh
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11Kenny Gryp
 

What's hot (20)

javaScript.ppt
javaScript.pptjavaScript.ppt
javaScript.ppt
 
Bootstrap 4 ppt
Bootstrap 4 pptBootstrap 4 ppt
Bootstrap 4 ppt
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Source control
Source controlSource control
Source control
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 
6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)6. Utilización del modelo de objetos del documento (DOM)
6. Utilización del modelo de objetos del documento (DOM)
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
Galera Cluster Best Practices for DBA's and DevOps Part 1
Galera Cluster Best Practices for DBA's and DevOps Part 1Galera Cluster Best Practices for DBA's and DevOps Part 1
Galera Cluster Best Practices for DBA's and DevOps Part 1
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Intro ProxySQL
Intro ProxySQLIntro ProxySQL
Intro ProxySQL
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and OrchestratorAlmost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Asp.net mvc 概觀介紹
Asp.net mvc 概觀介紹Asp.net mvc 概觀介紹
Asp.net mvc 概觀介紹
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
 
Bootstrap 5 basic
Bootstrap 5 basicBootstrap 5 basic
Bootstrap 5 basic
 
GitFlow, SourceTree and GitLab
GitFlow, SourceTree and GitLabGitFlow, SourceTree and GitLab
GitFlow, SourceTree and GitLab
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
 

Similar to Os Owens

android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51Mark Ginnebaugh
 
Getting Started with Sql Server Compact Edition
Getting Started with Sql Server Compact EditionGetting Started with Sql Server Compact Edition
Getting Started with Sql Server Compact EditionDonRobins
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for AndroidJakir Hossain
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on RailsViridians
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 
cPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturescPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturesDave Stokes
 
Online Fitness Gym Documentation
Online Fitness Gym Documentation Online Fitness Gym Documentation
Online Fitness Gym Documentation Abhishek Patel
 
Sql interview question part 10
Sql interview question part 10Sql interview question part 10
Sql interview question part 10kaashiv1
 
Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Enkitec
 
Experiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamExperiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamBrian Benz
 
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing ItYou Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing ItAleksandr Yampolskiy
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developerswebhostingguy
 
Dr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. HydeDr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. Hydewebhostingguy
 

Similar to Os Owens (20)

android sqlite
android sqliteandroid sqlite
android sqlite
 
Sql lite presentation
Sql lite presentationSql lite presentation
Sql lite presentation
 
Sq lite
Sq liteSq lite
Sq lite
 
Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51
 
Getting Started with Sql Server Compact Edition
Getting Started with Sql Server Compact EditionGetting Started with Sql Server Compact Edition
Getting Started with Sql Server Compact Edition
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
Sqlite
SqliteSqlite
Sqlite
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
Industrial training
Industrial trainingIndustrial training
Industrial training
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
cPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturescPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven Features
 
Online Fitness Gym Documentation
Online Fitness Gym Documentation Online Fitness Gym Documentation
Online Fitness Gym Documentation
 
Sql interview question part 10
Sql interview question part 10Sql interview question part 10
Sql interview question part 10
 
Ebook10
Ebook10Ebook10
Ebook10
 
Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12Kelly potvin nosurprises_odtug_oow12
Kelly potvin nosurprises_odtug_oow12
 
Experiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamExperiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure team
 
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing ItYou Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
You Too Can Be a Radio Host Or How We Scaled a .NET Startup And Had Fun Doing It
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developers
 
Dr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. HydeDr. Jekyll and Mr. Hyde
Dr. Jekyll and Mr. Hyde
 
Sq lite
Sq liteSq lite
Sq lite
 

More from oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifmoscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Moleoscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashearsoscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swposcon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Mythsoscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillipsoscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdatedoscon2007
 

More from oscon2007 (20)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
 
Os Borger
Os BorgerOs Borger
Os Borger
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
 
Os Fogel
Os FogelOs Fogel
Os Fogel
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
 

Recently uploaded

Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxWorkforce Group
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Centuryrwgiffor
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfAmzadHosen3
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
 
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyEthan lee
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLSeo
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataExhibitors Data
 

Recently uploaded (20)

Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
John Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdfJohn Halpern sued for sexual assault.pdf
John Halpern sued for sexual assault.pdf
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
 
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRLMONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
MONA 98765-12871 CALL GIRLS IN LUDHIANA LUDHIANA CALL GIRL
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
 
RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 

Os Owens

  • 1.
  • 2.
  • 3.
  • 4.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 25.
  • 26.
  • 27.  
  • 28.
  • 29. sqlite> CREATE TABLE x (a,b,c); sqlite> INSERT INTO x VALUES (1,2,3); sqlite> EXPLAIN SELECT * FROM x; addr opcode p1 p2 p3 ---- --------------- ---- ---- ------- 0 Goto 0 12 1 Integer 0 0 # x 2 OpenRead 0 2 3 SetNumColumns 0 3 4 Rewind 0 10 5 Column 0 0 # x.a 6 Column 0 1 # x.b 7 Column 0 2 # x.c 8 Callback 3 0 9 Next 0 5 10 Close 0 0 11 Halt 0 0 12 Transaction 0 0 13 VerifyCookie 0 1 14 Goto 0 1 15 Noop 0 0
  • 30.
  • 32.
  • 33.
  • 34.
  • 35. Example: Pseudocode # Open connection c1 = open('foods.db')‏ # Compile a statement stmt = c1.prepare('SELECT * FROM episodes')‏ # Execute and iterate over results while stmt.step() print stmt.column('name')‏ end # Finalize statement stmt.finalize()‏ c1.close()‏
  • 36. Example: C #include <sqlite3.h> int main(int argc, char **argv)‏ { int rc, i, ncols; sqlite3 *cnx; sqlite3_stmt *stmt; char *sql; const char *tail; /* Connect to database*/ sqlite3_open(&quot;db&quot;, &cnx); /* Prepare statement */ sql = &quot;SELECT * FROM x&quot;; sqlite3_prepare(cnx, sql, (int)strlen(sql), &stmt, &tail); /* Get the number of columns in statement */ ncols = sqlite3_column_count(stmt);
  • 37. A Simple Example: C (cont.)‏ /* Iterate over result set. */ while(sqlite3_step(stmt) == SQLITE_ROW) { for(i=0; i < ncols; i++) { fprintf(stderr, &quot;'%s' &quot;, sqlite3_column_text(stmt, i)); } } /* Finalize */ sqlite3_finalize(stmt); /* Close database */ sqlite3_close(cnx); return 0; }
  • 38.
  • 39.
  • 40. Data Structures, Locks, and Storage c1 = open('foods.db')‏ c2 = open('foods.db')‏ stmt1 = c1.prepare('SELECT * FROM episodes')‏ stmt2 = c1.prepare('SELECT * FROM episodes')‏ stmt3 = c2.prepare('INSERT INTO episodes...')‏ stmt4 = c2.prepare('UPDATE episodes ...')‏ while stmt1.step() print stmt1.column('name')‏ stmt4.step()‏ end ...
  • 41.  
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. Query Processing: Round 3 /* Stripped down: */ /* The gist of executing a query. */ sqlite3_open(&quot;db&quot;, &cnx); sqlite3_prepare(cnx, SQL, sqllen, &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { /* Do something with row. */ } sqlite3_finalize(stmt);
  • 48.  
  • 49. sqlite> EXPLAIN SELECT * FROM x; addr opcode p1 p2 p3 ---- --------------- ---- ---- ------- 0 Goto 0 12 1 Integer 0 0 # x 2 OpenRead 0 2 3 SetNumColumns 0 3 4 Rewind 0 10 5 Column 0 0 # x.a 6 Column 0 1 # x.b 7 Column 0 2 # x.c 8 Callback 3 0 9 Next 0 5 10 Close 0 0 11 Halt 0 0 12 Transaction 0 0 13 VerifyCookie 0 1 14 Goto 0 1 15 Noop 0 0
  • 50. sqlite> EXPLAIN SELECT * FROM x; addr opcode p1 p2 p3 ---- --------------- ---- ---- ------- 0 Goto 0 12 1 Integer 0 0 # x 2 OpenRead 0 2 3 SetNumColumns 0 3 4 Rewind 0 10 5 Column 0 0 # x.a 6 Column 0 1 # x.b 7 Column 0 2 # x.c 8 Callback 3 0 9 Next 0 5 10 Close 0 0 11 Halt 0 0 12 Transaction 0 0 13 VerifyCookie 0 1 14 Goto 0 1 15 Noop 0 0 Open a read-only cursor on table whose root page is 2. Load cols from B-Tree row. Move cursor, start over or end Start transaction Return SQLITE_ROW Close cursor and end Start. Goto instruction 12 Goto instruction 1 Sanity check(s)‏ sqlite3_step()‏ Position cursor to first row. Return SQLITE_DONE
  • 51.
  • 52.  
  • 53.  
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 62.
  • 63.
  • 64.  
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82. This Won't Work c1 = open('foods.db')‏ c2 = open('foods.db')‏ stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step() c2.exec('UPDATE episodes SET …)‏ end stmt.finalize()‏ c1.close()‏ c2.close()‏
  • 83.
  • 84. Solution: Single Connection c1 = open('foods.db')‏ stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step() sql = 'UPDATE episodes SET …' c1.exec(sql)‏ end stmt.finalize()‏ c1.exec('COMMIT')‏ c1.close()‏
  • 85.
  • 86. Brute Force stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step() sql = 'UPDATE episodes SET …' while c1.exec(sql) != SQLITE_OK # Keep trying until it works‏ end end
  • 87. Actual Example #!/usr/bin/env lua require &quot;sqlite3&quot; db = sqlite3.new()‏ stmt = sqlite3_stmt.new()‏ -- Connect to database sqlite3.open(db, &quot;foods.db&quot;)‏ -- Start a transaction if sqlite3.exec(db, &quot;BEGIN&quot;) ~= SQLITE_OK then print('BEGIN FAILED: ' .. sqlite3.errmsg(db))‏ return false end -- Compile a SELECT statement sql = 'SELECT id, type_id, name FROM foods ORDER BY id LIMIT 1' sqlite3.prepare(db, sql, stmt); -- Execute it. This is where an EXCLUSIVE lock will stop us local rc = sqlite3.step(stmt)‏ -- Check the value. If not SQLITE_ROW, we have a problem. if rc ~= SQLITE_ROW then print(&quot;SELECT FAILED: &quot; .. sqlite3.errmsg(db))‏ os.exit(1)‏ end
  • 88. -- Iterate over result set while rc == SQLITE_ROW do -- Get the record id local id = sqlite3.column_int(stmt, 0)‏ print(&quot;Fetched row: id=&quot;..id)‏ -- Update the row. Keep trying until it goes through sql = 'UPDATE foods SET type_id = 100 WHERE id=' .. id while sqlite3.exec(db, sql) ~= SQLITE_OK do print('UPDATE FAILED: ' .. sqlite3.errmsg(db))‏ os.execute(&quot;sleep 1&quot;)‏ end -- Next row rc = sqlite3.step(stmt)‏ end -- Finalize sqlite3.finalize(stmt); -- Commit transaction if sqlite3.exec(db, &quot;COMMIT&quot;) ~= SQLITE_OK then print('COMMIT FAILED: ' .. sqlite3.errmsg(db))‏ return false end sqlite3.close(db)‏
  • 89.
  • 90.
  • 91.
  • 92.
  • 93. Suggested Approach c1 = open('foods.db')‏ while c1.exec('BEGIN IMMEDIATE') != SQLITE_SUCCESS end stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()‏ # Will always work because we're in RESERVED c1.exec('UPDATE episodes SET …)‏ end stmt.finalize()‏ c1.exec('COMMIT')‏ c1.close()‏
  • 94.
  • 95.
  • 96.
  • 97. Pop Quiz # The correct place to apply brute force. while c1.exec('BEGIN IMMEDIATE') != SQLITE_OK end sql = 'UPDATE ...' stmt = c1.prepare(sql)‏ while stmt.step() != SQLITE_DONE # Keep trying end stmt.finalize()‏ c1.exec('COMMIT')‏
  • 98.
  • 99. Example select_sql = 'SELECT * from foods where type_id > 0' ORDER BY type_id; update_sql = 'UPDATE foods set type_id=type_id+1 where' stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step()‏ id = sqlite3_column_int(stmt, 0)‏ c1.exec(update_sql + 'id=' + id)‏ end
  • 100.
  • 101. Actual Example #!/usr/bin/env lua require &quot;sqlite3&quot; [==[ Assumes the following in database: CREATE TABLE discounts ( product_id INTEGER PRIMARY KEY value INT ); INSERT INTO discounts (value) VALUES (1); ]==] function print_value(db)‏ local sql = &quot;SELECT value FROM discounts&quot; local stmt = sqlite3_stmt.new()‏ local rc = sqlite3.prepare(db, sql, stmt); if rc ~= SQLITE_OK then error(sqlite3.errmsg(db))‏ end sqlite3.step(stmt)‏ print(string.format( &quot;RESULT: value = %i&quot;, sqlite3.column_int(stmt, 0)))‏ sqlite3.finalize(stmt); end
  • 102. -- Connect to database db = sqlite3.new()‏ stmt = sqlite3_stmt.new()‏ sqlite3.open(db, &quot;test.db&quot;)‏ -- Drop/recreat discounts table, if exists clear_table(db)‏ -- Create an index on the discount column sqlite3.exec(db, &quot;CREATE INDEX discounts_value_idx ON discounts(value)&quot;)‏ sql = &quot;SELECT * FROM discounts WHERE value > 0&quot; rc = sqlite3.prepare(db, sql, stmt); if rc ~= SQLITE_OK then print('SQL ERROR: ' .. sqlite3.errmsg(db))‏ print(rc)‏ os.exit(1)‏ end -- Iterate through result set while sqlite3.step(stmt) == SQLITE_ROW do local id = sqlite3.column_int(stmt, 0)‏ local type_id = sqlite3.column_int(stmt, 1)‏ print(string.format(&quot;SQLITE_ROW: id=%-2i x=%-2i&quot;, id, type_id))‏ -- Increment value by 1 sqlite3.exec( db, &quot;UPDATE discounts SET value=value+1 &quot; .. &quot; WHERE product_id=&quot; .. id )‏ end
  • 103. -- Close statement handle sqlite3.finalize(stmt); -- Print the current value print_value(db)‏ -- Close database sqlite3.close(db)‏
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109. Example c1 = open('foods.db')‏ c2 = open('foods.db')‏ c2.exec('CREATE TEMPORARY TABLE temp_epsidodes AS SELECT * from episodes')‏ stmt = c1.prepare('SELECT * FROM episodes')‏ while stmt.step() print stmt.column('name')‏ c2.exec('UPDATE temp_episodes SET …')‏ end stmt.finalize()‏
  • 110. c2.exec('BEGIN IMMEDIATE')‏ # Use conflict resolution to do the update in # in a single step c2.exec('REPLACE INTO episodes SELECT * FROM temp_episodes')‏ c2.exec('COMMIT')‏ c1.close()‏ c2.close()‏
  • 111.
  • 112.
  • 113.  
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121. Page Cache 101: Cache Sizing *** Table FOODS w/o any indices ************************************** Percentage of total database.......... 27.5% Number of entries..................... 412 Bytes of storage consumed............. 11264 Bytes of payload...................... 7245 64.3% Average payload per entry............. 17.58 Average unused bytes per entry........ 4.67 Average fanout........................ 10.00 Fragmentation......................... 60.0% Maximum payload per entry............. 49 Entries that use overflow............. 0 0.0% Index pages used...................... 1 Primary pages used.................... 10 Overflow pages used................... 0 Total pages used...................... 11 Unused bytes on index pages........... 942 92.0% Unused bytes on primary pages......... 982 9.6% Unused bytes on overflow pages........ 0 Unused bytes on all pages............. 1924 17.1%
  • 122.
  • 123.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129. #include <sqlite3ext.h> SQLITE_EXTENSION_INIT1 static void hello_newman( sqlite3_context *context, int argc, sqlite3_value **argv)‏ { sqlite3_result_text(context, &quot;Hello Jerry&quot;); } int newman_init( sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi )‏ { SQLITE_EXTENSION_INIT2(pApi); sqlite3_create_function( db, &quot;hello_newman&quot;, 1, SQLITE_ANY, 0, hello_newman, 0, 0 ); return 0; }
  • 130. owensmk $ gcc --shared examples/newman.c -o newman.so owensmk $ ./sqlite3 SQLite version 3.4.0 Enter &quot;.help&quot; for instructions sqlite> .load newman.so extension_init sqlite> select hello_newman(); Hello Jerry sqlite>
  • 131.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138. VI. Optimizations (and other dirty hacks)‏
  • 139.
  • 140.
  • 141.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.  
  • 152.