Ozzie.eu

Love to code, although it bugs me.

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Troubleshooting pymssql installation on Ubuntu


Installing pymssql on Ubuntu 13.10 was not an easy task. Trying to install directly from the .egg file gave an UCS2-UCS4 incompatibility error. So I installed it from source.

After installing the FreeTDS packages, the process was as follows:

  1. Get source from https://github.com/pymssql/pymssql
  2. Error: _mssql.c:8:22: fatal error: pyconfig.h: No such file or directory
  3. Install Python development libraries: sudo apt-get install python-dev
  4. Error: _mssql.c:314:22: fatal error: sqlfront.h: No such file or directory
  5. Install freeTDS development libraries: sudo apt-get install freetds-dev
  6. Install pymssql from the unzipped source directory: sudo python setup.py install
Success!

Free eBooks: Python, JavaScript and UI Design

6773415631_7cab96b8d9_m
Working on the application development scene, it’s hard to keep up with everything new. Every bit of help counts. Great resources are the eBooks you can find, for free, online on the Web. The books you can find in PDF format are great because you can take them with you anywhere. The ones that are available to view online are also great because you get any updates made on the subject. On this post I leave everyone a small set of links where you can find eBook compilations.
The first one comes from Speck boy Design Magazine and it’s mostly about User Interface design. For instance, the Mobile Web Design Best Practices by Mobify “is a handy mobile web design guide with over 50 tips that will help you build amazing mobile websites”. You can visit the Specky boy eBook compilation here: http://speckyboy.com/2013/06/10/free-ebooks-for-designers-and-developers/
The next eBook compilation is from Revolunet. It’s all about the Python programming language. You have the classic “Dive into Python” and a whole bunch of other interesting books. You can find them all at this Web page: http://pythonbooks.revolunet.com/
Finally, this list wouldn’t be complete without the emerging trend on multi-platform application development: javaScript. Here you have subjects for all tastes: Node.js, MongoDB, Windows 8, and so on. Get them all on this page: http://jsbooks.revolunet.com/
Happy readings!
Photo Credit: Mark J P via Compfight cc

Python, Oracle and LOB objects

The Python programming language is my preferred tool to develop quick and (sometimes) dirty scripts to perform single shot data processing tasks.
Recently, one of these tasks  involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
  1. Fetch all relevant primary keys from the table;
  2. Fetch the LOB column one-by-one using the PK list from the previous step.
To whom it may interest, I also make available the ode snippet from the LOB reader function:
def executaQueryLOB(txtQuery):
    import cx_Oracle
 
    orcl = cx_Oracle.connect('yourConnectioString')
    curs = orcl.cursor()
    curs.execute(txtQuery)
    result=curs.fetchall()
    strLOB=result[0][0].read()
 
    orcl.close()
    
    return strLOB
HTH.