SlideShare a Scribd company logo
1 of 58
Perl DBI Scripting with the ILS Roy Zimmer Western Michigan University
What do I need for database interactions with Perl?
What do I need for database interactions with Perl? DBI – DataBase Interface (always)
What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database  you must access)
What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database  you must access) a database? (some DBDs let you access non-database  data, such as CSV files)
What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database  you must access) a database? (some DBDs let you access non-database  data, such as CSV files) some Perl proficiency
What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database  you must access) a database? (some DBDs let you access non-database  data, such as CSV files) some Perl proficiency But we only care about using our Voyager  database, so we’ll stick with that.
What does this mean to you?
What does this mean to you? DBI – DataBase Interface (already on your Voyager  box)
What does this mean to you? DBI – DataBase Interface (already on your Voyager  box) DBD – DataBase Driver (for  , already on  your Voyager box)
What does this mean to you? DBI – DataBase Interface (already on your Voyager  box) DBD – DataBase Driver (for  , already on  your Voyager box) a database? (already on your Voyager box)
What does this mean to you? DBI – DataBase Interface (already on your Voyager  box) DBD – DataBase Driver (for  , already on  your Voyager box) a database? (already on your Voyager box) some Perl proficiency ( the only thing you supply! )
A simple program Always needed for database access nameletters.pl
A simple program Get access information from a setup file and connect to a database. File format (the only record): library.box.university.edu / username / password / VGER nameletters.pl
A simple program Connect to the database and get a handle. nameletters.pl
A simple program… for each letter, how many patrons’ last names start with that letter Create the query sprintf  is your  friend A sample query here is: select count (*)   from wmichdb.patron    where last_name like ‘S%’ nameletters.pl
A simple program… for each letter, how many patrons’ last names start with that letter Prepare the query, associating it with a database, giving it a handle. nameletters.pl
A simple program… for each letter, how many patrons’ last names start with that letter Run the query, get a return code. nameletters.pl
A simple program… for each letter, how many patrons’ last names start with that letter Get the query result… nameletters.pl
A simple program… for each letter, how many patrons’ last names start with that letter …and print it. nameletters.pl
A simple program… for each letter, how many patrons’ last names start with that letter A: 003016 B: 007113 C: 005041 D: 003792 E: 001322 F: 002605 G: 003603 H: 005388 I: 000368 J: 001970 K: 004371 L: 003763 M: 007039 N: 001622 O: 001299 P: 003792 Q: 000121 R: 003770 S: 008217 T: 002528 U: 000248 V: 001791 W: 004487 X: 000018 Y: 000562 Z: 000709 Output nameletters.pl
Nested query example… getting   barcodes of retirees who’ve borrowed something within the past year retirees.pl
Nested query example… getting   barcodes of retirees who’ve borrowed something within the past year Outer query Get patron information that meets the criteria, and connecting information for barcodes. (sprintf actually not needed here) retirees.pl
Nested query example… getting   barcodes of retirees who’ve borrowed something within the past year Inner query Remember the outer query? Note the positional correspondence of the query parameters with the while statement receiving a query row. retirees.pl
Nested query example… getting   barcodes of retirees who’ve borrowed something within the past year Inner query The inner query has a different query string name… retirees.pl
Nested query example… getting   barcodes of retirees who’ve borrowed something within the past year Inner query …as do the other variables for this query. retirees.pl
Nested query example… getting   barcodes of retirees who’ve borrowed something within the past year Inner query Doe, John R  doe1  pgroup: EMERIT/RET 21141002502810 08/16/1999 Other  99952803601000 11/25/2001 Expired  Doe, Josephine  doe2  pgroup: RETIREDSTF 21141001297289 08/16/1999 Other  21141002300660 08/16/1999 Other  11130755000000 09/04/2002 Expired   retirees.pl Sample output:
Termination Notes $sth->finish finish a query $dbh->disconnect disconnect from a database finish  seems like a good practice, but it’s not really needed. Yet… disconnect  isn’t really needed (for our purposes, read-only). However, without using the  finish  statement, you could run into error situations. leading us to…
CPAN  the Comprehensive Perl Archive Network Great resource for *all* kinds of Perl modules Documentation  for modules - comprehensively so for DBI and DBD - about 100 pages for DBI and 50 pages for DBD
A bit more documentation… $sth->fetchrow_array returns a single value, array, or list There are a number of other ways to get query data, but this seems to work best. You can also get lots of details about your database environment via DBI calls. See the DBI documentation for more information.
A quick little DBI utility dbddrivers.pl
A quick little DBI utility Available Perl DBD drivers on this system DBM ExampleP File Gofer Oracle Proxy Sponge Output dbddrivers.pl
What if you need to look at every bib record you’ve got?
What if you need to look at every bib record you’ve got? And you need to access the marc record (synonymous with  )? Here’s one approach… THE   BLOB
connect to the database query bib_data table to get the maximum bib ID set increment to 50,000 set ending bib ID to increment set beginning bib ID to 0 Traversing every record and dealing with THE BLOB along the way
connect to the database query bib_data table to get the maximum bib ID set increment to 50,000 set ending bib ID to increment set beginning bib ID to 0 while beginning bid ID < maximum bib ID chunkthroughdb() provide feedback of progress beginning bib ID = ending bib ID + 1 add increment to ending bib ID end provide final feedback Traversing every record and dealing with THE BLOB along the way
sub chunkthrudb query bib_data for blob data  based on bib IDs >= beginning bib ID and   bib IDs < ending bib ID for each record from the query assemble each bib ID's data into a marc record  do the required processing for this record end end Traversing every record and dealing with THE BLOB along the way
Traversing every record and dealing with THE BLOB along the way Discussion of this approach Alternative method: read the whole database at once! - might be impossible - might not be feasible - probably not efficient The program presented here…seems to be the better method.
Traversing every record and dealing with THE BLOB along the way Discussion of this approach If nothing else, “chunking” your way through your database is more efficient We have close to 1.6 million bib records. Based on the program we’re about to see, traversing our database… using 50,000 record chunks takes about 50 minutes without “chunking” it takes about 76 minutes
Traversing every record and dealing with THE BLOB along the way findbadleader.pl
Traversing every record and dealing with THE BLOB along the way Get our boundary condition findbadleader.pl
Traversing every record and dealing with THE BLOB along the way 0-50,000 – our first chunk of records findbadleader.pl
Traversing every record and dealing with THE BLOB along the way the loop findbadleader.pl
Traversing every record and dealing with THE BLOB along the way set up the next chunk the loop findbadleader.pl
Traversing every record and dealing with THE BLOB along the way - chunking subroutine (chunkthrudb) “ seqnum desc” is key to getting the blob data for each record This gets one chunk’s worth of MARC records (blob data) findbadleader.pl
Traversing every record and dealing with THE BLOB along the way - chunking subroutine (chunkthrudb ) Creates the MARC record for each bib retrieved. For larger records that don’t fit in one table row, assemble the record in reverse order (from the query). findbadleader.pl
Traversing every record and dealing with THE BLOB along the way - chunking subroutine (chunkthrudb ) Process each record. In this case, we’re looking for records with bad leaders (not ending in “4500”). Sample output: findbadleader.pl
Being in a  is a good thing… bind sprintf is a friend, but  bind  is a better friend
Being in a  is a good thing… bind sprintf is a friend, but  bind  is a better friend usual query method
Being in a  is a good thing… bind sprintf is a friend, but  bind  is a better friend usual query method query with bind values method
testbind.pl Illustrating and contrasting the query with bind method create, prepare, and execute a query
testbind.pl Illustrating and contrasting the query with bind method prepare and execute a query
testbind.pl Illustrating and contrasting the query with bind method prepare and execute a query, improved prepare moved outside of the loop
testbind.pl Illustrating and contrasting the query with bind method Using testbind.pl for about 80,000 patron records, these are the results: 10 Prepare and execute a query, improved (with bind) 11 Prepare and execute a query (with bind) 20 Create, prepare and execute a query Runtime (seconds) Method
Running reports, queries via Perl on your PC ActiveState sells products and also has free versions. I recommend their free Perl. Get the MSI version. It comes with DBI and DBD for Oracle, among  many  other modules (and lots of documentation). Still (!) requires external Oracle client software (at least as of version 5.10.0, build 1003)
The files listed below are available at http://homepages.wmich.edu/~zimmer/files/eugm2008 dbi.ppt this presentation nameletters.pl for every letter, find number of patrons whose last names begin with that letter retirees.pl get barcodes of retirees who’ve borrowed something in the last year dbddrivers.pl get list of DBD drivers on your system findbadleader.pl find bib records with bad leaders (not ending in 4500) testbind.pl demonstrates varying query method efficiencies Resources
CPAN http://cpan.org DBI  http://search.cpan.org/~timb/DBI-1.605/DBI.pm DBD Oracle http://search.cpan.org/~pythian/DBD-Oracle-1.21/Oracle.pm Active State Perl http://activestate.com/downloads/index.mhtml There is also a book on Perl and DBI. I’d recommend using it along with the most current documentation  from the CPAN sites above. Resources
Thank you for listening. Questions? [email_address] Picture © 2008 by Roy Zimmer

