49
1 Connecting to IDS Connecting to IDS The Open Source Way The Open Source Way Jonathan Leffler Jonathan Leffler Sr. Technical Staff Sr. Technical Staff Member/IBM Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta, Georgia December 8-9, 2005

1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

Embed Size (px)

Citation preview

Page 1: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

1

Connecting to IDSConnecting to IDS

The Open Source WayThe Open Source Way

Jonathan LefflerJonathan LefflerSr. Technical Staff Sr. Technical Staff

Member/IBMMember/IBM

Informix User Forum 2005 Moving Forward With Informix

Atlanta, Georgia December 8-9, 2005

Page 2: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 22

AgendaAgenda

Open SourceOpen Source Connecting to IDSConnecting to IDS Perl, DBI, and DBD::Informix Perl, DBI, and DBD::Informix ** Tcl/Tk and isqltclTcl/Tk and isqltcl PHPPHP Aubit 4GLAubit 4GL SQLCMD SQLCMD ** SQSLSQSL Python Python ** RubyRuby

Page 3: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 33

Open SourceOpen Source

What is Open Source?What is Open Source?– Which rock have you been hiding under?Which rock have you been hiding under?– Software released under an Open Source Software released under an Open Source

licenselicense Conformant with the Open Source DefinitionConformant with the Open Source Definition Found at Found at http://www.opensource.org/http://www.opensource.org/

– Free RedistributionFree Redistribution– Source CodeSource Code– Derived Works PermittedDerived Works Permitted– No Discrimination Against People or GroupsNo Discrimination Against People or Groups– No Discrimination Against Fields of EndeavourNo Discrimination Against Fields of Endeavour– Distribution of LicenseDistribution of License

Page 4: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 44

Open Source LicensesOpen Source Licenses

There are many Open Source licensesThere are many Open Source licenses– GPL – GNU Public LicenseGPL – GNU Public License– LGPL – Lesser GNU Public LicenseLGPL – Lesser GNU Public License– BSD – Berkeley Systems DistributionBSD – Berkeley Systems Distribution– MIT – Massachussetts Institute of TechnologyMIT – Massachussetts Institute of Technology– MPL – Mozilla Public LicenseMPL – Mozilla Public License– Academic Free LicenseAcademic Free License– Open Software LicenseOpen Software License– Nearly 60 licenses at the Open Source Nearly 60 licenses at the Open Source

Initiative!Initiative!

Page 5: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 55

Informix Database Informix Database ConnectivityConnectivity ESQL/CESQL/C

– The original connectivity.The original connectivity.– Standardized in SQL by ISO/IEC 9075:1992Standardized in SQL by ISO/IEC 9075:1992

ODBCODBC– Originally defined by Microsoft.Originally defined by Microsoft.– Standardized (as CLI) by ISO/IEC 9075-3:1996.Standardized (as CLI) by ISO/IEC 9075-3:1996.

JDBCJDBC– Java analogue of ODBC.Java analogue of ODBC.– Standardized by Sun.Standardized by Sun.

All of these are proprietary.All of these are proprietary. But can be used with Open Source But can be used with Open Source

software.software.

Page 6: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 66

ESQL/CESQL/C

Preprocessor which converts extended C Preprocessor which converts extended C into pure C.into pure C.

Links with specific libraries.Links with specific libraries. Separates static and dynamic SQL.Separates static and dynamic SQL.

– Even though Informix does not really do so.Even though Informix does not really do so.int main(void) {int main(void) { EXEC SQL WHENEVER ERROR STOP;EXEC SQL WHENEVER ERROR STOP; EXEC SQL DATABASE Stores;EXEC SQL DATABASE Stores; EXEC SQL BEGIN WORK;EXEC SQL BEGIN WORK; EXEC SQL DROP TABLE Customer;EXEC SQL DROP TABLE Customer; EXEC SQL ROLLBACK WORK;EXEC SQL ROLLBACK WORK; return(0);return(0);}}

