SlideShare une entreprise Scribd logo
1  sur  45
SQLite 3
  Scott MacVicar
PHP Barcelona 2008
Who Am I?


• Employed by Jelsoft Enterprises Ltd
• PHP (SQLite3, imagick, svn)
• GD
Overview

• What is SQLite?
• Why use SQLite?
• Who uses SQLite?
• SQLite Explained
• Difference between SQLite 2 and 3
• PDO / SQLite3
What is SQLite?

• Embedded SQL Database Engine
• Serverless - accesses disk directly
• Single file
• Cross Platform / Architecture
• Small footprint
• Manifest typing
Why use SQLite?


• Zero Configuration
• Portable
• Public Domain
Public Domain?


May you do good and not evil.

May you find forgiveness for yourself and forgive others.

May you share freely, never taking more than you give.
¿Public Domain?
Big SQLite Users



                                            •   Lightroom

                                            •   AIR


sqlite3 ~/Pictures/Lightroom/Lightroom Library.aglib
Big SQLite Users

•   Mail

•   Safari

•   Aperture

•   Core Data

•   iPhone
             sqlite3 ~/Library/Mail/Envelope Index
             sqlite3 ~/Library/Caches/com.apple.Safari/Cache.db
             sqlite3 ~/Pictures/Aperture Library.aplibrary/Aperture.aplib
Big SQLite Users



           •   Gears

           •   Android
Big SQLite Users




•   Virus Information
Big SQLite Users


           •   History

           •   Bookmarks

           •   Downloads
Big SQLite Users




•   Metadata
Where can SQLite be used?

• Replacement for a custom file format
• Temporary data storage (Unit Tests) - :memory:
• Alternative to enterprise DB for demo
• Local node storage
• Communication between apps
• Embedded Devices
Versions


• SQLite - 2.8.17
• PDO - 3.3.7 + 2.8.17   (3.6.2 in PHP 5.3)

• SQLite3 - 3.6.2, minimum is 3.3.9
SQLite 3
•   64-bit Rowids            •   Connections shared
                                 between threads
•   BLOB support
                             •   Runtime loadable
•   Improved concurrency         extensions

•   UTF-16 / UTF-8           •   Fulltext searching

•   User defined collations   •   ICU support

•   Named bound              •   OS Interface
    parameters
SQLite v2

• Smaller subset of SQL supported
• Larger file format
• Database format incompatible with v3
• No Unicode support
• No reading while writing
Examples


• Firefox 3.0
  • Profile directory contains places.sqlite
  • Schema on the next page
• iPhone SMS
Firefox Places Schema
PDO
SQLite3
Live Demo (Hopefully)
iPhone SMS Schema




 /private/var/root/Library/SMS/sms.db
 ~/Library/Application Support/MobileSync/Backup
Custom Functions


• Define SQL Functions in PHP
• Implement missing features
• Aggregation functions
Function Example
Custom Collations

•   Sorting in alphabetical   ☹   ☺
    order
                              a   a
•   ICU also provides this    i   é
    functionality
                              u   i
•   Use createCollation to    é   ó
    define comparison          ó   u
    function
Fulltext Indexing
Fulltext Searching
SQLite3 Extension

        SQLite3        SQLite3Stmt
open              paramCount
close             close
exec              execute
version           reset
lastInsertRowID   clear
loadExtension     bindValue
escapeString      bindParam
prepare
query
createFunction
createAggregate
lastErrorMsg
SQLite3 Extension

   SQLite3Result
fetchArray
reset
finalize
columnType
columnName
numColumns
Improving Performance

• Pragma
  • cache_size
  • fullfsync
  • synchronous
• Shared Cache
• Use Transactions
Benchmarks


•   Dual Xeon 3.2GHz,
    2GB RAM, Centos 5

•   MySQL vs SQLite

•   Synthetic Benchmark -
    YMMV
                            Original Image by Ben McLeod
Benchmarks - Tests

• 15 tests
• INSERT
• SELECT
• UPDATE
• DELETE
• DROP
Benchmarks - Insert
                          MySQL
10.0                      SQLite 2
                          SQLite 3
 7.5                      SQLite 3 (nosync)

 5.0

 2.5

  0
        Test 1   Test 2
Benchmarks - Select
                          MySQL
10.0                      SQLite 2
                          SQLite 3
 7.5                      SQLite 3 (nosync)

 5.0

 2.5

  0
        Test 3   Test 4
Benchmarks - Indices
                         MySQL
1.2                      SQLite 2
                         SQLite 3