More Related Content

What's hot

What is Python JSON | Edureka
What is Python JSON | EdurekaWhat is Python JSON | Edureka
What is Python JSON | EdurekaEdureka!
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Spaceramanjosan
 
Text Mining with R -- an Analysis of Twitter Data
Text Mining with R -- an Analysis of Twitter DataText Mining with R -- an Analysis of Twitter Data
Text Mining with R -- an Analysis of Twitter DataYanchang Zhao
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsingFelix Z. Hoffmann
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
Crafting tailored wordlists with Wordsmith
Crafting tailored wordlists with WordsmithCrafting tailored wordlists with Wordsmith
Crafting tailored wordlists with WordsmithSanjiv Kawa
 
Linking the Open Data? by Petko Valtchev
Linking the Open Data? by Petko ValtchevLinking the Open Data? by Petko Valtchev
Linking the Open Data? by Petko ValtchevTrudat
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output ConceptsVicter Paul
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Data file handling in python reading & writing methods
Data file handling in python reading & writing methodsData file handling in python reading & writing methods
Data file handling in python reading & writing methodskeeeerty
 

What's hot (15)

Files and streams
Files and streamsFiles and streams
Files and streams
 
What is Python JSON | Edureka
What is Python JSON | EdurekaWhat is Python JSON | Edureka
What is Python JSON | Edureka
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Space
 
