Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Connecting to IDS The Open Source Way Jonathan Leffler Sr. Technical Staff Member/IBM Informix User Forum 2005 Moving Forward With Informix Atlanta,"— Presentation transcript:

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, Georgia December 8-9, 2005

2 9 th December 2005Connecting to IDS the Open Source Way2 Agenda Open Source Open Source Connecting to IDS Connecting to IDS Perl, DBI, and DBD::Informix * Perl, DBI, and DBD::Informix * Tcl/Tk and isqltcl Tcl/Tk and isqltcl PHP PHP Aubit 4GL Aubit 4GL SQLCMD * SQLCMD * SQSL SQSL Python * Python * Ruby Ruby

3 9 th December 2005Connecting to IDS the Open Source Way3 Open Source What is 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 Conformant with the Open Source Definition Found at Found at –Free Redistribution –Source Code –Derived Works Permitted –No Discrimination Against People or Groups –No Discrimination Against Fields of Endeavour –Distribution of License

4 9 th December 2005Connecting to IDS the Open Source Way4 Open Source Licenses There are many Open Source licenses There are many Open Source licenses –GPL – GNU Public License –LGPL – Lesser GNU Public License –BSD – Berkeley Systems Distribution –MIT – Massachussetts Institute of Technology –MPL – Mozilla Public License –Academic Free License –Open Software License –Nearly 60 licenses at the Open Source Initiative!

5 9 th December 2005Connecting to IDS the Open Source Way5 Informix Database Connectivity ESQL/C ESQL/C –The original connectivity. –Standardized in SQL by ISO/IEC 9075:1992 ODBC ODBC –Originally defined by Microsoft. –Standardized (as CLI) by ISO/IEC :1996. JDBC JDBC –Java analogue of ODBC. –Standardized by Sun. All of these are proprietary. All of these are proprietary. But can be used with Open Source software. But can be used with Open Source software.

6 9 th December 2005Connecting to IDS the Open Source Way6 ESQL/C Preprocessor which converts extended C into pure C. Preprocessor which converts extended 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. 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);}

7 9 th December 2005Connecting to IDS the Open Source Way7 ODBC Database agnostic. Database agnostic. –Separates driver manager from drivers. –Different drivers can be loaded at run time. –You can avoid database-specific features. –But sometimes you want to use them. All statements are dynamic. All statements are dynamic. De-emphasized by Microsoft De-emphasized by Microsoft –In favour of newer technologies ADO,.NET ADO,.NET

8 9 th December 2005Connecting to IDS the Open Source Way8 JDBC 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 use. The other way to connect in Java is ESQL/J. The other way to connect in Java is ESQL/J. –Not widely accepted. JDBC is the lingua franca of the Java database world. JDBC is the lingua franca of the Java database world.

9 9 th December 2005Connecting to IDS the Open Source Way9 Perl – Practical Extraction and Report Language * Originally written by Larry Wall Originally written by Larry Wall –Version 1.0 in 1987 –Version 5.0 in 1994 –Version 6 under development (2+ years so far) Current stable version: Current stable version: –5.8.7— June 2005 Obtain via CPAN Obtain via CPAN –Comprehensive Perl Archive Network –http://www.cpan.org/

10 9 th December 2005Connecting to IDS the Open Source Way10 Perl Script Language Script Language –Does not require separate compilation Complex looking code Complex looking code Can be incredibly terse Can be incredibly terse Can be quite legible Can be quite legible Excellent at string handling Excellent at string handling Excellent access to operating system Excellent access to operating system

11 9 th December 2005Connecting to IDS the Open Source Way11 Perl Database Interface DBI written by Tim Bunce. DBI written by Tim Bunce. Standard way to access databases with Perl. Standard way to access databases with Perl. Many database drivers available. Many database drivers available. –Including ODBC, DB2, and Oracle. –And, of course, Informix. –And many others. DBI – version 1.49, November DBI – version 1.49, November –Requires Perl or later. DBD::Informix – version , July DBD::Informix – version , July 2005.

12 9 th December 2005Connecting to IDS the Open Source Way12 DBI – Database Handles Load DBI Load DBI –use DBI; Create database handles Create database handles –$dbh = DBI->connect(‘DBI:Informix:stores7’); Database methods Database methods –$dbh->do(‘DELETE FROM Customer’); Transaction control Transaction control –$dbh->rollback; –$dbh->commit; Disconnect Disconnect –$dbh->disconnect;