Page 7: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 77

ODBCODBC

Database agnostic.Database agnostic.– Separates driver manager from drivers.Separates driver manager from drivers.– Different drivers can be loaded at run time.Different drivers can be loaded at run time.– You can avoid database-specific features.You can avoid database-specific features.– But sometimes you want to use them.But sometimes you want to use them.

All statements are dynamic.All statements are dynamic. De-emphasized by MicrosoftDe-emphasized by Microsoft

– In favour of newer technologiesIn favour of newer technologies ADO, .NETADO, .NET

Page 8: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 88

JDBCJDBC

Database agnostic.Database agnostic. Drivers have different levels of Java-ness.Drivers have different levels of Java-ness.

– Type 4: pure Java – usually the best type to Type 4: pure Java – usually the best type to use.use.

The other way to connect in Java is The other way to connect in Java is ESQL/J.ESQL/J.– Not widely accepted.Not widely accepted.

JDBC is the lingua franca of the Java JDBC is the lingua franca of the Java database world.database world.

Page 9: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 99

Perl – Perl – Practical Extraction Practical Extraction and Report Language and Report Language **

Originally written by Larry WallOriginally written by Larry Wall– Version 1.0 in 1987Version 1.0 in 1987– Version 5.0 in 1994Version 5.0 in 1994– Version 6 under development (2+ years so Version 6 under development (2+ years so

far)far) Current stable version:Current stable version:

– 5.8.75.8.7 — June 2005— June 2005 Obtain via CPANObtain via CPAN

– Comprehensive Perl Archive NetworkComprehensive Perl Archive Network– http://www.cpan.org/http://www.cpan.org/

Page 10: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1010

PerlPerl

Script LanguageScript Language– Does not require separate compilationDoes not require separate compilation

Complex looking codeComplex looking code Can be incredibly terseCan be incredibly terse Can be quite legibleCan be quite legible Excellent at string handlingExcellent at string handling Excellent access to operating systemExcellent access to operating system

Page 11: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1111

Perl Database InterfacePerl Database Interface

DBI written by Tim Bunce.DBI written by Tim Bunce. Standard way to access databases with Standard way to access databases with

Perl.Perl. Many database drivers available.Many database drivers available.

– Including ODBC, DB2, and Oracle.Including ODBC, DB2, and Oracle.– And, of course, Informix.And, of course, Informix.– And many others.And many others.

DBI – version 1.49, November 2005.DBI – version 1.49, November 2005.– Requires Perl 5.6.1 or later.Requires Perl 5.6.1 or later.

DBD::Informix – version 2005.02, July DBD::Informix – version 2005.02, July 2005.2005.

Page 12: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1212

DBI – Database HandlesDBI – Database Handles

Load DBILoad DBI– use DBI;use DBI;

Create database handlesCreate database handles– $dbh = DBI->connect(‘DBI:Informix:stores7’);$dbh = DBI->connect(‘DBI:Informix:stores7’);

Database methodsDatabase methods– $dbh->do(‘DELETE FROM Customer’);$dbh->do(‘DELETE FROM Customer’);

Transaction controlTransaction control– $dbh->rollback;$dbh->rollback;– $dbh->commit;$dbh->commit;

DisconnectDisconnect– $dbh->disconnect;$dbh->disconnect;

Page 13: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1313

DBI – Statement HandlesDBI – Statement Handles

Create statement handlesCreate statement handles– my $xname = $dbh->quote(“%$name%”);my $xname = $dbh->quote(“%$name%”);– $sth = $dbh->prepare(qq{ DELETE FROM $sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE $xname AND Customer WHERE Lname LIKE $xname AND ZipCode IS NULL });ZipCode IS NULL });

Statements can be executedStatements can be executed– $sth->execute();$sth->execute();

Statement handles can be releasedStatement handles can be released– Implicitly – statement handle goes out of Implicitly – statement handle goes out of

scopescope– Explicitly – Explicitly – undef $sth;undef $sth;