Text Mining with R -- an Analysis of Twitter Data
Text Mining with R -- an Analysis of Twitter DataText Mining with R -- an Analysis of Twitter Data
Text Mining with R -- an Analysis of Twitter Data
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Python-files
Python-filesPython-files
Python-files
 
Crafting tailored wordlists with Wordsmith
Crafting tailored wordlists with WordsmithCrafting tailored wordlists with Wordsmith
Crafting tailored wordlists with Wordsmith
 
Linking the Open Data? by Petko Valtchev
Linking the Open Data? by Petko ValtchevLinking the Open Data? by Petko Valtchev
Linking the Open Data? by Petko Valtchev
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
1
11
1
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Data file handling in python reading & writing methods
Data file handling in python reading & writing methodsData file handling in python reading & writing methods
Data file handling in python reading & writing methods
 

Similar to Perl DBI Scripting with the ILS

Querying data on the Web – client or server?
Querying data on the Web – client or server?Querying data on the Web – client or server?
Querying data on the Web – client or server?Ruben Verborgh
 
Prophet - Beijing Perl Workshop
Prophet - Beijing Perl WorkshopProphet - Beijing Perl Workshop
Prophet - Beijing Perl WorkshopJesse Vincent
 
Practical Hadoop using Pig
Practical Hadoop using PigPractical Hadoop using Pig
Practical Hadoop using PigDavid Wellman
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++Mike Acton
 
The Lonesome LOD Cloud
The Lonesome LOD CloudThe Lonesome LOD Cloud
The Lonesome LOD CloudRuben Verborgh
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
The Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitThe Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitStephen Scaffidi
 
Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016Chris Fregly
 
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016MLconf
 
Querying federations 
of Triple Pattern Fragments
Querying federations 
of Triple Pattern FragmentsQuerying federations 
of Triple Pattern Fragments
Querying federations 
of Triple Pattern FragmentsRuben Verborgh
 
Sustainable queryable access to Linked Data
Sustainable queryable access to Linked DataSustainable queryable access to Linked Data
Sustainable queryable access to Linked DataRuben Verborgh
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?lichtkind
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainKen Collins
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupBrian Cardiff
 