13 9 th December 2005Connecting to IDS the Open Source Way13 DBI – Statement Handles Create statement handles Create statement handles –my $xname = $dbh->quote(“%$name%”); –$sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE $xname AND ZipCode IS NULL }); Statements can be executed Statements can be executed –$sth->execute(); Statement handles can be released Statement handles can be released –Implicitly – statement handle goes out of scope –Explicitly – undef $sth;

14 9 th December 2005Connecting to IDS the Open Source Way14 Danger – SQL Injection What happens if the code is written as: What happens if the code is written as: –$sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ‘%$name%’ AND ZipCode IS NULL }); This is a security breach ready to happen This is a security breach ready to happen –SQL injection exploit. What happens if the user enters this name: What happens if the user enters this name: –X%’ OR fname != ‘X’ OR fname = ‘

15 9 th December 2005Connecting to IDS the Open Source Way15 Danger – SQL Injection The query is now: The query is now: –DELETE FROM Customer WHERE Lname LIKE ‘%X%’ OR fname != ‘X’ OR fname = ‘%’ 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 SQL Better to use placeholders (?) in the SQL –$sth = $dbh->prepare(qq{ DELETE FROM Customer WHERE Lname LIKE ? AND ZipCode IS NULL });

16 9 th December 2005Connecting to IDS the Open Source Way16 DBI – Handling SELECT Statement handles are used for SELECT too Statement handles are used for SELECT too –$sth = $dbh->prepare(q% SELECT * FROM Customer WHERE Fname = ? AND Lname = ? ORDER BY Lname, Fname%); –$sth->execute($firstname, $surname); = $sth->fetchall_arrayref; –…process results… print $results[$rownum][$colnum]; print $results[$rownum][$colnum]; –undef $sth;

17 9 th December 2005Connecting to IDS the Open Source Way17 DBI – Handling SELECT Many ways to fetch rows Many ways to fetch rows –$sth->fetchrow_array –$sth->fetchrow_hashref –$sth->fetchrow_arrayref –$sth->fetchall_arrayref All rows All rows Also utility methods Also utility methods –$dbh->selectrow_array First row only First row only –$dbh->selectall_arrayref

18 9 th December 2005Connecting to IDS the Open Source Way18 #! /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 { print “Name: $$row[0] $$row[1], Phone: $$row[2]\n”; } $dbh->disconnect; DBD::Informix – example

19 9 th December 2005Connecting to IDS the Open Source Way19 Tcl/Tk and isqltcl Tcl – Tool Control Language Tcl – Tool Control Language –Invented by John Ousterhout Tk – Tool Kit (GUI) Tk – Tool Kit (GUI) Tcl/Tk – at Tcl/Tk – at –Current version – December isqltcl – Informix SQL access via Tcl. isqltcl – Informix SQL access via Tcl. –Available at –Version 5.0 – released February –Builds into dynamically loadable shared library

20 9 th December 2005Connecting to IDS the Open Source Way20 Tcl/Tk Extensions Tcl/Tk is designed to be easily extended Tcl/Tk is designed to be easily extended Many extensions available for all jobs Many extensions available for all jobs For example For example –Expect Designed to handle scripting of processes Designed to handle scripting of processes Used for automating testing Used for automating testing ftp://expect.nist.gov/ ftp://expect.nist.gov/ ftp://expect.nist.gov/ –And many more...

21 9 th December 2005Connecting to IDS the Open Source Way21 Loading ISQLTCL Load the ISQLTCL extension Load the ISQLTCL extension –load isql.so Adds the command ‘sql’ to Tcl/Tk Adds the command ‘sql’ to Tcl/Tk –tclsh –wish

22 9 th December 2005Connecting to IDS the Open Source Way22 ISQLTCL – Connections Connect to a database Connect to a database –sql connect dbase as conn1 user \ $username password $password Connect to given database Connect to given database –sql disconnect \ [current|default|all|conn1] Close database connection Close database connection –sql setconnection [default|conn1] Sets the specified connection Sets the specified connection

23 9 th December 2005Connecting to IDS the Open Source Way23 ISQLTCL – Statements Executable statements Executable statements –Statements that return no data sql run {delete from sometable sql run {delete from sometable where pkcol = ?} $pkval where pkcol = ?} $pkval –Prepares and executes the statement –Optionally takes a number of arguments for placeholders –Returns zero on success; non-zero on failure

