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

Contenu connexe

Tendances

Exported resources design patterns
Exported resources design patternsExported resources design patterns
Exported resources design patternsYevgeny Trachtinov
 
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 FrameworkExove
 
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...Lucidworks
 
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 thereMarco Gralike
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Andy Bunce
 
Database2011 MySQL Sharding
Database2011 MySQL ShardingDatabase2011 MySQL Sharding
Database2011 MySQL ShardingMoshe Kaplan
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2ArangoDB Database
 
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, AirbnbLucidworks
 
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 2016Duyhai Doan
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration managementAlexander Tkachev
 
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 RisksAcquia
 
Hive @ Bucharest Java User Group
Hive @ Bucharest Java User GroupHive @ Bucharest Java User Group
Hive @ Bucharest Java User GroupRemus Rusanu
 
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, LucidworksLucidworks
 

Tendances (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
 

En vedette

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

En vedette (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
 

Similaire à Sqlite virtual-tables written in Perl

Php course-in-navimumbai
Php course-in-navimumbaiPhp course-in-navimumbai
Php course-in-navimumbaivibrantuser
 
Better Data Persistence on Android
Better Data Persistence on AndroidBetter Data Persistence on Android
Better Data Persistence on AndroidEric Maxwell
 
20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnddo_aki
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesDoris Chen
 
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 FIWAREFernando Lopez Aguilar
 
Cosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationCosmos, Big Data GE Implementation
Cosmos, Big Data GE ImplementationFIWARE
 
Cordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITECordova training - Day 9 - SQLITE
Cordova training - Day 9 - SQLITEBinu Paul
 
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...Alex Sadovsky
 
Drupal module development
Drupal module developmentDrupal module development
Drupal module developmentDamjan Cvetan
 
Building .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase LiteBuilding .NET Apps using Couchbase Lite
Building .NET Apps using Couchbase Litegramana
 
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...Databricks
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLitecharsbar
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
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 Symfony2Hugo Hamon
 

Similaire à 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
 

Plus de Laurent Dami

PowerPivot_model_Geneva_Justice_20230531.pptx
PowerPivot_model_Geneva_Justice_20230531.pptxPowerPivot_model_Geneva_Justice_20230531.pptx
PowerPivot_model_Geneva_Justice_20230531.pptxLaurent Dami
 
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 grammarsLaurent Dami
 
Yapceu2015 geneva courts
Yapceu2015 geneva courtsYapceu2015 geneva courts
Yapceu2015 geneva courtsLaurent Dami
 
DBIx::Class vs. DBix::DataModel
DBIx::Class vs. DBix::DataModelDBIx::Class vs. DBix::DataModel
DBIx::Class vs. DBix::DataModelLaurent Dami
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail Laurent Dami
 
Gestion documentaire pour les tribunaux genevois
Gestion documentaire pour les tribunaux genevoisGestion documentaire pour les tribunaux genevois
Gestion documentaire pour les tribunaux genevoisLaurent Dami
 
Working with databases in Perl
Working with databases in PerlWorking with databases in Perl
Working with databases in PerlLaurent Dami
 
Emacs, a performant IDE for Perl
Emacs, a performant IDE for PerlEmacs, a performant IDE for Perl
Emacs, a performant IDE for PerlLaurent Dami
 
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 PerlLaurent Dami
 

Plus de 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
 

Dernier

Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 

Dernier (20)

Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 

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