Code as Data workshop: Using source{d} Engine to extract insights from git re...
Code as Data workshop: Using source{d} Engine to extract insights from git re...Code as Data workshop: Using source{d} Engine to extract insights from git re...
Code as Data workshop: Using source{d} Engine to extract insights from git re...source{d}
 
Docopt, beautiful command-line options for R, user2014
Docopt, beautiful command-line options for R,  user2014Docopt, beautiful command-line options for R,  user2014
Docopt, beautiful command-line options for R, user2014Edwin de Jonge
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185Mahmoud Samir Fayed
 

Similar to Perl DBI Scripting with the ILS (20)

Querying data on the Web – client or server?
Querying data on the Web – client or server?Querying data on the Web – client or server?
Querying data on the Web – client or server?
 
Prophet - Beijing Perl Workshop
Prophet - Beijing Perl WorkshopProphet - Beijing Perl Workshop
Prophet - Beijing Perl Workshop
 
Practical Hadoop using Pig
Practical Hadoop using PigPractical Hadoop using Pig
Practical Hadoop using Pig
 
Linked Data Fragments
Linked Data FragmentsLinked Data Fragments
Linked Data Fragments
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 
The Lonesome LOD Cloud
The Lonesome LOD CloudThe Lonesome LOD Cloud
The Lonesome LOD Cloud
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
The Essential Perl Hacker's Toolkit
The Essential Perl Hacker's ToolkitThe Essential Perl Hacker's Toolkit
The Essential Perl Hacker's Toolkit
 
Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016Atlanta MLconf Machine Learning Conference 09-23-2016
Atlanta MLconf Machine Learning Conference 09-23-2016
 
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
Chris Fregly, Research Scientist, PipelineIO at MLconf ATL 2016
 
Access
AccessAccess
Access
 
Querying federations 
of Triple Pattern Fragments
Querying federations 
of Triple Pattern FragmentsQuerying federations 
of Triple Pattern Fragments
Querying federations 
of Triple Pattern Fragments
 
Sustainable queryable access to Linked Data
Sustainable queryable access to Linked DataSustainable queryable access to Linked Data
Sustainable queryable access to Linked Data
 
What we can learn from Rebol?
What we can learn from Rebol?What we can learn from Rebol?
What we can learn from Rebol?
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
Streams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetupStreams of information - Chicago crystal language monthly meetup
Streams of information - Chicago crystal language monthly meetup
 
Neo4j
Neo4jNeo4j
Neo4j
 
Code as Data workshop: Using source{d} Engine to extract insights from git re...
Code as Data workshop: Using source{d} Engine to extract insights from git re...Code as Data workshop: Using source{d} Engine to extract insights from git re...
Code as Data workshop: Using source{d} Engine to extract insights from git re...
 
Docopt, beautiful command-line options for R, user2014
Docopt, beautiful command-line options for R,  user2014Docopt, beautiful command-line options for R,  user2014
Docopt, beautiful command-line options for R, user2014
 
The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185The Ring programming language version 1.5.4 book - Part 180 of 185
The Ring programming language version 1.5.4 book - Part 180 of 185
 

More from Roy Zimmer

Automating a Vendor File Load Process with Perl and Shell Scripting
Automating a Vendor File Load Process with Perl and Shell ScriptingAutomating a Vendor File Load Process with Perl and Shell Scripting
Automating a Vendor File Load Process with Perl and Shell ScriptingRoy Zimmer
 
Orientation Session for (New) Presenters and Moderators
Orientation Session for (New) Presenters and ModeratorsOrientation Session for (New) Presenters and Moderators
Orientation Session for (New) Presenters and ModeratorsRoy Zimmer
 
Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...
Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...
Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...Roy Zimmer
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsRoy Zimmer
 
Voyager Meets MeLCat: MC'ing the Introductions
Voyager Meets MeLCat: MC'ing the IntroductionsVoyager Meets MeLCat: MC'ing the Introductions
Voyager Meets MeLCat: MC'ing the IntroductionsRoy Zimmer
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Roy Zimmer
 
Marcive Documents: Catching Up and Keeping Up
Marcive Documents: Catching Up and Keeping UpMarcive Documents: Catching Up and Keeping Up
Marcive Documents: Catching Up and Keeping UpRoy Zimmer
 
