Connecting to Informix Databases the Open Source

Connecting to Informix Databases the Open Source

Platform: IBM Informix Dynamic Server 10.00 Connecting to IBM Informix Dynamic Server – the Open Source Way Jonathan Leffler STSM, IBM Informix Database Engineering Session: K12 2005-05-26 08:30 Agenda • Open Source • Underlying connectivity • ESQL/C • ODBC • JDBC • Perl, DBI, and DBD::Informix • Tcl/Tk, isqltcl • PHP • Python • Ruby 2 Open Source • What is Open Source? • Which rock have you been hiding under? • Software released under an Open Source license • Conformant with the Open Source Definition • Found at http://www.opensource.org/ • Free Redistribution • Source Code • Derived Works Permitted • No Discrimination Against People or Groups • No Discrimination Against Fields of Endeavour • Distribution of License 3 Open Source Licenses • There are many alternative Open Source licenses • GPL – GNU Public License • LGPL – Lesser GNU Public License • BSD – Berkeley Systems Distribution • MIT – Massachussetts Institute of Technology (X) • MPL – Mozilla Public License • Academic Free License • Open Software License • Nearly 60 licenses listed at the Open Source Initiative! 4 Informix Database Connectivity • ESQL/C • The original connectivity. • Standardized in SQL standards (ISO/IEC 9075:1992 onwards). • ODBC • Originally defined by Microsoft. • Standardized (as CLI) by ISO/IEC 9075-3:1996. • JDBC • Java analogue of ODBC. • Standardized by Sun. • All of these are proprietary. • But can be used with Open Source software. 5 ESQL/C • Preprocessor which converts extended C into pure C. • Links with specific libraries. • Permits separation of static and dynamic SQL. • Even though Informix does not really do so. int main(void) { EXEC SQL WHENEVER ERROR STOP; EXEC SQL DATABASE Stores; EXEC SQL BEGIN WORK; EXEC SQL DROP TABLE Customer; EXEC SQL ROLLBACK WORK; return(0); } 6 ODBC • Database agnostic. • Separates driver manager from drivers. • Different drivers can be loaded at run time. • With care, you can avoid database-specific features. • But sometimes you want to use them. • All statements are dynamic. • De-emphasized by Microsoft • In favour of newer technologies • ADO • .NET 7 JDBC • Database agnostic. • Drivers have different levels of Java-ness. • Type 4: pure Java – usually the best type to use. • The only other way to connect is ESQL/J. • Not widely accepted. • JDBC is the lingua franca of the Java database world. 8 Perl, DBI, and DBD::Informix • Perl • DBI • DBD::Informix • Apache • mod_perl 9 Perl – Practical Extraction and Report Language • Originally written by Larry Wall • Version 1.0 in 1987 • Version 4.0 in 1991 under GPL and Artistic License • Version 5.0 in 1994 • Current stable versions: • 5.8.6 — November 2004 • 5.6.1 — August 2001 • 5.005_03 — April 2000 • Obtain via CPAN • Comprehensive Perl Archive Network • http://www.cpan.org/ 10 Perl • Script Language • Does not require compilation • Complex looking code • Can be incredibly terse • Can be quite legible • Excellent at string handling • Excellent access to operating system 11 Remove RCS Keyword Markers • #!/usr/bin/perl -wp • s/\$([A-Z][a-z]+|RCSfile): ([^\$]+) \$/$2/go; • TMTOWTDI • There’s more than one way to do it! • (Yes, you could use sed for this) • perl -wp -e ’s/\$\w+: ([^\$]+) \$/$1/go;’ $* 12 File Renaming #!/usr/bin/perl # @(#)$Id: rename.pl,v 1.1 1992/01/05 22:33:47 jl Exp $ # Rename files using a Perl substitute command ($op = shift) || die "Usage: $0 perlexpr [filenames]\n"; if (!@ARGV) { @ARGV = <STDIN>; chop(@ARGV); } for (@ARGV){ $was = $_; eval $op; die $@ if $@; rename($was, $_) unless $was eq $_; } 13 Perl Database Interface • DBI written by Tim Bunce. • Standard way to access databases with Perl. • Many database drivers available. • Including ODBC, DB2, and Oracle. • And, of course, Informix. • And many others. • Current version 1.48 – March 2005. • Requires Perl 5.6.1 or later. • Using Perl and a database? Use DBI! • Or a module built on top of DBI. 14 The Cheetah Book • The ‘bible’ for Perl DBI • Authors: • Alligator Descartes • Tim Bunce • O’Reilly, February 2000 • ISBN 1-56592-699-4 • http://www.oreilly.com/ 15 DBI - Database Handles • Load DBI • use DBI; • Create database handles • $dbh = DBI->connect(‘DBI:Informix:stores7’); • Database methods • $dbh->do(‘DELETE FROM Customer’); • Transaction control • $dbh->rollback; • $dbh->commit; • Disconnect • $dbh->disconnect; 16 DBI - Statement Handles • Create statement handles • $sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ‘%$name%’ AND ZipCode IS NULL }); • Statements can be executed • $sth->execute(); • Statement handles can be released • Implicitly • Statement handle goes out of scope • Explicitly • undef $sth; 17 DBI - Handling SELECT • Statement handles are used for SELECT too • $sth = $dbh->prepare(qq% SELECT * FROM Customer WHERE Fname = ? AND Lname = ? ORDER BY Lname, Fname%); • $sth->execute($firstname, $surname); • @results = $sth->fetchall_arrayref; • …process results • print $results[$rownum][$colnum], etc • undef $sth; • SELECT is fairly simple 18 DBI - Handling SELECT • Many ways to fetch rows • $sth->fetchrow_array • $sth->fetchrow_hashref • $sth->fetchrow_arrayref • $sth->fetchall_arrayref • All rows • Also utility methods • $dbh->selectrow_array • First row only • $dbh->selectall_arrayref 19 DBD::Informix - at last • Using DBD::Informix is using DBI • All the examples work with DBD::Informix • Current version is 2005.01 – March 2005 • Building DBD::Informix is easy • Requires working ESQL/C 5.00 or later (eg ClientSDK) • ANSI C compiler (code uses prototypes) • Test database with DBA privileges • Perl version 5.6.0 or later • 5.8.6 (or, at a pinch, 5.6.1) strongly recommended • DBI version 1.38 or later • Version 1.48 or later strongly recommended 20 Installing DBD::Informix • Download software from CPAN • cd DBD-Informix-2005.01 • more README • perl Makefile.PL • make • make test • make install • Have fun! • Same rules apply to all Perl modules • Building Perl modules is easy! 21 DBD::Informix - example #! /usr/bin/perl -w use DBI; $dbh = DBI->connect(‘DBI:Informix:stores7’,’’,’’, {RaiseError => 1, PrintError=>1}); $sth = $dbh->prepare(q%SELECT Fname, Lname, Phone FROM Customer WHERE Customer_num = ? %); $sth->execute(106); $ref = $sth->fetchall_arrayref(); for $row (@$ref) { print “Name: $$row[0] $$row[1], Phone: $$row[2]\n”; } $dbh->disconnect; 22 DBD::Informix & AutoCommit • AutoCommit is on by default • To comply with DBI requirements • Cannot be unset on unlogged databases • Simulates MODE ANSI on logged databases • Explicit BEGIN WORK is possible • $dbh->do(‘begin work’); • $dbh->{AutoCommit} = 0; • $dbh = DBI->connect(‘DBI:Informix:stores7’, ‘’, ‘’, { AutoCommit => 0 }); 23 Standard DBI Information • Standard database attributes • $dbh->{Driver} • $dbh->{AutoCommit} • $dbh->{PrintError} • $dbh->{RaiseError} • $dbh->{ChopBlanks} • There are others, too. 24 Standard DBI Information • Standard statement attributes • $sth->{Statement} • $sth->{CursorName} • $sth->{NUM_OF_FIELDS} • $sth->{NUM_OF_PARAMS} • $sth->{NAME} • $sth->{TYPE} • $sth->{NULLABLE} 25 Standard DBI Information • Standard handle attributes • $h->err • $h->errstr • $h->state • Standard handle methods • $h->trace($trace_level) • $h->trace_msg(“message”) 26 Informix-only Information • SQLCA is available • $sth->{ix_sqlcode} • $sth->{ix_sqlerrd} - an array • $sth->{ix_sqlerrm} • $sth->{ix_sqlerrp} • $sth->{ix_sqlwarn} - an array 27 Informix-only Information • Non-standard attributes • $dbh->{ix_InformixOnline} • $dbh->{ix_LoggedDatabase} • $dbh->{ix_ModeAnsiDatabase} • $dbh->{ix_InTransaction} • $dbh->{ix_ConnectionName} • Standard attribute • $dbh->{Name} — database name 28 Informix-only Information • Non-standard attributes • $drh->{ix_ProductVersion} • a version number for ESQL/C • $drh->{ix_ProductName} • $drh->{ix_MultipleConnections} • $drh->{ix_ActiveConnections} • $drh->{ix_CurrentConnection} • $drh->{ix_ServerVersion} • a version number for the database server • All these attributes can also be found via the database handle, $dbh 29 Informix-only Information • Non-standard attributes • $sth->{ix_NativeTypeName} • $sth->{ix_ColType} • $sth->{ix_ColLength} 30 DBD::Informix • Known Limitations: • Not yet fully aware of 9.x collection types or UDTs. • No support for bind_param_inout method. • No handling for most new DBI features since v1.14. • Version 1.00.PC2 was an official Informix product. • Officially “IBM Informix Database Driver for Perl”. • Version 2003.04 was officially not an IBM product. • The support channel is the mailing list: • [email protected][email protected][email protected] 31 DBD::Informix Documents • Primary References • Pre-install • README file • Files in Notes sub-directory • Post-install • perldoc DBI • perldoc DBD::Informix • Books • Programming Perl, 3rd Edition • Programming the Perl DBI 32 DBD::Informix - Web Sites • Use CPAN to obtain the software • http://www.cpan.org/ • http://search.cpan.org/ • perl –MCPAN –e ‘install Bundle::DBD::Informix’ • DBI web site • http://dbi.perl.org/ • Sign up for [email protected] mailing list • Help yourself - join the mailing list! 33 Apache • Apache Web Server • Most widely used web server • Version 1.3.33 • unless there’s a new version this week • Or Version 2.0.52 • Modular structure • Allows special purpose modules to be added • mod_jserv - Java Server • mod_perl - Perl Interpreter 34 Apache, Perl and CGI • CGI scripts drive the web • Many of them are Perl scripts • Most of those use the CGI module • http://www.somewhere.com/cgi-bin/script.pl • Giveaway that there’s a Perl script in use • Often

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    82 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us