Page 14: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1414

Danger – SQL InjectionDanger – SQL Injection

What happens if the code is written as:What happens if the code is written as:– $sth = $dbh->prepare(qq{ DELETE FROM $sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ‘%$name%’ AND Customer WHERE Lname LIKE ‘%$name%’ AND ZipCode IS NULL });ZipCode IS NULL });

This is a security breach ready to This is a security breach ready to happenhappen– SQL injection exploit.SQL injection exploit.

What happens if the user enters this What happens if the user enters this name:name:– X%’ OR fname != ‘X’ OR fname = ‘X%’ OR fname != ‘X’ OR fname = ‘

Page 15: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1515

Danger – SQL InjectionDanger – SQL Injection

The query is now:The query is now:– DELETE FROM Customer WHERE Lname LIKE ‘%DELETE FROM Customer WHERE Lname LIKE ‘%X%’ OR X%’ OR fname != ‘X’ OR fname = ‘fname != ‘X’ OR fname = ‘%’ AND ZipCode IS NULL%’ AND ZipCode IS NULL

This deletes all (most) rows from the table!This deletes all (most) rows from the table! Use $dbh->quote($name) – if you must.Use $dbh->quote($name) – if you must. Better to use placeholders (?) in the SQLBetter to use placeholders (?) in the SQL

– $sth = $dbh->prepare(qq{ DELETE FROM Customer $sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ? AND ZipCode IS NULL });WHERE Lname LIKE ? AND ZipCode IS NULL });

Page 16: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1616

DBI – Handling SELECTDBI – Handling SELECT

Statement handles are used for SELECT Statement handles are used for SELECT tootoo– $sth = $dbh->prepare(q% SELECT * FROM $sth = $dbh->prepare(q% SELECT * FROM Customer WHERE Fname = ? AND Lname = ? Customer WHERE Fname = ? AND Lname = ? ORDER BY Lname, Fname%);ORDER BY Lname, Fname%);

– $sth->execute($firstname, $surname);$sth->execute($firstname, $surname);– @results = $sth->fetchall_arrayref;@results = $sth->fetchall_arrayref;– ……process results…process results…

print $results[$rownum][$colnum];print $results[$rownum][$colnum];– undef $sth;undef $sth;

Page 17: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1717

DBI – Handling SELECTDBI – Handling SELECT

Many ways to fetch rowsMany ways to fetch rows– $sth->fetchrow_array$sth->fetchrow_array– $sth->fetchrow_hashref$sth->fetchrow_hashref– $sth->fetchrow_arrayref$sth->fetchrow_arrayref– $sth->fetchall_arrayref$sth->fetchall_arrayref

All rowsAll rows Also utility methodsAlso utility methods

– $dbh->selectrow_array$dbh->selectrow_array First row onlyFirst row only

– $dbh->selectall_arrayref$dbh->selectall_arrayref

Page 18: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1818

#! /usr/bin/perl -wuse 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;

DBD::Informix – exampleDBD::Informix – example

Page 19: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 1919

Tcl/Tk and isqltclTcl/Tk and isqltcl

Tcl – Tool Control LanguageTcl – Tool Control Language– Invented by John OusterhoutInvented by John Ousterhout

Tk – Tool Kit (GUI)Tk – Tool Kit (GUI) Tcl/Tk – at Tcl/Tk – at http://www.tcl.tk/http://www.tcl.tk/

– Current version 8.4.12 – December 2005.Current version 8.4.12 – December 2005. isqltcl – Informix SQL access via Tcl.isqltcl – Informix SQL access via Tcl.

– Available at Available at http://isqltcl.sourceforge.net/http://isqltcl.sourceforge.net/ – Version 5.0 – released February 2002.Version 5.0 – released February 2002.– Builds into dynamically loadable shared libraryBuilds into dynamically loadable shared library

Page 20: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2020

Tcl/Tk ExtensionsTcl/Tk Extensions

Tcl/Tk is designed to be easily Tcl/Tk is designed to be easily extendedextended