24 9 th December 2005Connecting to IDS the Open Source Way24 ISQLTCL – Cursors SELECT, EXECUTE PROCEDURE SELECT, EXECUTE PROCEDURE set stmt [sql open {select * from set stmt [sql open {select * from sometable}] sometable}] –Does PREPARE, DECLARE, and OPEN –Returns a statement number (id) or a negative error –Optionally takes arguments for placeholders set row [sql fetch $stmt 1] set row [sql fetch $stmt 1] –Collects one row of data –As a Tcl list in the variable ‘row’ –The 1 is optional and means strip trailing blanks –The list is empty if there is no more data

25 9 th December 2005Connecting to IDS the Open Source Way25 ISQLTCL – Cursors sql reopen $stmt ?arg1? ?arg2? sql reopen $stmt ?arg1? ?arg2? –Reopens the statement, with new parameters sql close $stmt sql close $stmt –Indicates you have no further use for the statement –It frees both the cursor and statement!

26 9 th December 2005Connecting to IDS the Open Source Way26 What is PHP? Hypertext Processor Hypertext Processor –Was once ‘Personal Home Page’ Version released October 2005 Version released October 2005 Version released September 2005 Version released September 2005 Version released November 2005 Version released November 2005 An HTML scripting language An HTML scripting language –Server-side –Cross-platform –Embedded in HTML documents –Extensible

27 9 th December 2005Connecting to IDS the Open Source Way27 What is PHP? Built into the Apache Web Server Built into the Apache Web Server –Using DSO (dynamic shared objects) –mod_php Or as a CGI binary Or as a CGI binary –With 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. –See PHP Security Consortium

28 9 th December 2005Connecting to IDS the Open Source Way28 What is PHP? Built-in access to: Built-in access to: – –XML –HTTP (cookies, sessions) And databases: And databases: –ODBC DB2, Adabas-D, Empress, Solid, Velocis DB2, Adabas-D, Empress, Solid, Velocis –mSQL, MySQL, PostgreSQL –Sybase, Oracle –Informix

29 9 th December 2005Connecting to IDS the Open Source Way29 What is PHP? IBM also provides modern PDO drivers IBM also provides modern PDO drivers PDO – PHP Data Objects PDO – PHP Data Objects –PHP analogue of Perl DBI –Article on DeveloperWorks –For DB2 Via PDO_ODBC Via PDO_ODBC –For IDS (beta version 0.2.1)

30 9 th December 2005Connecting to IDS the Open Source Way30 Informative PHP Script PHP Information PHP Information

31 9 th December 2005Connecting to IDS the Open Source Way31 Old Informix Driver Code provided as standard part of PHP. Code provided as standard part of PHP. –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.

32 9 th December 2005Connecting to IDS the Open Source Way32 Old Informix Driver Connection management Connection management –ifx_connect –ifx_pconnect –ifx_close Basic Operations Basic Operations –ifx_prepare –ifx_query –ifx_fetch_row –ifx_do –ifx_free_result

33 9 th December 2005Connecting to IDS the Open Source Way33 Old Informix Driver Status and Error Handling Status and Error Handling –ifx_getsqlca –ifx_error –ifx_errormsg –ifx_affected_rows Attribute Queries Attribute Queries Blob handling Blob handling Utility functions Utility functions –ifx_htmltbl_result

34 9 th December 2005Connecting to IDS the Open Source Way34 New Informix Driver Accessed via PDO functions Accessed via PDO functions –See: – getMessage(). " "; die(); } ?>

35 9 th December 2005Connecting to IDS the Open Source Way35 Python and InformixDB * Version 2.4 – November Version 2.4 – November InformixDB – under active development InformixDB – under active development –Maintainer: Carsten Haese See Carsten’s presentation on CD See Carsten’s presentation on CD –Python DB-API 2.0 compliant –Requires Python 2.2 or better –Needs Informix ClientSDK

36 9 th December 2005Connecting to IDS the Open Source Way36 Python and InformixDB import informixdb conn = informixdb.connect(”test”, ”informix”, ”pw”) cur = conn.cursor() cur.execute(“create table test1(a int, b int)”) 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") 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])

37 9 th December 2005Connecting to IDS the Open Source Way37 Aubit 4GL – Open Source 4GL 99% Informix™ 4GL Compatible 99% Informix™ 4GL Compatible BODR=Business Oriented, Database Related BODR=Business Oriented, Database Related –Task-focussed language Embedded SQL for database access Embedded SQL for database access High productivity, easy to learn High productivity, easy to learn Licensed under GPL/LGPL Licensed under GPL/LGPL Includes 4GL-based Open Source software Includes 4GL-based Open Source software For commercial and non-commercial applications For commercial and non-commercial applications