0.9                      SQLite 3 (nosync)

0.6

0.3

 0
       Test 5   Test 6
Benchmarks - Update
                                   MySQL
5.00                               SQLite 2
                                   SQLite 3
3.75                               SQLite 3 (nosync)

2.50

1.25

  0
        Test 7   Test 8   Test 9
Benchmarks - Delete
                                        MySQL
2.0                                     SQLite 2
                                        SQLite 3
1.6
                                        SQLite 3 (nosync)
1.2

0.8

0.4

 0
      Test 11   Test 12   Test 13   Test 14
Benchmarks - Summary


• SQLite 3 is faster in almost every test
• Using MyISAM would show faster results
• Doesn’t test concurrency
Converting from MySQL

• varchar, char -> text
• smallint, tinyint, int -> integer
• auto_increment -> autoincrement
• unknown types converted to text
• MySQLi functions have SQLite3 equivalents
Unsupported SQL - Examples




                Original Image by Clive Arundell
Limitations

• Very large datasets
• High concurrency
• No Foreign Keys
• Nested Transactions
• Writing to Views
Miscellaneous


•   Integrity Check

•   Reclaim Unused Space

•   Backup
Tools - SQLite Manager
Resources

• http://www.sqlite.org
• http://www.php.net/sqlite3
• http://pecl.php.net/sqlite3
• http://talks.macvicar.net
• https://addons.mozilla.org/en-US/firefox/
 addon/5817

Contenu connexe

Tendances

Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
Yogiji Creations
 
Oracle Database Overview
Oracle Database OverviewOracle Database Overview
Oracle Database Overview
honglee71
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 

Tendances (20)

Oracle database performance tuning
Oracle database performance tuningOracle database performance tuning
Oracle database performance tuning
 
Pl sql student guide v 1
Pl sql student guide v 1Pl sql student guide v 1
Pl sql student guide v 1
 
Postgresql
PostgresqlPostgresql
Postgresql
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Oracle Database Overview
Oracle Database OverviewOracle Database Overview
Oracle Database Overview
 
Oracle Database | Computer Science
Oracle Database | Computer ScienceOracle Database | Computer Science
Oracle Database | Computer Science
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
MySQL Cookbook: Recipes for Your Business
MySQL Cookbook: Recipes for Your BusinessMySQL Cookbook: Recipes for Your Business
MySQL Cookbook: Recipes for Your Business
 
ETL Testing Training Presentation
ETL Testing Training PresentationETL Testing Training Presentation
ETL Testing Training Presentation
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
Understanding index
Understanding indexUnderstanding index
Understanding index
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
RMAN in 12c: The Next Generation (PPT)
RMAN in 12c: The Next Generation (PPT)RMAN in 12c: The Next Generation (PPT)
RMAN in 12c: The Next Generation (PPT)
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS Schema
 
Pl lab solution
Pl lab solutionPl lab solution
Pl lab solution
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWR
 
SQL commands
SQL commandsSQL commands
SQL commands
 

En vedette

Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
Stanley Huang
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
Warawut
 
Advance sqlite3
Advance sqlite3Advance sqlite3
Advance sqlite3
Raghu nath
 
Sqlite3 command reference
Sqlite3 command referenceSqlite3 command reference
Sqlite3 command reference
Raghu nath
 

En vedette (20)

SQLite - Overview
SQLite - OverviewSQLite - Overview
SQLite - Overview
 
SQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management SystemSQLite: Light, Open Source Relational Database Management System
SQLite: Light, Open Source Relational Database Management System
 
Sqlite
SqliteSqlite
Sqlite
 
Introduction4 SQLite
Introduction4 SQLiteIntroduction4 SQLite
Introduction4 SQLite
 
SQLite3
SQLite3SQLite3
SQLite3
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
 
SQLite Techniques
SQLite TechniquesSQLite Techniques
SQLite Techniques
 
Sqlite
SqliteSqlite
Sqlite
 
SQLite
SQLiteSQLite
SQLite
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
 
SQLite
SQLiteSQLite
SQLite
 
Access ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-FrontendsAccess ohne Access: Freie Datenbank-Frontends
Access ohne Access: Freie Datenbank-Frontends
 
Advance sqlite3
Advance sqlite3Advance sqlite3
Advance sqlite3
 
(140625) #fitalk sq lite 소개와 구조 분석
(140625) #fitalk   sq lite 소개와 구조 분석(140625) #fitalk   sq lite 소개와 구조 분석
(140625) #fitalk sq lite 소개와 구조 분석
 
