. "d842e0e2d131e3d2d25f4f75d730c78a" . . "---+iODBC Python HOWTO \r\n\r\n%TOC%\r\n\r\n---++Disclaimer\r\n\r\nThe following is a HOWTO document for installing Python with iODBC on Linux\r\nor Unix. Feel free to criticize, suggest modifications, or ask further\r\nquestions. It is currently maintained by Tim Haynes of Openlink Software\r\n(iodbc@openlinksw.com)\r\n\r\nPrerequisites include basic Unix familiarity, such as creating directories\r\nand users, using an editor, etc.\r\n\r\nThis HOWTO is intended to assist in connecting python to back-end databases\r\nvia ODBC in a development environment and should not take the place of\r\nthorough testing before deployment on a production system.\r\n\r\n---++ ODBC Overview\r\n\r\nODBC (Open Database Connectivity) is an operating system- and database-\r\nindependent communication API for database connectivity. It enables ODBC\r\ncompliant client applications to connect transparently to back-end\r\ndatabases via ODBC function calls which are implemented by ODBC Drivers for\r\ntarget back-end databases.\r\n\r\nODBC provides your applications with database-independence;\r\nconsequentially, you no longer have to incur the development and\r\nmaintenance cost of inextricably binding your application to backend\r\ndatabase engines via their proprietary data-access (aka native) APIs.\r\n\r\nODBC connections involve an ODBC-compliant Application or Data Access\r\nLayer, ODBC Driver Manager, ODBC Driver, and back-end Database. The ODBC\r\nDriver Manager for Microsoft Windows platforms is administered via the ODBC\r\nAdministrator Control Panel applet at setup and configuration time. The\r\nDriver Manager registers a set of ODBC driver connection parameters called\r\na Data Source Name (DSN), and maintains (in persistent form) a relationship\r\nbetween the DSN and an underlying ODBC Driver that will honor data access\r\nrequest via that DSN.\r\n\r\nAt runtime an application looks to the driver manager for a DSN, and then\r\npasses the connection parameters specified in the DSN to the appropriate\r\ndriver, which makes the actual database connection. Under non-Windows\r\nplatforms you may need to install a Driver Manager if this isn't delivered\r\nas an integral part of your operating environment. Platform independent\r\nODBC (aka iODBC) is an Open Source ODBC project (dual license LGPL /\r\nBSD)for non Windows platforms maintained by OpenLink Software that consists\r\nof an ODBC SDK (libraries and header files) and ODBC Runtime components\r\n(Administrator and Driver Manager).\r\n\r\n\r\n---++ Preface\r\n\r\nYou will also need an ODBC Driver and Database to complete the architecture.\r\n\r\nIf you need ODBC drivers to connect to a third-party database on the same\r\nor another machine, OpenLink ODBC Drivers are available, and may be\r\ndownloaded from http://www.openlinksw.com\r\n\r\nThe Virtuoso database may also be downloaded from\r\nhttp://virtuoso.openlinksw.com/\r\n\r\nBoth sets of ODBC Drivers are available on a free 30 day evaluation basis.\r\n\r\nSupport for setting up the OpenLink Drivers may be obtained at\r\nhttp://support.openlinksw.com/\r\n\r\n\r\n---++ Installing Python\r\n\r\nIf you already have Python installed and running, you probably do not need\r\nto rebuild it. Otherwise, you can compile it from source if you wish, thus:\r\n\r\nFirst, download the latest source distribution from http://www.python.org/\r\n- currently this is version 2.2.3.\r\n\r\nUnpack it into a build directory with the command\r\n\r\n\r\ngzip -cd < Python-2.2.3.tgz | tar xvpf -\r\n\r\n\r\nEnter the build directory, and run configure, specifying any optional\r\nconfigurations as desired:\r\n\r\n\r\n\r\ncd Python-2.2.3/\r\nzsh, purple 2:50PM Python-2.2.3/ % ./configure --help\r\nUsage: configure [options] [host]\r\nOptions: [defaults in brackets after descriptions]\r\nConfiguration:\r\n--cache-file=FILE cache test results in FILE\r\n[snip]\r\nDirectory and file names:\r\n--prefix=PREFIX install architecture-independent files in PREFIX\r\n[/usr/local]\r\n[snip]\r\n--with-libs='lib1 ...' link against additional libs\r\n--with-signal-module disable/enable signal module\r\n--with-dec-threads use DEC Alpha/OSF1 thread-safe libraries\r\n--with(out)-threads[=DIRECTORY] disable/enable thread support\r\n[snip]\r\nzsh, purple 2:50PM Python-2.2.3/ % ./configure --prefix=/usr/local/stow/python-2.2.3\r\ncreating cache ./config.cache\r\nchecking MACHDEP... linux2\r\nchecking for --without-gcc... no\r\nchecking for --with-cxx=<compiler>... no\r\nchecking for c++... g++\r\nchecking whether the C++ compiler (g++ ) works... yes\r\nchecking whether the C++ compiler (g++ ) is a cross-compiler... no\r\n[snip]\r\ncreating Makefile.pre\r\ncreating Modules/Setup.config\r\ncreating pyconfig.h\r\ncreating Setup\r\ncreating Setup.local\r\ncreating Makefile\r\nzsh, purple 2:52PM Python-2.2.3/ % make\r\ngcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o Modules/python.o Modules/python.c\r\ngcc -c -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DHAVE_CONFIG_H -o Parser/acceler.o Parser/acceler.c\r\nrunning build_scripts\r\ncreating build/scripts-2.2\r\ncopying and adjusting /home/tim/public_html/docs/python-HOWTO/Python-2.2.3/Tools/scripts/pydoc -> build/scripts-2.2\r\nzsh, purple 2:59PM Python-2.2.3/ % su\r\nbash-2.05b# make install\r\n[snip]\r\nCreating directory /usr/local/stow/python-2.2.3/man\r\nCreating directory /usr/local/stow/python-2.2.3/man/man1\r\n/bin/install -c -m 644 ./Misc/python.man /usr/local/stow/python-2.2.3/man/man1/python.1\r\n\r\n\r\n---++ Installing iODBC\r\n\r\nIf you do not already have iODBC installed, either install an RPM from [[http://www.iodbc.org/][iODBC.org]], or install from source:\r\n\r\n\r\n---+++ Compiling iODBC from source\r\n\r\nRequirements: C-compiler; optionally gtk+-1.2 (required if building from CVS).\r\n\r\nAs before, unpack the iODBC sources, enter the build directory, configure, make and make install:\r\n\r\n\r\n\r\nzsh, purple 4:13PM C/ % tar xvpfz libiodbc-3.51.1.tar.gz\r\nlibiodbc-3.51.1/\r\nlibiodbc-3.51.1/admin/\r\nlibiodbc-3.51.1/admin/Makefile.am\r\nlibiodbc-3.51.1/admin/Makefile.in\r\nlibiodbc-3.51.1/admin/acinclude.m4\r\n[snip]\r\nlibiodbc-3.51.1/samples/Makefile.in\r\nlibiodbc-3.51.1/samples/iodbctest.c\r\nzsh, purple 4:14PM C/ % cd libiodbc-3.51.1\r\nzsh, purple 4:14PM libiodbc-3.51.1/ % ./configure --prefix=/usr/local/stow/iodbc-3.51.1\r\nchecking for a BSD-compatible install... /bin/install -c\r\nchecking whether build environment is sane... yes\r\nchecking for gawk... gawk\r\n[snip]\r\nconfig.status: executing depfiles commands\r\nconfig.status: executing default commands\r\nzsh, purple 4:15PM libiodbc-3.51.1/ % make\r\nMaking all in admin\r\nmake[1]: Entering directory `/home/tim/C/libiodbc-3.51.1/admin'\r\n[snip]\r\nmake[1]: Leaving directory `/home/tim/C/libiodbc-3.51.1'\r\nzsh, purple 4:15PM libiodbc-3.51.1/ % su root -c 'make install'\r\n\r\n\r\nIt's advisable to install into /usr/local, or stow your installation into\r\n/usr/local, as that is searched by most other applications trying to locate\r\niODBC.\r\n\r\n\r\n---++ Testing ODBC\r\n\r\nNow is a good time to configure iODBC, by adding a DSN - create a file ~/.odbc.ini, edit it to look something like this:\r\n\r\n\r\n\r\n[ODBC Data Sources]\r\nPostgreSQL native localhost = PostgreSQL native driver\r\nLocal Virtuoso Demo = localhost virtuoso (demo instance)\r\nLocal Virtuoso = localhost virtuoso\r\n\r\n[Local Virtuoso Demo]\r\nDescription = Virtuoso 3.1\r\nDriver = /home/tim/virtuoso/lib/virtodbc31.so\r\nAddress = localhost:1112\r\nUserName = dba\r\nUser = dba\r\n\r\n[Local Virtuoso]\r\nDescription = Virtuoso 3.1\r\nDriver = /home/tim/virtuoso/lib/virtodbc31.so\r\nAddress = localhost:1111\r\nUserName = dba\r\nUser = dba\r\n\r\n[PostgreSQL native localhost]\r\nDriver = /usr/lib/postgresql/lib/libodbcpsql.so\r\nHost = localhost\r\nServer = localhost\r\nServerName = localhost\r\nDatabase = tim\r\nUserName = tim\r\nUID = tim\r\nPort = 5432\r\n\r\n\r\nIt is advisable to export the environment variable ODBCINI to point to this\r\nfile, too - depending on your shell, either:\r\n\r\n\r\necho 'export ODBCINI=$HOME/.odbc.ini' >> .bashrc\r\n\r\nor\r\n\r\n\r\necho 'setenv ODBCINI $HOME/.odbc.ini' >> .tcshrc\r\n\r\n\r\nas appropriate.\r\n\r\nYou can now make a test connection with the _iodbctest_ utility, thus:\r\n\r\n\r\n\r\nzsh, purple 4:54PM libiodbc-3.51.1/ % which iodbctest\r\n/usr/local/bin//iodbctest\r\nzsh, purple 4:54PM libiodbc-3.51.1/ % iodbctest \r\niODBC Demonstration program\r\nThis program shows an interactive SQL processor\r\nDriver Manager: 03.51.0001.0908\r\n\r\nEnter ODBC connect string (? shows list): ?\r\n\r\nDSN | Description \r\n---------------------------------------------------------------\r\nLocal Virtuoso | localhost virtuoso \r\nLocal Virtuoso Demo | localhost virtuoso (demo instance)\r\nMySQL | MySQL native driver \r\nPostgreSQL native localhost | PostgreSQL native driver \r\nPostgreSQL OpenLink localhost | PostgreSQL over OpenLink multi-tier\r\nVirtuoso30 | OpenLink Virtuoso 3.0 \r\n\r\nEnter ODBC connect string (? shows list): DSN=Local Virtuoso Demo;UID=dba;PWD=cens0red\r\nDriver: 03.50.2505 OpenLink Virtuoso ODBC Driver\r\n\r\nSQL>\r\n\r\n\r\nIf you see the SQL> prompt there, then all has gone well.\r\n\r\n\r\n---++ Building Egenix' mxODBC module\r\n\r\nThe last infrastructure hurdle to overcome is the building of Egenix's\r\nmxODBC module; download the sources from\r\nhttp://www.egenix.com/files/python/mxODBC.html, and run the following:\r\n\r\n\r\n\r\nzsh, purple 4:21PM egenix-mx-commercial-2.0.6/ % python setup.py install\r\n\r\n\r\nThis requires root privileges, and will install in your python site-packages directory, thus:\r\n\r\n\r\nzsh, purple 4:24PM tim/ % ls /usr/lib/python2.2/site-packages/mx/ODBC \r\nCOPYRIGHT LazyModule.py Misc/ ODBC.pyo __init__.pyc unixODBC/\r\nDoc/ LazyModule.pyc ODBC.py README __init__.pyo\r\nLICENSE LazyModule.pyo ODBC.pyc __init__.py iODBC/\r\n\r\n\r\n\r\n\r\n---++ Sample script to use the module\r\n\r\nFinally, a small script to link it all together. You can use this to test\r\nsimple functionality of iODBC, mxODBC and Python.\r\n\r\n\r\n#!/usr/bin/python\r\n\r\nimport mx.ODBC.iODBC\r\n\r\ndsn=\"Local Virtuoso Demo\"\r\n\r\nconn=mx.ODBC.iODBC.Connect (dsn, \"dba\", \"cens0red\")\r\n\r\nprint \"Content-Type: text/plain\r\n\r\n\"\r\nprint \"Database Type: \" + conn.getinfo (17)[1] + \"\r\n\"\r\n\r\ncurshandle=conn.cursor()\r\n\r\nprint \"Top 10 in Shippers table:\"\r\ncurshandle.execute (\"select top 10 * from Demo.demo.Shippers\")\r\nfor i in curshandle.fetchall():\r\nprint i\r\n\r\n#print curshandle.fetchall()\r\n\r\nprint \"\r\nCreating and populating timtest table:\"\r\n\r\ntry:\r\ncurshandle.execute (\"drop table timtest\") \r\nexcept: \r\npass\r\n\r\ncurshandle.execute (\"create table timtest (id integer, str varchar (255))\")\r\ncurshandle.execute (\"insert into timtest values (99, 'testing')\")\r\ncurshandle.execute (\"select * from timtest\")\r\n\r\nfor i in curshandle.fetchall():\r\nprint i\r\n\r\n\r\nOn running it, you should see the following output:\r\n\r\n\r\n\r\nzsh, purple 11:22AM python/ % ./dbi-test.py\r\nDatabase Type: OpenLink Virtuoso\r\n\r\nTop 10 in Shippers table:\r\n(1, 'Speedy Express', '(503) 555-9831')\r\n(2, 'United Package', '(503) 555-3199')\r\n(3, 'Federal Shipping', '(503) 555-9931')\r\n\r\nCreating and populating timtest table:\r\n(99, 'testing')\r\n\r\n\r\n\r\n---++ References\r\n\r\n * [[http://www.iodbc.org][iODBC]] \r\n * History of [[ODBCOnUnix][ODBC on Unix]] \r\n * [[http://www.openlinksw.com/][OpenLink Software]] - [[http://www.openlinksw.com/support/suppindx.htm][Support]] , [[http://www.openlinksw.com/support/teclinks.htm][links]] and [[http://www.openlinksw.com/info/docs/odbcwhp/tableof.htm][white-papers]] \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" . . . "IODBCPythonHOWTO" . . . . . . . . . . . . . . . "2016-09-14T12:28:33Z" . . "2016-09-14T12:28:33.787095"^^ . . "IODBCPythonHOWTO" . "2016-09-14T12:28:33Z" . "2016-09-14T12:28:33.787095"^^ . . . "IODBCPythonHOWTO" . . .