Many extensions available for all jobs Many extensions available for all jobs For exampleFor example

– ExpectExpect Designed to handle scripting of Designed to handle scripting of

processesprocesses Used for automating testingUsed for automating testing ftp://expect.nist.gov/ ftp://expect.nist.gov/

– And many more...And many more...

Page 21: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2121

Loading ISQLTCLLoading ISQLTCL

Load the ISQLTCL extensionLoad the ISQLTCL extension– load isql.soload isql.so

Adds the command ‘sql’ to Tcl/TkAdds the command ‘sql’ to Tcl/Tk– tclshtclsh– wishwish

Page 22: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2222

ISQLTCL – ConnectionsISQLTCL – Connections

Connect to a databaseConnect to a database– sql connect dbase as conn1 user \ sql connect dbase as conn1 user \ $username password $password$username password $password

Connect to given databaseConnect to given database– sql disconnect \ sql disconnect \ [current|default|[current|default|all|conn1all|conn1]]

Close database connectionClose database connection– sql setconnection sql setconnection [default|conn1][default|conn1]

Sets the specified connectionSets the specified connection

Page 23: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2323

ISQLTCL – StatementsISQLTCL – Statements

Executable statementsExecutable statements– Statements that return no dataStatements that return no data

sql run {delete from sometablesql run {delete from sometable where pkcol = ?} $pkvalwhere pkcol = ?} $pkval

– Prepares and executes the statementPrepares and executes the statement– Optionally takes a number of arguments Optionally takes a number of arguments

for placeholdersfor placeholders– Returns zero on success; non-zero on Returns zero on success; non-zero on

failurefailure

Page 24: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2424

ISQLTCL – CursorsISQLTCL – Cursors

SELECT, EXECUTE PROCEDURESELECT, EXECUTE PROCEDURE set stmt [sql open {select * fromset stmt [sql open {select * from

sometable}]sometable}]– Does PREPARE, DECLARE, and OPENDoes PREPARE, DECLARE, and OPEN– Returns a statement number (id) or a negative errorReturns a statement number (id) or a negative error– Optionally takes arguments for placeholdersOptionally takes arguments for placeholders

set row [sql fetch $stmt 1]set row [sql fetch $stmt 1]– Collects one row of dataCollects one row of data– As a Tcl list in the variable ‘row’As a Tcl list in the variable ‘row’– The 1 is optional and means strip trailing blanksThe 1 is optional and means strip trailing blanks– The list is empty if there is no more dataThe list is empty if there is no more data

Page 25: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2525

ISQLTCL – CursorsISQLTCL – Cursors

sql reopen $stmt sql reopen $stmt ?arg1? ?arg2??arg1? ?arg2?– Reopens the statement, with new Reopens the statement, with new

parametersparameters sql close $stmtsql close $stmt

– Indicates you have no further use for the Indicates you have no further use for the statementstatement

– It frees both the cursor and statement!It frees both the cursor and statement!

Page 26: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2626

What is PHP?What is PHP?

Hypertext ProcessorHypertext Processor– Was once ‘Personal Home Page’Was once ‘Personal Home Page’

Version 4.4.1 released October 2005Version 4.4.1 released October 2005 Version 5.0.5 released September 2005Version 5.0.5 released September 2005 Version 5.1.1 released November 2005Version 5.1.1 released November 2005 An HTML scripting languageAn HTML scripting language

– Server-sideServer-side– Cross-platformCross-platform– Embedded in HTML documentsEmbedded in HTML documents– ExtensibleExtensible

Page 27: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2727

What is PHP?What is PHP?

Built into the Apache Web ServerBuilt into the Apache Web Server– Using DSO (dynamic shared objects)Using DSO (dynamic shared objects)– mod_phpmod_php

Or as a CGI binaryOr as a CGI binary– With any web serverWith any web server

PHP has a reputation for being insecure.PHP has a reputation for being insecure.– Largely a question of how it is used.Largely a question of how it is used.– See PHP Security ConsortiumSee PHP Security Consortium