Implementing a Backup Catalog… on a Student Budget
Implementing a Backup Catalog… on a Student BudgetImplementing a Backup Catalog… on a Student Budget
Implementing a Backup Catalog… on a Student BudgetRoy Zimmer
 
A Strand of Perls: Some Home Grown Utilities
A Strand of Perls: Some Home Grown UtilitiesA Strand of Perls: Some Home Grown Utilities
A Strand of Perls: Some Home Grown UtilitiesRoy Zimmer
 
Another Way to Attack the BLOB: Server-side Access via PL/SQL and Perl
Another Way to Attack the BLOB: Server-side Access via PL/SQL and PerlAnother Way to Attack the BLOB: Server-side Access via PL/SQL and Perl
Another Way to Attack the BLOB: Server-side Access via PL/SQL and PerlRoy Zimmer
 

More from Roy Zimmer (11)

Automating a Vendor File Load Process with Perl and Shell Scripting
Automating a Vendor File Load Process with Perl and Shell ScriptingAutomating a Vendor File Load Process with Perl and Shell Scripting
Automating a Vendor File Load Process with Perl and Shell Scripting
 
Orientation Session for (New) Presenters and Moderators
Orientation Session for (New) Presenters and ModeratorsOrientation Session for (New) Presenters and Moderators
Orientation Session for (New) Presenters and Moderators
 
Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...
Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...
Taking Your Customers to the Cleaners: Historical Patron Data Cleanup and Rou...
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
Voyager Meets MeLCat: MC'ing the Introductions
Voyager Meets MeLCat: MC'ing the IntroductionsVoyager Meets MeLCat: MC'ing the Introductions
Voyager Meets MeLCat: MC'ing the Introductions
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)
 
Marcive Documents: Catching Up and Keeping Up
Marcive Documents: Catching Up and Keeping UpMarcive Documents: Catching Up and Keeping Up
Marcive Documents: Catching Up and Keeping Up
 
Implementing a Backup Catalog… on a Student Budget
Implementing a Backup Catalog… on a Student BudgetImplementing a Backup Catalog… on a Student Budget
Implementing a Backup Catalog… on a Student Budget
 
A Strand of Perls: Some Home Grown Utilities
A Strand of Perls: Some Home Grown UtilitiesA Strand of Perls: Some Home Grown Utilities
A Strand of Perls: Some Home Grown Utilities
 
Another Way to Attack the BLOB: Server-side Access via PL/SQL and Perl
Another Way to Attack the BLOB: Server-side Access via PL/SQL and PerlAnother Way to Attack the BLOB: Server-side Access via PL/SQL and Perl
Another Way to Attack the BLOB: Server-side Access via PL/SQL and Perl
 
Batchhow
BatchhowBatchhow
Batchhow
 