In01 - Programmation Android - 05 - Google map
In01 - Programmation Android - 05 - Google mapIn01 - Programmation Android - 05 - Google map
In01 - Programmation Android - 05 - Google map
 
In01 - Programmation Android - 03 - HMI
In01 - Programmation Android - 03 - HMIIn01 - Programmation Android - 03 - HMI
In01 - Programmation Android - 03 - HMI
 
Python sqlite3 - flask
Python   sqlite3 - flaskPython   sqlite3 - flask
Python sqlite3 - flask
 
Aula 06 - TEP - Introdução SQLite
Aula 06 - TEP - Introdução SQLiteAula 06 - TEP - Introdução SQLite
Aula 06 - TEP - Introdução SQLite
 
Sqlite3 command reference
Sqlite3 command referenceSqlite3 command reference
Sqlite3 command reference
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
 

Similaire à SQLite 3

Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACPerformance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Kristofferson A
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
Jakir Hossain
 

Similaire à SQLite 3 (20)

ASP.NET MVC Performance
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performance
 
Qure Tech Presentation
Qure Tech PresentationQure Tech Presentation
Qure Tech Presentation
 
Database automated build and test - SQL In The City Cambridge
Database automated build and test - SQL In The City CambridgeDatabase automated build and test - SQL In The City Cambridge
Database automated build and test - SQL In The City Cambridge
 
MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
My sql 56_roadmap_april2012
My sql 56_roadmap_april2012My sql 56_roadmap_april2012
My sql 56_roadmap_april2012
 
Nadzor sql a
Nadzor sql aNadzor sql a
Nadzor sql a
 
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RACPerformance Scenario: Diagnosing and resolving sudden slow down on two node RAC
Performance Scenario: Diagnosing and resolving sudden slow down on two node RAC
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
What's New in MySQL 5.7
What's New in MySQL 5.7What's New in MySQL 5.7
What's New in MySQL 5.7
 
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines SlidesMySQL Cluster 7.3 Performance Tuning - Severalnines Slides
MySQL Cluster 7.3 Performance Tuning - Severalnines Slides
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
 
MySQL Aquarium Paris
MySQL Aquarium ParisMySQL Aquarium Paris
MySQL Aquarium Paris
 
OpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL CloneOpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL Clone
 
My sql crashcourse_intro_kdl
My sql crashcourse_intro_kdlMy sql crashcourse_intro_kdl
My sql crashcourse_intro_kdl
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL Azure
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
Exploring mysql cluster 7.4
Exploring mysql cluster 7.4Exploring mysql cluster 7.4
Exploring mysql cluster 7.4
 

Plus de Scott MacVicar

Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
Scott MacVicar
 
Caching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingCaching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and Profiling
Scott MacVicar
 
How to write PHPT tests
How to write PHPT testsHow to write PHPT tests
How to write PHPT tests
Scott MacVicar
 

Plus de Scott MacVicar (7)

Alternative Databases
Alternative DatabasesAlternative Databases
Alternative Databases
 
Caching for Cash: Caching
Caching for Cash: CachingCaching for Cash: Caching
Caching for Cash: Caching
 
Caching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and ProfilingCaching for Cash: Benchmarking and Profiling
Caching for Cash: Benchmarking and Profiling
 
PHP 5.3 + Windows
PHP 5.3 + WindowsPHP 5.3 + Windows
PHP 5.3 + Windows
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Alternative Databases
Alternative DatabasesAlternative Databases
Alternative Databases
 
How to write PHPT tests
How to write PHPT testsHow to write PHPT tests
How to write PHPT tests
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 