http://phpsec.org/ http://phpsec.org/

Page 28: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2828

What is PHP?What is PHP?

Built-in access to:Built-in access to:– EmailEmail– XMLXML– HTTP (cookies, sessions)HTTP (cookies, sessions)

And databases:And databases:– ODBCODBC

DB2, Adabas-D, Empress, Solid, VelocisDB2, Adabas-D, Empress, Solid, Velocis– mSQL, MySQL, PostgreSQLmSQL, MySQL, PostgreSQL– Sybase, OracleSybase, Oracle– InformixInformix

Page 29: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 2929

What is PHP?What is PHP?

IBM also provides modern PDO driversIBM also provides modern PDO drivers PDO – PHP Data ObjectsPDO – PHP Data Objects

– PHP analogue of Perl DBIPHP analogue of Perl DBI– Article on DeveloperWorksArticle on DeveloperWorks

http://tinyurl.com/eycg2http://tinyurl.com/eycg2 – For DB2For DB2

Via PDO_ODBCVia PDO_ODBC– For IDS (beta version 0.2.1)For IDS (beta version 0.2.1)

  http://pecl.php.net/package/PDO_INFORMIX http://pecl.php.net/package/PDO_INFORMIX

Page 30: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3030

Informative PHP ScriptInformative PHP Script

<HTML><HTML>

<HEAD><HEAD>

<TITLE> PHP Information </TITLE></HEAD><TITLE> PHP Information </TITLE></HEAD>

<BODY><BODY>

<?php<?phpecho “URL: echo “URL:

<B>http://$HTTP_HOST$PHP_SELF</B>”<B>http://$HTTP_HOST$PHP_SELF</B>”echo “<BR>\n”echo “<BR>\n”

phpinfo() ?>phpinfo() ?>

</BODY></BODY>

</HTML></HTML>

Page 31: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3131

Old Informix DriverOld Informix Driver

Code provided as standard part of PHP.Code provided as standard part of PHP.– But not maintained for several years.But not maintained for several years.

Must be explicitly compiled into PHP.Must be explicitly compiled into PHP. 30 core functions.30 core functions. 8 functions to manipulate SBLOBs.8 functions to manipulate SBLOBs.

Page 32: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3232

Old Informix DriverOld Informix Driver

Connection managementConnection management– ifx_connectifx_connect– ifx_pconnectifx_pconnect– ifx_closeifx_close

Basic OperationsBasic Operations– ifx_prepareifx_prepare– ifx_queryifx_query– ifx_fetch_rowifx_fetch_row– ifx_doifx_do– ifx_free_resultifx_free_result

Page 33: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3333

Old Informix DriverOld Informix Driver

Status and Error HandlingStatus and Error Handling– ifx_getsqlcaifx_getsqlca– ifx_errorifx_error– ifx_errormsgifx_errormsg– ifx_affected_rowsifx_affected_rows

Attribute QueriesAttribute Queries Blob handlingBlob handling Utility functionsUtility functions

– ifx_htmltbl_resultifx_htmltbl_result

Page 34: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3434

New Informix DriverNew Informix Driver

Accessed via PDO functionsAccessed via PDO functions– See: http://www.php.net/pdoSee: http://www.php.net/pdo– <?php<?php

try {try {   $dbh = new PDO(‘informix:dbname=stores',    $dbh = new PDO(‘informix:dbname=stores', $user, $pass);$user, $pass);} catch (PDOException $e) {} catch (PDOException $e) {   print "Error!: " . $e->getMessage() .    print "Error!: " . $e->getMessage() . "<br/>";"<br/>";   die();   die();}}?> ?>

Page 35: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3535

Python and InformixDBPython and InformixDB **

http://www.python.org/ http://www.python.org/ Version 2.4 – November 2004.Version 2.4 – November 2004. InformixDB – under active InformixDB – under active

