SlideShare ist ein Scribd-Unternehmen logo
1 von 13
05.09.2014 - Page 1 
Département 
Office 
Sqlite Virtual Tables 
written in Perl 
Swiss Perl Workshop 2014 
laurent.dami@justice.ge.ch 
Etat de Genève, Pouvoir Judiciaire 
Département 
Office
What is SQLite 
• Relational Database Engine in a C software library 
–  SQL support, including foreign keys constraints, transactions, etc. 
– Also fulltext support 
– Self-contained 
• File-based 
–  No server, no sockets, zero configuration 
• Extensible 
–  can add user-defined functions, aggregate functions, etc. 
Great for tests 
Great for embedded devices 
 "the most widely deployed database engine in the world" 
(smartphones, Firefox, etc.) http://www.sqlite.org
SQLite and Perl 
• DBD::SQLite driver 
– Contains the whole SQLite source (no external dependency) 
– Regularly updated 
• Usage : 
use DBI; 
my $dsn = "dbi:SQLite:dbname=$dbfile"; 
my $dbh = DBI->connect($dsn,"","", %options);
Tied variables in Perl 
my %regular_hash 
Perl Core 
implementation 
tie my %foo_hash, 'Tie::Hash::Foo'; 
Tie::Hash::Foo 
+TIEHASH 
+FETCH 
+STORE 
...
Virtual tables in SQLite 
CREATE TABLE Foo(...) 
SQLite core 
implementation 
CREATE VIRTUAL TABLE Bar 
USING foobar (....) 
Foobar.c 
+xOpen 
+xNext 
+xEof 
+xColumn 
... 
C code 
Virtual tables in DBD::Sqlite '1.43_08' 
# register the virtual table module within sqlite 
$dbh->sqlite_create_module(mod_name => 
"DBD::SQLite::VirtualTable::Subclass"); 
# create a virtual table 
$dbh->do("CREATE VIRTUAL TABLE vtbl " 
"USING mod_name(arg1, arg2, ...)") 
Will be passed to 
the CREATE() 
method 
# use it as any regular table 
my $sth = $dbh->prepare("SELECT * FROM vtbl ...");
Implementing a virtual table 
DBD::SQLite::VirtualTable DBD::SQLite::VirtualTable::Cursor 
MyVTab MyVTab::Cursor 
+CREATE 
+BEST_INDEX 
... 
+FILTER 
+NEXT 
+EOF 
+COLUMN 
...
Builtin 1: VirtualTable::FileContent 
CREATE VIRTUAL TABLE tbl USING fcontent( 
source = src_table, 
content_col = content, 
path_col = path, 
expose = "path, col1, col2, col3", --or "*" 
root = "/foo/bar", 
get_content = Foo::Bar::read_from_file 
); 
SELECT col1, path, content FROM tbl WHERE ...; 
CREATE VIRTUAL TABLE fts USING fts4( 
content="tbl", tokenize=unicode61);
FileContent + FTS4 
Virtual (FTS4, C code) Virtual (FileContent, Perl) 
C1 Content 
C1 C2 Path 
get_content() 
C1 Content 
Regular table 
FTS4 internals 
Filesystem
Builtin 2: VirtualTable::PerlData 
CREATE VIRTUAL TABLE atbl USING perl( 
foo, bar, etc, 
arrayrefs="some::global::var::aref") 
CREATE VIRTUAL TABLE htbl USING perl( 
foo, bar, etc, 
hashrefs="some::global::var::href") 
CREATE VIRTUAL TABLE ctbl USING perl( 
single_col, 
colref="some::global::var::ref")
Hashrefs example 
use Unicode::UCD 'charinfo'; 
our $chars = [map {charinfo($_)} 0x300..0x400]; 
CREATE VIRTUAL TABLE charinfo USING perl( 
code, name, block, script, category, 
hashrefs="main::chars"); 
SELECT * FROM charinfo 
WHERE script='Greek' 
AND name LIKE '%SIGMA%'
Colref example 
# perl 
our $values = @ARGV; 
# SQL 
CREATE VIRTUAL TABLE iarray USING perl(i INT, 
colref="main::values"); 
SELECT * FROM some_table WHERE some_col IN iarray; 
# BEWARE! 
INSERT INTO iarray VALUES (99); # pushes in @ARGV
Go and try 
• https://metacpan.org/source/ISHIGAKI/DBD-SQLite- 
1.43_08 
• https://github.com/DBD-SQLite/DBD-SQLite

Weitere ähnliche Inhalte

Was ist angesagt?

Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
ArangoDB Database
 

Was ist angesagt? (20)

Exported resources design patterns
Exported resources design patternsExported resources design patterns
Exported resources design patterns
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a Framework
 