SQLite 3

  • 1. SQLite 3 Scott MacVicar PHP Barcelona 2008
  • 2. Who Am I? • Employed by Jelsoft Enterprises Ltd • PHP (SQLite3, imagick, svn) • GD
  • 3. Overview • What is SQLite? • Why use SQLite? • Who uses SQLite? • SQLite Explained • Difference between SQLite 2 and 3 • PDO / SQLite3
  • 4. What is SQLite? • Embedded SQL Database Engine • Serverless - accesses disk directly • Single file • Cross Platform / Architecture • Small footprint • Manifest typing
  • 5. Why use SQLite? • Zero Configuration • Portable • Public Domain
  • 6. Public Domain? May you do good and not evil. May you find forgiveness for yourself and forgive others. May you share freely, never taking more than you give.
  • 8. Big SQLite Users • Lightroom • AIR sqlite3 ~/Pictures/Lightroom/Lightroom Library.aglib
  • 9. Big SQLite Users • Mail • Safari • Aperture • Core Data • iPhone sqlite3 ~/Library/Mail/Envelope Index sqlite3 ~/Library/Caches/com.apple.Safari/Cache.db sqlite3 ~/Pictures/Aperture Library.aplibrary/Aperture.aplib
  • 10. Big SQLite Users • Gears • Android
  • 11. Big SQLite Users • Virus Information
  • 12. Big SQLite Users • History • Bookmarks • Downloads
  • 14. Where can SQLite be used? • Replacement for a custom file format • Temporary data storage (Unit Tests) - :memory: • Alternative to enterprise DB for demo • Local node storage • Communication between apps • Embedded Devices
  • 15. Versions • SQLite - 2.8.17 • PDO - 3.3.7 + 2.8.17 (3.6.2 in PHP 5.3) • SQLite3 - 3.6.2, minimum is 3.3.9
  • 16. SQLite 3 • 64-bit Rowids • Connections shared between threads • BLOB support • Runtime loadable • Improved concurrency extensions • UTF-16 / UTF-8 • Fulltext searching • User defined collations • ICU support • Named bound • OS Interface parameters
  • 17. SQLite v2 • Smaller subset of SQL supported • Larger file format • Database format incompatible with v3 • No Unicode support • No reading while writing
  • 18. Examples • Firefox 3.0 • Profile directory contains places.sqlite • Schema on the next page • iPhone SMS
  • 20. PDO
  • 23. iPhone SMS Schema /private/var/root/Library/SMS/sms.db ~/Library/Application Support/MobileSync/Backup
  • 24. Custom Functions • Define SQL Functions in PHP • Implement missing features • Aggregation functions
  • 26. Custom Collations • Sorting in alphabetical ☹ ☺ order a a • ICU also provides this i é functionality u i • Use createCollation to é ó define comparison ó u function
  • 29. SQLite3 Extension SQLite3 SQLite3Stmt open paramCount close close exec execute version reset lastInsertRowID clear loadExtension bindValue escapeString bindParam prepare query createFunction createAggregate lastErrorMsg
  • 30. SQLite3 Extension SQLite3Result fetchArray reset finalize columnType columnName numColumns
  • 31. Improving Performance • Pragma • cache_size • fullfsync • synchronous • Shared Cache • Use Transactions
  • 32. Benchmarks • Dual Xeon 3.2GHz, 2GB RAM, Centos 5 • MySQL vs SQLite • Synthetic Benchmark - YMMV Original Image by Ben McLeod
  • 33. Benchmarks - Tests • 15 tests • INSERT • SELECT • UPDATE • DELETE • DROP
  • 34. Benchmarks - Insert MySQL 10.0 SQLite 2 SQLite 3 7.5 SQLite 3 (nosync) 5.0 2.5 0 Test 1 Test 2
  • 35. Benchmarks - Select MySQL 10.0 SQLite 2 SQLite 3 7.5 SQLite 3 (nosync) 5.0 2.5 0 Test 3 Test 4
  • 36. Benchmarks - Indices MySQL 1.2 SQLite 2 SQLite 3 0.9 SQLite 3 (nosync) 0.6 0.3 0 Test 5 Test 6
  • 37. Benchmarks - Update MySQL 5.00 SQLite 2 SQLite 3 3.75 SQLite 3 (nosync) 2.50 1.25 0 Test 7 Test 8 Test 9
  • 38. Benchmarks - Delete MySQL 2.0 SQLite 2 SQLite 3 1.6 SQLite 3 (nosync) 1.2 0.8 0.4 0 Test 11 Test 12 Test 13 Test 14
  • 39. Benchmarks - Summary • SQLite 3 is faster in almost every test • Using MyISAM would show faster results • Doesn’t test concurrency
  • 40. Converting from MySQL • varchar, char -> text • smallint, tinyint, int -> integer • auto_increment -> autoincrement • unknown types converted to text • MySQLi functions have SQLite3 equivalents
  • 41. Unsupported SQL - Examples Original Image by Clive Arundell
  • 42. Limitations • Very large datasets • High concurrency • No Foreign Keys • Nested Transactions • Writing to Views
  • 43. Miscellaneous • Integrity Check • Reclaim Unused Space • Backup
  • 44. Tools - SQLite Manager
  • 45. Resources • http://www.sqlite.org • http://www.php.net/sqlite3 • http://pecl.php.net/sqlite3 • http://talks.macvicar.net • https://addons.mozilla.org/en-US/firefox/ addon/5817