developmentdevelopment– Maintainer: Carsten HaeseMaintainer: Carsten Haese

See Carsten’s presentation on CDSee Carsten’s presentation on CD– Python DB-API 2.0 compliantPython DB-API 2.0 compliant– Requires Python 2.2 or betterRequires Python 2.2 or better– Needs Informix ClientSDKNeeds Informix ClientSDK

Page 36: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3636

Python and InformixDBPython and InformixDB

import informixdbimport informixdbconn = informixdb.connect(”test”, ”informix”, ”pw”)conn = informixdb.connect(”test”, ”informix”, ”pw”)cur = conn.cursor()cur = conn.cursor()cur.execute(“create table test1(a int, b int)”)cur.execute(“create table test1(a int, b int)”)for i in range(1,25):for i in range(1,25): cur.execute("insert into test1 values(?,?)", (i, i**2))cur.execute("insert into test1 values(?,?)", (i, i**2))cur.execute("select * from test1")cur.execute("select * from test1")for row in cur:for row in cur: print "The square of %d is %d." % (row[0], row[1])print "The square of %d is %d." % (row[0], row[1])

Page 37: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3737

Aubit 4GL – Open Source Aubit 4GL – Open Source 4GL4GL 99% Informix99% Informix™™ 4GL Compatible 4GL Compatible BODR=Business Oriented, Database BODR=Business Oriented, Database

RelatedRelated– Task-focussed languageTask-focussed language

Embedded SQL for database accessEmbedded SQL for database access High productivity, easy to learnHigh productivity, easy to learn Licensed under GPL/LGPL Licensed under GPL/LGPL Includes 4GL-based Open Source softwareIncludes 4GL-based Open Source software For commercial and non-commercial For commercial and non-commercial

applicationsapplications

Page 38: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3838

Aubit 4GL – New to 4GL?Aubit 4GL – New to 4GL?

MAINMAINMENU "Title for my test menu"MENU "Title for my test menu"COMMAND "Impress Me" "Do something to impress me“COMMAND "Impress Me" "Do something to impress me“

HELP 126HELP 126CALL OpenMyWindow()CALL OpenMyWindow()

COMMAND "Exit" "Exit this menu" HELP 127COMMAND "Exit" "Exit this menu" HELP 127EXIT MENUEXIT MENU

END MENUEND MENUEND MAINEND MAIN

FUNCTION OpenMyWindow()FUNCTION OpenMyWindow()OPEN WINDOW MyTestWindow AT 2,3 WITH FORM OPEN WINDOW MyTestWindow AT 2,3 WITH FORM "FormForMyTestWindow" ATTRIBUTE(BORDER, WHITE)"FormForMyTestWindow" ATTRIBUTE(BORDER, WHITE)

END FUNCTIONEND FUNCTION

Think about amount of code to achieve same functionality in 3GL!Think about amount of code to achieve same functionality in 3GL!

Page 39: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 3939

Aubit 4GL – FeaturesAubit 4GL – Features

Database independentDatabase independent– ODBC, native, ESQL/CODBC, native, ESQL/C

Fully modular (plug-in) architectureFully modular (plug-in) architecture User interface independentUser interface independent

– GUI and Curses modesGUI and Curses modes Platform independentPlatform independent

– (POSIX, UNIX, Windows)(POSIX, UNIX, Windows) Easy to embed 3GL in 4GLEasy to embed 3GL in 4GL

– Embedded C codeEmbedded C code

Page 40: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4040

Aubit 4GL – Aubit 4GL – EnhancementsEnhancements

Logical ReportsLogical Reports ASQL – dbaccess/isql replacementASQL – dbaccess/isql replacement Flexible key mapping Flexible key mapping Print Screen functionsPrint Screen functions Fully integrated testing hooks Fully integrated testing hooks

(including key recording and replay for (including key recording and replay for batch jobs)batch jobs)

Dynamic function calls (like perl ‘::’)Dynamic function calls (like perl ‘::’)

Page 41: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4141