38 9 th December 2005Connecting to IDS the Open Source Way38 Aubit 4GL – New to 4GL? MAIN MENU "Title for my test menu" COMMAND "Impress Me" "Do something to impress me“ HELP 126 CALL OpenMyWindow() COMMAND "Exit" "Exit this menu" HELP 127 EXIT MENU END MENU END MAIN FUNCTION OpenMyWindow() OPEN WINDOW MyTestWindow AT 2,3 WITH FORM "FormForMyTestWindow" ATTRIBUTE(BORDER, WHITE) END FUNCTION Think about amount of code to achieve same functionality in 3GL!

39 9 th December 2005Connecting to IDS the Open Source Way39 Aubit 4GL – Features Database independent Database independent –ODBC, native, ESQL/C Fully modular (plug-in) architecture Fully modular (plug-in) architecture User interface independent User interface independent –GUI and Curses modes Platform independent Platform independent –(POSIX, UNIX, Windows) Easy to embed 3GL in 4GL Easy to embed 3GL in 4GL –Embedded C code

40 9 th December 2005Connecting to IDS the Open Source Way40 Aubit 4GL – Enhancements Logical Reports Logical Reports ASQL – dbaccess/isql replacement ASQL – dbaccess/isql replacement Flexible key mapping Flexible key mapping Print Screen functions Print Screen functions Fully integrated testing hooks (including key recording and replay for batch jobs) Fully integrated testing hooks (including key recording and replay for batch jobs) Dynamic function calls (like perl ‘::’) Dynamic function calls (like perl ‘::’)

41 9 th December 2005Connecting to IDS the Open Source Way41 Aubit 4GL – Web Sites Web site Web site Bug Tracker Bug Tracker Bulletin board Bulletin board Commercial supporthttp://www.aubit.com Commercial supporthttp://www.aubit.comhttp://www.aubit.com Current version: Current version: – dated

42 9 th December 2005Connecting to IDS the Open Source Way42 SQLCMD * Originally called RDSQL in Originally called RDSQL in –Renamed SQLCMD in Intended as an alternative to ‘isql’. Intended as an alternative to ‘isql’. –Before DB-Access was created. Designed for use in shell scripts. Designed for use in shell scripts. –Exits with non-zero status on error. –Careful use of standard input, output, error. –Output layout independent of selected data. Designed for interactive use. Designed for interactive use.

43 9 th December 2005Connecting to IDS the Open Source Way43 SQSL – Structured Query Scripting Language SQSL is a scripting language SQSL is a scripting language –Created by Marco Greco –Superset of SQL –Features aimed at scripting, reporting, and simple ETL –Lets a DBA perform daily activities as easily as possible

44 9 th December 2005Connecting to IDS the Open Source Way44 SQSL – Structured Query Scripting Language It has a low learning curve: It has a low learning curve: –Language features should be familiar To anyone with experience of SQL, SPL, Informix 4GL or Bourne shell To anyone with experience of SQL, SPL, Informix 4GL or Bourne shell It includes flow-control operations It includes flow-control operations It has a curses-based full-screen mode It has a curses-based full-screen mode –Like DB-Access

45 9 th December 2005Connecting to IDS the Open Source Way45 Ruby Version – September Version – September No known Informix support No known Informix support –Lots of different database support packages. –No unifying concept like DBI or PDO. See also ‘Ruby on Rails’ See also ‘Ruby on Rails’ –http://www.rubyonrails.com/

46 9 th December 2005Connecting to IDS the Open Source Way46 IIUG Software Archive Many useful utilities Many useful utilities Art Kagel’s ‘utils2_ak’ package Art Kagel’s ‘utils2_ak’ package –Generate UPDATE STATISTICS statements –DB-Copy Stored Procedure Libraries Stored Procedure Libraries Example DataBlades Example DataBlades 4GL Code Generators 4GL Code Generators

47 9 th December 2005Connecting to IDS the Open Source Way47

48 9 th December 2005Connecting to IDS the Open Source Way48

49 49 Connecting to IDS The Open Source Way Jonathan Leffler Informix User Forum 2005 Moving Forward With Informix Atlanta, Georgia December 8-9, 2005


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

Similar presentations


Ads by Google