SlideShare une entreprise Scribd logo
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

Tendances (20)

Using Queryable State for Fun and Profit
Using Queryable State for Fun and ProfitUsing Queryable State for Fun and Profit
Using Queryable State for Fun and Profit
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud
 
Graph Computing with JanusGraph
Graph Computing with JanusGraphGraph Computing with JanusGraph
Graph Computing with JanusGraph
 
Oracle SQL Developer for SQL Server?
Oracle SQL Developer for SQL Server?Oracle SQL Developer for SQL Server?
Oracle SQL Developer for SQL Server?
 
(BDT318) How Netflix Handles Up To 8 Million Events Per Second
(BDT318) How Netflix Handles Up To 8 Million Events Per Second(BDT318) How Netflix Handles Up To 8 Million Events Per Second
(BDT318) How Netflix Handles Up To 8 Million Events Per Second
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
PySpark dataframe
PySpark dataframePySpark dataframe
PySpark dataframe
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
 
Migrating ETL Workflow to Apache Spark at Scale in Pinterest
Migrating ETL Workflow to Apache Spark at Scale in PinterestMigrating ETL Workflow to Apache Spark at Scale in Pinterest
Migrating ETL Workflow to Apache Spark at Scale in Pinterest
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
 
ACID ORC, Iceberg, and Delta Lake—An Overview of Table Formats for Large Scal...
ACID ORC, Iceberg, and Delta Lake—An Overview of Table Formats for Large Scal...ACID ORC, Iceberg, and Delta Lake—An Overview of Table Formats for Large Scal...
ACID ORC, Iceberg, and Delta Lake—An Overview of Table Formats for Large Scal...
 
Getting Started with SQLite
Getting Started with SQLiteGetting Started with SQLite
Getting Started with SQLite
 
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
 
Sq lite presentation
Sq lite presentationSq lite presentation
Sq lite presentation
 
YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions YugaByte DB Internals - Storage Engine and Transactions
YugaByte DB Internals - Storage Engine and Transactions
 
A look under the hood at Apache Spark's API and engine evolutions
A look under the hood at Apache Spark's API and engine evolutionsA look under the hood at Apache Spark's API and engine evolutions
A look under the hood at Apache Spark's API and engine evolutions
 
ELK Elasticsearch Logstash and Kibana Stack for Log Management
ELK Elasticsearch Logstash and Kibana Stack for Log ManagementELK Elasticsearch Logstash and Kibana Stack for Log Management
ELK Elasticsearch Logstash and Kibana Stack for Log Management
 

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: 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
 
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
 
HDMI
HDMIHDMI
HDMI
 
SQLite
SQLiteSQLite
SQLite
 

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

Dernier (20)

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfBuy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 

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