Aubit 4GL – Web SitesAubit 4GL – Web Sites

Web site Web site http://aubit4gl.sourceforge.nethttp://aubit4gl.sourceforge.net

Bug Tracker Bug Tracker http://www.aubit.com/mantishttp://www.aubit.com/mantis

Bulletin boardBulletin boardhttp://www.aubit.com/phpBBhttp://www.aubit.com/phpBB

Commercial supportCommercial supporthttp://www.aubit.comhttp://www.aubit.com

Current version:Current version:– 0.50-2 dated 2005-06-220.50-2 dated 2005-06-22

Page 42: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4242

SQLCMDSQLCMD **

Originally called RDSQL Originally called RDSQL in 1987.in 1987.– Renamed SQLCMD in 1992.Renamed SQLCMD in 1992.

Intended as an alternative to ‘isql’.Intended as an alternative to ‘isql’.– Before DB-Access was created.Before DB-Access was created.

Designed for use in shell scripts.Designed for use in shell scripts.– Exits with non-zero status on error.Exits with non-zero status on error.– Careful use of standard input, output, error.Careful use of standard input, output, error.– Output layout independent of selected data.Output layout independent of selected data.

Designed for interactive use.Designed for interactive use.

Page 43: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4343

SQSL – Structured Query SQSL – Structured Query Scripting LanguageScripting Language SQSL is a scripting languageSQSL is a scripting language

– Created by Marco GrecoCreated by Marco Greco– Superset of SQLSuperset of SQL– Features aimed at scripting, reporting, and Features aimed at scripting, reporting, and

simple ETLsimple ETL– Lets a DBA perform daily activities as Lets a DBA perform daily activities as

easily as possibleeasily as possible

Page 44: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4444

SQSL – Structured Query SQSL – Structured Query Scripting LanguageScripting Language It has a low learning curve:It has a low learning curve:

– Language features should be familiarLanguage features should be familiar To anyone with experience of SQL, SPL, To anyone with experience of SQL, SPL,

Informix 4GL or Bourne shellInformix 4GL or Bourne shell It includes flow-control operationsIt includes flow-control operations It has a curses-based full-screen modeIt has a curses-based full-screen mode

– Like DB-AccessLike DB-Access http://www.4glworks.com/sqsl.htm http://www.4glworks.com/sqsl.htm

Page 45: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4545

RubyRuby

http://www.ruby-lang.org/ http://www.ruby-lang.org/ Version 1.8.3 – September 2005.Version 1.8.3 – September 2005. No known Informix supportNo known Informix support

– Lots of different database support Lots of different database support packages.packages.

– No unifying concept like DBI or PDO.No unifying concept like DBI or PDO. See also ‘Ruby on Rails’See also ‘Ruby on Rails’

– http://www.rubyonrails.com/ http://www.rubyonrails.com/

Page 46: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4646

IIUG Software ArchiveIIUG Software Archive

http://www.iiug.org/software http://www.iiug.org/software Many useful utilitiesMany useful utilities Art Kagel’s ‘utils2_ak’ packageArt Kagel’s ‘utils2_ak’ package

– Generate UPDATE STATISTICS statementsGenerate UPDATE STATISTICS statements– DB-CopyDB-Copy

Stored Procedure LibrariesStored Procedure Libraries Example DataBladesExample DataBlades 4GL Code Generators4GL Code Generators

Page 47: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4747

http://www.ibm.com/software/data/informixhttp://www.iiug.org/software

Page 48: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

99thth December 2005 December 2005 Connecting to IDS the Open Source WayConnecting to IDS the Open Source Way 4848

http://www.ibm.com/software/data/informixhttp://www.iiug.org/software

Page 49: 1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,

49

Connecting to IDSConnecting to IDSThe Open Source WayThe Open Source Way

Jonathan LefflerJonathan [email protected]@us.ibm.com

Informix User Forum 2005 Moving Forward With Informix

Atlanta, Georgia December 8-9, 2005