SlideShare a Scribd company logo
1 of 24
DBI
SQL dialects
SQLite
MySQL
PostgreSQL
Oracle
Case insensitive
SQL language is case insensitive
Textual data is case sensitive
SQL reserved words in CAPs
– By convention
– Not mandatory
SQLite
$ sqlite3 address.db
SQL Create
CREATE TABLE address (
id INTEGER PRIMARY KEY,
first_name TEXT,
last_name TEXT,
city TEXT,
state TEXT
);
SQLite
sqlite> .tables
sqlite> .schema address
sqlite> .quit
SQL Insert
INSERT INTO address
(first_name, last_name, city, state)
VALUES ('John', 'Doe', 'Hollywood', 'CA');
SQL Update
UPDATE address
SET city='Hollywood',
state='FL'
WHERE id=1;
SQL Select
SELECT * FROM address;
-- show everything
SELECT *
FROM address
WHERE state='FL';
-- only florida
SELECT first_name, last_name
FROM address
WHERE state='FL';
-- specific fields
SQL Delete
DELETE FROM address;
-- very dangerous
-- deletes everything
DELETE FROM address
WHERE state='FL';
-- use a WHERE condition
DBI
$ cpanm DBD::SQLite
DBI->connect()
#!/usr/bin/perl
use warnings;
use strict;
use DBI;
my $dbh = DBI->connect(
"dbi:SQLite:dbname=address.db", "", ""
);
prepare/execute/fetch
$sth = $dbh->prepare ("
SELECT id, first_name, last_name, city, state
FROM address
WHERE city=?
AND state=?
");
$sth->execute ('Sacramento', 'CA');
# fills in values to the ? placeholders
while (my $row = $sth->fetch()) {
my ($id, $first_name, $last_name, $city, $state) = @$row;
print "$city, $state: $first_name $last_namen";
}
Placeholder
?
Security: The placeholder escapes data
– Counters SQL injection attack
Optimization: Prepare once, execute many. Sometimes faster.
– MySQL: no difference
– Oracle: faster
fetchrow_hashref
while (my $row = $sth->fetchrow_hashref() ) {
print Dumper $row;
}
# $VAR1 = {
# 'city' => 'Sacramento',
# 'id' => 2,
# 'state' => 'CA',
# 'first_name' => 'Jane',
# 'last_name' => 'Doe'
# };
fetchall_arrayref()
# No WHERE condition. Get everything.
$sth = $dbh->prepare ("
SELECT id, first_name, last_name, city, state
FROM address
");
$sth->execute ();
my $rows = $sth->fetchall_arrayref();
foreach my $row (@$rows) {
my ($id, $first_name, $last_name, $city, $state) = @$row;
print "$city, $state: $first_name $last_namen";
}
No fetch
$sth = $dbh->prepare ("
INSERT INTO address (first_name, last_name, city, state)
VALUES (?,?,?,?)
");
$sth->execute('Doug', 'Engelbart', 'Moscow', 'Idaho');
No fetch
$sth = $dbh->prepare ("
UPDATE address SET state=?
WHERE city=?
");
$sth->execute ('TN', 'Moscow');
No fetch
$sth = $dbh->prepare ("
UPDATE address SET first_name=?, last_name=?
WHERE city=? AND state=?
");
$sth->execute ('Edgar', 'Codd', 'TN', 'Moscow');
No fetch
$sth = $dbh->prepare ("
DELETE FROM address
WHERE city=? AND state=?
");
$sth->execute ('Moscow', 'TN');
last_insert_id()
# after your INSERT statement
my $row_id = $dbh->last_insert_id(
undef, undef, undef, undef
);
print "row_id: $row_idn";
Caching the dbh
Opening a database connection incurs overhead.
You want to cache the database handle
– Open once.
– Keep it open.
Example of caching on next slide
state
use feature 'state'; # perl 5.10
sub get_dbh {
state $dbh;
if (!$dbh) {
$dbh = DBI->connect(
"dbi:SQLite:dbname=address.db", "", ""
);
}
return $dbh;
}
DBI

More Related Content

What's hot

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First WidgetChris Wilcoxson
 
AKA BRANDBOOK 2016 NEW small
AKA BRANDBOOK 2016 NEW smallAKA BRANDBOOK 2016 NEW small
AKA BRANDBOOK 2016 NEW smallRob Jones FCCA
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for DeveloperNHN FORWARD
 
How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2Michał Kruczek
 
How to work with legacy code
How to work with legacy codeHow to work with legacy code
How to work with legacy codeMichał Kruczek
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency InjectionRifat Nabi
 
Perspec sys tokenization paper_a4
Perspec sys tokenization paper_a4Perspec sys tokenization paper_a4
Perspec sys tokenization paper_a4Mullrich1012
 
WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPandrewnacin
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようDaisuke Komatsu
 
Tips for using Firebird system tables
Tips for using Firebird system tablesTips for using Firebird system tables
Tips for using Firebird system tablesMind The Firebird
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Colin O'Dell
 
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Hiroshi Shibamura
 

What's hot (20)

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
Php
PhpPhp
Php
 
AKA BRANDBOOK 2016 NEW small
AKA BRANDBOOK 2016 NEW smallAKA BRANDBOOK 2016 NEW small
AKA BRANDBOOK 2016 NEW small
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer[2019] 아직도 돈 주고 DB 쓰나요? for Developer
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
 
How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2How to work with legacy code PHPers Rzeszow #2
How to work with legacy code PHPers Rzeszow #2
 
How to work with legacy code
How to work with legacy codeHow to work with legacy code
How to work with legacy code
 
wget.pl
wget.plwget.pl
wget.pl
 
Facebook
FacebookFacebook
Facebook
 
Sugar introduction
Sugar introductionSugar introduction
Sugar introduction
 
6. hello popescu 2
6. hello popescu 26. hello popescu 2
6. hello popescu 2
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Perspec sys tokenization paper_a4
Perspec sys tokenization paper_a4Perspec sys tokenization paper_a4
Perspec sys tokenization paper_a4
 
WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHP
 
FormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめようFormValidator::LazyWay で検証ルールをまとめよう
FormValidator::LazyWay で検証ルールをまとめよう
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
Tips for using Firebird system tables
Tips for using Firebird system tablesTips for using Firebird system tables
Tips for using Firebird system tables
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016Hacking Your Way To Better Security - Dutch PHP Conference 2016
Hacking Your Way To Better Security - Dutch PHP Conference 2016
 
Practica csv
Practica csvPractica csv
Practica csv
 
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
 

Similar to DBI

Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
Quill + Spark = Better Together
Quill + Spark = Better TogetherQuill + Spark = Better Together
Quill + Spark = Better TogetherAlexander Ioffe
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding HorrorsMark Baker
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfaryan9007
 
Everything About PowerShell
Everything About PowerShellEverything About PowerShell
Everything About PowerShellGaetano Causio
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 

Similar to DBI (20)

Php.docx
Php.docxPhp.docx
Php.docx
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Php functions
Php functionsPhp functions
Php functions
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Presentation1
Presentation1Presentation1
Presentation1
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
DBI
DBIDBI
DBI
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
Quill + Spark = Better Together
Quill + Spark = Better TogetherQuill + Spark = Better Together
Quill + Spark = Better Together
 
Coding Horrors
Coding HorrorsCoding Horrors
Coding Horrors
 
Php My Sql
Php My SqlPhp My Sql
Php My Sql
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdf
 
Everything About PowerShell
Everything About PowerShellEverything About PowerShell
Everything About PowerShell
 
Drupal7 dbtng
Drupal7  dbtngDrupal7  dbtng
Drupal7 dbtng
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 

More from Lambert Lum

Software Testing
Software TestingSoftware Testing
Software TestingLambert Lum
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionLambert Lum
 
Web Crawlers in Perl
Web Crawlers in PerlWeb Crawlers in Perl
Web Crawlers in PerlLambert Lum
 
Moose: Perl Objects
Moose: Perl ObjectsMoose: Perl Objects
Moose: Perl ObjectsLambert Lum
 
Pack/Unpack: manipulate binary data
Pack/Unpack: manipulate binary dataPack/Unpack: manipulate binary data
Pack/Unpack: manipulate binary dataLambert Lum
 

More from Lambert Lum (6)

Database Theory
Database TheoryDatabase Theory
Database Theory
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Web Crawlers in Perl
Web Crawlers in PerlWeb Crawlers in Perl
Web Crawlers in Perl
 
Moose: Perl Objects
Moose: Perl ObjectsMoose: Perl Objects
Moose: Perl Objects
 
Pack/Unpack: manipulate binary data
Pack/Unpack: manipulate binary dataPack/Unpack: manipulate binary data
Pack/Unpack: manipulate binary data
 

Recently uploaded

Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...amitlee9823
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...amitlee9823
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsJoseMangaJr1
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...amitlee9823
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...amitlee9823
 

Recently uploaded (20)

Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 

DBI

  • 1. DBI
  • 3. Case insensitive SQL language is case insensitive Textual data is case sensitive SQL reserved words in CAPs – By convention – Not mandatory
  • 5. SQL Create CREATE TABLE address ( id INTEGER PRIMARY KEY, first_name TEXT, last_name TEXT, city TEXT, state TEXT );
  • 7. SQL Insert INSERT INTO address (first_name, last_name, city, state) VALUES ('John', 'Doe', 'Hollywood', 'CA');
  • 8. SQL Update UPDATE address SET city='Hollywood', state='FL' WHERE id=1;
  • 9. SQL Select SELECT * FROM address; -- show everything SELECT * FROM address WHERE state='FL'; -- only florida SELECT first_name, last_name FROM address WHERE state='FL'; -- specific fields
  • 10. SQL Delete DELETE FROM address; -- very dangerous -- deletes everything DELETE FROM address WHERE state='FL'; -- use a WHERE condition
  • 12. DBI->connect() #!/usr/bin/perl use warnings; use strict; use DBI; my $dbh = DBI->connect( "dbi:SQLite:dbname=address.db", "", "" );
  • 13. prepare/execute/fetch $sth = $dbh->prepare (" SELECT id, first_name, last_name, city, state FROM address WHERE city=? AND state=? "); $sth->execute ('Sacramento', 'CA'); # fills in values to the ? placeholders while (my $row = $sth->fetch()) { my ($id, $first_name, $last_name, $city, $state) = @$row; print "$city, $state: $first_name $last_namen"; }
  • 14. Placeholder ? Security: The placeholder escapes data – Counters SQL injection attack Optimization: Prepare once, execute many. Sometimes faster. – MySQL: no difference – Oracle: faster
  • 15. fetchrow_hashref while (my $row = $sth->fetchrow_hashref() ) { print Dumper $row; } # $VAR1 = { # 'city' => 'Sacramento', # 'id' => 2, # 'state' => 'CA', # 'first_name' => 'Jane', # 'last_name' => 'Doe' # };
  • 16. fetchall_arrayref() # No WHERE condition. Get everything. $sth = $dbh->prepare (" SELECT id, first_name, last_name, city, state FROM address "); $sth->execute (); my $rows = $sth->fetchall_arrayref(); foreach my $row (@$rows) { my ($id, $first_name, $last_name, $city, $state) = @$row; print "$city, $state: $first_name $last_namen"; }
  • 17. No fetch $sth = $dbh->prepare (" INSERT INTO address (first_name, last_name, city, state) VALUES (?,?,?,?) "); $sth->execute('Doug', 'Engelbart', 'Moscow', 'Idaho');
  • 18. No fetch $sth = $dbh->prepare (" UPDATE address SET state=? WHERE city=? "); $sth->execute ('TN', 'Moscow');
  • 19. No fetch $sth = $dbh->prepare (" UPDATE address SET first_name=?, last_name=? WHERE city=? AND state=? "); $sth->execute ('Edgar', 'Codd', 'TN', 'Moscow');
  • 20. No fetch $sth = $dbh->prepare (" DELETE FROM address WHERE city=? AND state=? "); $sth->execute ('Moscow', 'TN');
  • 21. last_insert_id() # after your INSERT statement my $row_id = $dbh->last_insert_id( undef, undef, undef, undef ); print "row_id: $row_idn";
  • 22. Caching the dbh Opening a database connection incurs overhead. You want to cache the database handle – Open once. – Keep it open. Example of caching on next slide
  • 23. state use feature 'state'; # perl 5.10 sub get_dbh { state $dbh; if (!$dbh) { $dbh = DBI->connect( "dbi:SQLite:dbname=address.db", "", "" ); } return $dbh; }