Re: Perl interface to Informix
Posted in 1998
On Mon, 28 Sep 1998, Jonathan White wrote: > Can anyone tell me how to use perl to access an informix data base? > (Maybe some example code) See my sig. One test from DBD::Informix is attached -- it is a semi-reasonable example as it doesn't use too much material from the DBD::InformixTest package. DBD::InformixTest does the regulation 'use DBI;' which you would normally write in your own code, unless you developed a package parallel to DBD::InformixTest to give you convenient cover functions for SQL operations. You will also need DBI 1.02 from CPAN. Yours, Jonathan Leffler (jleffler@informix.com) #include <witticism.h> Guardian of DBD::Informix v0.60 -- http://www.perl.com/CPAN Informix IDN for D4GL & Linux -- http://www.informix.com/idn #!/usr/bin/perl -w # # @(#)$Id: t40rows.t,v 57.1 1997/07/29 01:24:32 johnl Exp $ # # Test $sth->rows1 for DBD::Informix # # Copyright (C) 1997 Jonathan Leffler use DBD::InformixTest; sub select_row_data { my ($dbh, $num, $stmt) = @_; my ($count, $st2) = (0); my (@row); &stmt_note("# $stmt\\n"); # Check that there is some data &stmt_fail() unless ($st2 = $dbh->prepare($stmt)); &stmt_fail() unless ($st2->execute); while (@row = $st2->fetchrow) { my($pad, $i) = ("# ", 0); for ($i = 0; $i < @row; $i++) { &stmt_note("$pad$row[$i]"); $pad = " :: "; } &stmt_note("\\n"); my($n) = $st2->rows; $count++; &stmt_note("# rows = $n, count = $count\\n"); &stmt_fail() unless $n = $count; } &stmt_fail() unless ($count == $num); &stmt_fail() unless ($st2->finish); undef $st2; &stmt_ok(); } # Test install... $dbh = &connect_to_test_database(1); &stmt_note("1..9\\n"); &stmt_ok(); $table = "dbd_ix_rows"; # Create table for testing stmt_test $dbh, qq{ CREATE TEMP TABLE $table ( Col01 SERIAL(1000) NOT NULL, Col02 CHAR(20) NOT NULL, Col03 DATE NOT NULL, Col04 DATETIME YEAR TO FRACTION(5) NOT NULL, Col05 DECIMAL NOT NULL ) }; stmt_test $dbh, qq{ INSERT INTO $table VALUES(0, 'Some Value', TODAY, CURRENT, 3.14159) }; $select = "SELECT * FROM $table"; # Check that there is now one row of data select_row_data $dbh, 1, $select; # Insert a row of values. $sth = $dbh->prepare("INSERT INTO $table VALUES(0, ?, ?, ?, ?)"); &stmt_fail() unless $sth; &stmt_ok; &stmt_fail() unless $sth->execute('Another value', 'today', '1997-02-28 00:11:22.55555', 2.8128); &stmt_ok; print_sqlca $sth; $rows = $sth->rows; print "# ROWS = $rows\\n"; # Check that there are now two rows of data select_row_data $dbh, 2, $select; $sth = $dbh->prepare("DELETE FROM $table"); &stmt_fail() unless $sth; &stmt_ok; &stmt_fail() unless $sth->execute();; &stmt_ok; print_sqlca $sth; $rows = $sth->rows; print "# ROWS = $rows\\n"; &all_ok();