Recently uploaded

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Perl DBI Scripting with the ILS

  • 1. Perl DBI Scripting with the ILS Roy Zimmer Western Michigan University
  • 2. What do I need for database interactions with Perl?
  • 3. What do I need for database interactions with Perl? DBI – DataBase Interface (always)
  • 4. What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database you must access)
  • 5. What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database you must access) a database? (some DBDs let you access non-database data, such as CSV files)
  • 6. What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database you must access) a database? (some DBDs let you access non-database data, such as CSV files) some Perl proficiency
  • 7. What do I need for database interactions with Perl? DBI – DataBase Interface (always) DBD – DataBase Driver (one for each type of database you must access) a database? (some DBDs let you access non-database data, such as CSV files) some Perl proficiency But we only care about using our Voyager database, so we’ll stick with that.
  • 8. What does this mean to you?
  • 9. What does this mean to you? DBI – DataBase Interface (already on your Voyager box)
  • 10. What does this mean to you? DBI – DataBase Interface (already on your Voyager box) DBD – DataBase Driver (for , already on your Voyager box)
  • 11. What does this mean to you? DBI – DataBase Interface (already on your Voyager box) DBD – DataBase Driver (for , already on your Voyager box) a database? (already on your Voyager box)
  • 12. What does this mean to you? DBI – DataBase Interface (already on your Voyager box) DBD – DataBase Driver (for , already on your Voyager box) a database? (already on your Voyager box) some Perl proficiency ( the only thing you supply! )
  • 13. A simple program Always needed for database access nameletters.pl
  • 14. A simple program Get access information from a setup file and connect to a database. File format (the only record): library.box.university.edu / username / password / VGER nameletters.pl
  • 15. A simple program Connect to the database and get a handle. nameletters.pl
  • 16. A simple program… for each letter, how many patrons’ last names start with that letter Create the query sprintf is your friend A sample query here is: select count (*) from wmichdb.patron where last_name like ‘S%’ nameletters.pl
  • 17. A simple program… for each letter, how many patrons’ last names start with that letter Prepare the query, associating it with a database, giving it a handle. nameletters.pl
  • 18. A simple program… for each letter, how many patrons’ last names start with that letter Run the query, get a return code. nameletters.pl
  • 19. A simple program… for each letter, how many patrons’ last names start with that letter Get the query result… nameletters.pl
  • 20. A simple program… for each letter, how many patrons’ last names start with that letter …and print it. nameletters.pl
  • 21. A simple program… for each letter, how many patrons’ last names start with that letter A: 003016 B: 007113 C: 005041 D: 003792 E: 001322 F: 002605 G: 003603 H: 005388 I: 000368 J: 001970 K: 004371 L: 003763 M: 007039 N: 001622 O: 001299 P: 003792 Q: 000121 R: 003770 S: 008217 T: 002528 U: 000248 V: 001791 W: 004487 X: 000018 Y: 000562 Z: 000709 Output nameletters.pl
  • 22. Nested query example… getting barcodes of retirees who’ve borrowed something within the past year retirees.pl
  • 23. Nested query example… getting barcodes of retirees who’ve borrowed something within the past year Outer query Get patron information that meets the criteria, and connecting information for barcodes. (sprintf actually not needed here) retirees.pl
  • 24. Nested query example… getting barcodes of retirees who’ve borrowed something within the past year Inner query Remember the outer query? Note the positional correspondence of the query parameters with the while statement receiving a query row. retirees.pl
  • 25. Nested query example… getting barcodes of retirees who’ve borrowed something within the past year Inner query The inner query has a different query string name… retirees.pl
  • 26. Nested query example… getting barcodes of retirees who’ve borrowed something within the past year Inner query …as do the other variables for this query. retirees.pl
  • 27. Nested query example… getting barcodes of retirees who’ve borrowed something within the past year Inner query Doe, John R doe1 pgroup: EMERIT/RET 21141002502810 08/16/1999 Other 99952803601000 11/25/2001 Expired Doe, Josephine doe2 pgroup: RETIREDSTF 21141001297289 08/16/1999 Other 21141002300660 08/16/1999 Other 11130755000000 09/04/2002 Expired retirees.pl Sample output:
  • 28. Termination Notes $sth->finish finish a query $dbh->disconnect disconnect from a database finish seems like a good practice, but it’s not really needed. Yet… disconnect isn’t really needed (for our purposes, read-only). However, without using the finish statement, you could run into error situations. leading us to…
  • 29. CPAN the Comprehensive Perl Archive Network Great resource for *all* kinds of Perl modules Documentation for modules - comprehensively so for DBI and DBD - about 100 pages for DBI and 50 pages for DBD
  • 30. A bit more documentation… $sth->fetchrow_array returns a single value, array, or list There are a number of other ways to get query data, but this seems to work best. You can also get lots of details about your database environment via DBI calls. See the DBI documentation for more information.
  • 31. A quick little DBI utility dbddrivers.pl
  • 32. A quick little DBI utility Available Perl DBD drivers on this system DBM ExampleP File Gofer Oracle Proxy Sponge Output dbddrivers.pl
  • 33. What if you need to look at every bib record you’ve got?
  • 34. What if you need to look at every bib record you’ve got? And you need to access the marc record (synonymous with )? Here’s one approach… THE BLOB
  • 35. connect to the database query bib_data table to get the maximum bib ID set increment to 50,000 set ending bib ID to increment set beginning bib ID to 0 Traversing every record and dealing with THE BLOB along the way
  • 36. connect to the database query bib_data table to get the maximum bib ID set increment to 50,000 set ending bib ID to increment set beginning bib ID to 0 while beginning bid ID < maximum bib ID chunkthroughdb() provide feedback of progress beginning bib ID = ending bib ID + 1 add increment to ending bib ID end provide final feedback Traversing every record and dealing with THE BLOB along the way
  • 37. sub chunkthrudb query bib_data for blob data based on bib IDs >= beginning bib ID and bib IDs < ending bib ID for each record from the query assemble each bib ID's data into a marc record do the required processing for this record end end Traversing every record and dealing with THE BLOB along the way
  • 38. Traversing every record and dealing with THE BLOB along the way Discussion of this approach Alternative method: read the whole database at once! - might be impossible - might not be feasible - probably not efficient The program presented here…seems to be the better method.
  • 39. Traversing every record and dealing with THE BLOB along the way Discussion of this approach If nothing else, “chunking” your way through your database is more efficient We have close to 1.6 million bib records. Based on the program we’re about to see, traversing our database… using 50,000 record chunks takes about 50 minutes without “chunking” it takes about 76 minutes
  • 40. Traversing every record and dealing with THE BLOB along the way findbadleader.pl
  • 41. Traversing every record and dealing with THE BLOB along the way Get our boundary condition findbadleader.pl
  • 42. Traversing every record and dealing with THE BLOB along the way 0-50,000 – our first chunk of records findbadleader.pl
  • 43. Traversing every record and dealing with THE BLOB along the way the loop findbadleader.pl
  • 44. Traversing every record and dealing with THE BLOB along the way set up the next chunk the loop findbadleader.pl
  • 45. Traversing every record and dealing with THE BLOB along the way - chunking subroutine (chunkthrudb) “ seqnum desc” is key to getting the blob data for each record This gets one chunk’s worth of MARC records (blob data) findbadleader.pl
  • 46. Traversing every record and dealing with THE BLOB along the way - chunking subroutine (chunkthrudb ) Creates the MARC record for each bib retrieved. For larger records that don’t fit in one table row, assemble the record in reverse order (from the query). findbadleader.pl
  • 47. Traversing every record and dealing with THE BLOB along the way - chunking subroutine (chunkthrudb ) Process each record. In this case, we’re looking for records with bad leaders (not ending in “4500”). Sample output: findbadleader.pl
  • 48. Being in a is a good thing… bind sprintf is a friend, but bind is a better friend
  • 49. Being in a is a good thing… bind sprintf is a friend, but bind is a better friend usual query method
  • 50. Being in a is a good thing… bind sprintf is a friend, but bind is a better friend usual query method query with bind values method
  • 51. testbind.pl Illustrating and contrasting the query with bind method create, prepare, and execute a query
  • 52. testbind.pl Illustrating and contrasting the query with bind method prepare and execute a query
  • 53. testbind.pl Illustrating and contrasting the query with bind method prepare and execute a query, improved prepare moved outside of the loop
  • 54. testbind.pl Illustrating and contrasting the query with bind method Using testbind.pl for about 80,000 patron records, these are the results: 10 Prepare and execute a query, improved (with bind) 11 Prepare and execute a query (with bind) 20 Create, prepare and execute a query Runtime (seconds) Method
  • 55. Running reports, queries via Perl on your PC ActiveState sells products and also has free versions. I recommend their free Perl. Get the MSI version. It comes with DBI and DBD for Oracle, among many other modules (and lots of documentation). Still (!) requires external Oracle client software (at least as of version 5.10.0, build 1003)
  • 56. The files listed below are available at http://homepages.wmich.edu/~zimmer/files/eugm2008 dbi.ppt this presentation nameletters.pl for every letter, find number of patrons whose last names begin with that letter retirees.pl get barcodes of retirees who’ve borrowed something in the last year dbddrivers.pl get list of DBD drivers on your system findbadleader.pl find bib records with bad leaders (not ending in 4500) testbind.pl demonstrates varying query method efficiencies Resources
  • 57. CPAN http://cpan.org DBI http://search.cpan.org/~timb/DBI-1.605/DBI.pm DBD Oracle http://search.cpan.org/~pythian/DBD-Oracle-1.21/Oracle.pm Active State Perl http://activestate.com/downloads/index.mhtml There is also a book on Perl and DBI. I’d recommend using it along with the most current documentation from the CPAN sites above. Resources
  • 58. Thank you for listening. Questions? [email_address] Picture © 2008 by Roy Zimmer