Rebuilding Solr 6 Examples - Layer by Layer: Presented by Alexandre Rafalovit...
Rebuilding Solr 6 Examples - Layer by Layer: Presented by Alexandre Rafalovit...Rebuilding Solr 6 Examples - Layer by Layer: Presented by Alexandre Rafalovit...
Rebuilding Solr 6 Examples - Layer by Layer: Presented by Alexandre Rafalovit...
 
XFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in thereXFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in there
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application
 
Database2011 MySQL Sharding
Database2011 MySQL ShardingDatabase2011 MySQL Sharding
Database2011 MySQL Sharding
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
 
Airbnb Search Architecture: Presented by Maxim Charkov, Airbnb
Airbnb Search Architecture: Presented by Maxim Charkov, AirbnbAirbnb Search Architecture: Presented by Maxim Charkov, Airbnb
Airbnb Search Architecture: Presented by Maxim Charkov, Airbnb
 
lab56_db
lab56_dblab56_db
lab56_db
 
D7dev
D7devD7dev
D7dev
 
XQuery in the Cloud
XQuery in the CloudXQuery in the Cloud
XQuery in the Cloud
 
Cassandra 3 new features @ Geecon Krakow 2016
Cassandra 3 new features  @ Geecon Krakow 2016Cassandra 3 new features  @ Geecon Krakow 2016
Cassandra 3 new features @ Geecon Krakow 2016
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration management
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksMigrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
 
Hive @ Bucharest Java User Group
Hive @ Bucharest Java User GroupHive @ Bucharest Java User Group
Hive @ Bucharest Java User Group
 
Visualize Solr Data with Banana: Presented by Andrew Thanalertvisuti, Lucidworks
Visualize Solr Data with Banana: Presented by Andrew Thanalertvisuti, LucidworksVisualize Solr Data with Banana: Presented by Andrew Thanalertvisuti, Lucidworks
Visualize Solr Data with Banana: Presented by Andrew Thanalertvisuti, Lucidworks
 

Andere mochten auch (6)

perl language update
perl language updateperl language update
perl language update
 
2013年のCPANモジュール作成事情
2013年のCPANモジュール作成事情2013年のCPANモジュール作成事情
2013年のCPANモジュール作成事情
 
JSON, JSON::PP, and more
JSON, JSON::PP, and moreJSON, JSON::PP, and more
JSON, JSON::PP, and more
 
10年モノ熟成Perlとの付き合い方
10年モノ熟成Perlとの付き合い方10年モノ熟成Perlとの付き合い方
10年モノ熟成Perlとの付き合い方
 
2016年のPerl (Long version)
2016年のPerl (Long version)2016年のPerl (Long version)
2016年のPerl (Long version)
 
Infrastructure of Pathtraq
Infrastructure of PathtraqInfrastructure of Pathtraq
Infrastructure of Pathtraq
 

Ähnlich wie Sqlite virtual-tables written in Perl

android sqlite
android sqliteandroid sqlite
android sqlite
Deepa Rani
 
Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE Implementation
FIWARE
 

Ähnlich wie Sqlite virtual-tables written in Perl (20)

Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbai
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
Better Data Persistence on Android
Better Data Persistence on AndroidBetter Data Persistence on Android
Better Data Persistence on Android
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Advance Mobile Application Development class 01
Advance Mobile Application Development class 01Advance Mobile Application Development class 01
Advance Mobile Application Development class 01
 
Swift core
Swift coreSwift core
Swift core
 
20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnd
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
Cosmos, Big Data GE implementation in FIWARE
Cosmos, Big Data GE implementation in FIWARECosmos, Big Data GE implementation in FIWARE
Cosmos, Big Data GE implementation in FIWARE
 
Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE Implementation
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Cordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITECordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITE
 
More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module development
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Lite
 
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...
Spark Summit EU 2015: Spark DataFrames: Simple and Fast Analysis of Structure...
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLite
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 

Mehr von Laurent Dami

DBIx::Class vs. DBix::DataModel
DBIx::Class vs. DBix::DataModelDBIx::Class vs. DBix::DataModel
DBIx::Class vs. DBix::DataModel
Laurent Dami
 

Mehr von Laurent Dami (9)

PowerPivot_model_Geneva_Justice_20230531.pptx
PowerPivot_model_Geneva_Justice_20230531.pptxPowerPivot_model_Geneva_Justice_20230531.pptx
PowerPivot_model_Geneva_Justice_20230531.pptx
 
Studying geneva real estate prices using perl grammars
Studying geneva real estate prices using perl grammarsStudying geneva real estate prices using perl grammars
Studying geneva real estate prices using perl grammars
 
Yapceu2015 geneva courts
Yapceu2015 geneva courtsYapceu2015 geneva courts
Yapceu2015 geneva courts
 
DBIx::Class vs. DBix::DataModel
DBIx::Class vs. DBix::DataModelDBIx::Class vs. DBix::DataModel
DBIx::Class vs. DBix::DataModel
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail
 
Gestion documentaire pour les tribunaux genevois
Gestion documentaire pour les tribunaux genevoisGestion documentaire pour les tribunaux genevois
Gestion documentaire pour les tribunaux genevois
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in Perl
 
Emacs, a performant IDE for Perl
Emacs, a performant IDE for PerlEmacs, a performant IDE for Perl
Emacs, a performant IDE for Perl
 
Managing Geneva's law courts, from Cobol to Perl
Managing Geneva's law courts, from Cobol to PerlManaging Geneva's law courts, from Cobol to Perl
Managing Geneva's law courts, from Cobol to Perl
 

Kürzlich hochgeladen

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Kürzlich hochgeladen (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Sqlite virtual-tables written in Perl

  • 1. 05.09.2014 - Page 1 Département Office Sqlite Virtual Tables written in Perl Swiss Perl Workshop 2014 laurent.dami@justice.ge.ch Etat de Genève, Pouvoir Judiciaire Département Office
  • 2. What is SQLite • Relational Database Engine in a C software library –  SQL support, including foreign keys constraints, transactions, etc. – Also fulltext support – Self-contained • File-based –  No server, no sockets, zero configuration • Extensible –  can add user-defined functions, aggregate functions, etc. Great for tests Great for embedded devices  "the most widely deployed database engine in the world" (smartphones, Firefox, etc.) http://www.sqlite.org
  • 3. SQLite and Perl • DBD::SQLite driver – Contains the whole SQLite source (no external dependency) – Regularly updated • Usage : use DBI; my $dsn = "dbi:SQLite:dbname=$dbfile"; my $dbh = DBI->connect($dsn,"","", %options);
  • 4. Tied variables in Perl my %regular_hash Perl Core implementation tie my %foo_hash, 'Tie::Hash::Foo'; Tie::Hash::Foo +TIEHASH +FETCH +STORE ...
  • 5. Virtual tables in SQLite CREATE TABLE Foo(...) SQLite core implementation CREATE VIRTUAL TABLE Bar USING foobar (....) Foobar.c +xOpen +xNext +xEof +xColumn ... C code 
  • 6. Virtual tables in DBD::Sqlite '1.43_08' # register the virtual table module within sqlite $dbh->sqlite_create_module(mod_name => "DBD::SQLite::VirtualTable::Subclass"); # create a virtual table $dbh->do("CREATE VIRTUAL TABLE vtbl " "USING mod_name(arg1, arg2, ...)") Will be passed to the CREATE() method # use it as any regular table my $sth = $dbh->prepare("SELECT * FROM vtbl ...");
  • 7. Implementing a virtual table DBD::SQLite::VirtualTable DBD::SQLite::VirtualTable::Cursor MyVTab MyVTab::Cursor +CREATE +BEST_INDEX ... +FILTER +NEXT +EOF +COLUMN ...
  • 8. Builtin 1: VirtualTable::FileContent CREATE VIRTUAL TABLE tbl USING fcontent( source = src_table, content_col = content, path_col = path, expose = "path, col1, col2, col3", --or "*" root = "/foo/bar", get_content = Foo::Bar::read_from_file ); SELECT col1, path, content FROM tbl WHERE ...; CREATE VIRTUAL TABLE fts USING fts4( content="tbl", tokenize=unicode61);
  • 9. FileContent + FTS4 Virtual (FTS4, C code) Virtual (FileContent, Perl) C1 Content C1 C2 Path get_content() C1 Content Regular table FTS4 internals Filesystem
  • 10. Builtin 2: VirtualTable::PerlData CREATE VIRTUAL TABLE atbl USING perl( foo, bar, etc, arrayrefs="some::global::var::aref") CREATE VIRTUAL TABLE htbl USING perl( foo, bar, etc, hashrefs="some::global::var::href") CREATE VIRTUAL TABLE ctbl USING perl( single_col, colref="some::global::var::ref")
  • 11. Hashrefs example use Unicode::UCD 'charinfo'; our $chars = [map {charinfo($_)} 0x300..0x400]; CREATE VIRTUAL TABLE charinfo USING perl( code, name, block, script, category, hashrefs="main::chars"); SELECT * FROM charinfo WHERE script='Greek' AND name LIKE '%SIGMA%'
  • 12. Colref example # perl our $values = @ARGV; # SQL CREATE VIRTUAL TABLE iarray USING perl(i INT, colref="main::values"); SELECT * FROM some_table WHERE some_col IN iarray; # BEWARE! INSERT INTO iarray VALUES (99); # pushes in @ARGV
  • 13. Go and try • https://metacpan.org/source/ISHIGAKI/DBD-SQLite- 1.43_08 • https://github.com/DBD-SQLite/DBD-SQLite