473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Python database access questions

Hi All,

I want to write an application that will talk to a RDBMS.

The application needs to be platform neutral from both an operating
system and database backend point of view.

I have decided to create a prototype in Python, the RDBMS will be
PostgreSQL running on a Linux box.

I am from a Microsoft background and I now take for granted components
such as ADO (Activex Data Objects) that make database access simple
and portable.

I have been looking at the Python DB-API modules and this seems to
make it relatively simple to access a RDBMS but it seems to be at a
lower level than say ADO and I feel this may potentially cause me more
work to prevent potential problems that I may encounter.

Let me explain...

ADO allows you to reference field objects when manipulating records
retrieved from the database, this makes your code less likely to be
broken by reordering of the columns of say a "select * from table"
query, it also allows you to get information on the datatypes of the
fields and so on.

ADO also provides a safer way to pass information when using parameter
queries or stored procedures, you have a parameter object that you can
assign parameter values to and any problems such as "' " /" within the
string are then handled by the objects to prevent breakage of the sql
statement passed to the RDBMS.

ADO allows you to create a "recordset" that allwos you to iterate
through the records and columns and also then assign values to the
field objects within and update these changes with method calls, it
seems all this type of stuff needs to be manually done with DB-API
i.e. you would have to create all the DML statements for this.

What are your views on this, it may just be me being naive as I only
know of the Microsoft way of doing things ;-), you may find
technologies such as ADO cumbersome and/or restrictive ?

Any views on this matter would be greatly appreciated :-)
Jul 18 '05 #1
1 1884
In article <aa*************************@posting.google.com> , Limey wrote:
ADO allows you to reference field objects when manipulating records
retrieved from the database, this makes your code less likely to be
broken by reordering of the columns of say a "select * from table"
query, it also allows you to get information on the datatypes of the
fields and so on.
Some of the dbapi compliant modules (e.g. pyPgSQL) return row objects that
can be queried by position or field name. Some (psycopg) provide dictfetch*
methods that return rows as dictionaries instead of tuples. And converting
the rows to dictionaries is trivial anyway:

cursor.execute(blah)
col_names = [tup[0] for tup in cursor.description]
dict_results = [dict(zip(col_names, row)) for row in cursor.fetchall()]
ADO also provides a safer way to pass information when using parameter
queries or stored procedures, you have a parameter object that you can
assign parameter values to and any problems such as "' " /" within the
string are then handled by the objects to prevent breakage of the sql
statement passed to the RDBMS.
All the postgres dbapi modules can interpolate input using pyformat:

data = {'name' : 'Dobbs, Bob', 'phone_no' : '555-1212'}
cursor.execute("""INSERT INTO contact (name, phone_no)
VALUES (%(name)s, %(phone_no)s)""", data)

(You can have more keys in your dict than in the query, they will be ignored,
but not too few, obviously.)
ADO allows you to create a "recordset" that allwos you to iterate
through the records and columns and also then assign values to the
field objects within and update these changes with method calls, it
seems all this type of stuff needs to be manually done with DB-API
i.e. you would have to create all the DML statements for this.


There are various modules that sit on top of the DBAPI that add similar
features. I wrote my own. Python string handling makes it fairly easy.

You might want to investigate SQLObject or other object-relational mappers:

http://www.thinkware.se/cgi-bin/thin...ppersForPython

Dave Cook
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Ubaidullah Nubar | last post by:
Hi, How well is Python suited for developing database based applications? I am new to Python so please bear with me if some of the questions are too simple. I specifically have the following...
10
by: David ROBERT | last post by:
Hello, I need to read data from a MS Access database. The program (reader) is installed on a linux box and is written in python langage. The database is MS Access 2002 installed on a Win XP box...
0
by: Emile van Sebille | last post by:
QOTW (in the OS agnostic category): "There is a (very popular) Python package out there which exposes the win32 api. I'm not sure what it's called. (win32api? pythonwin? win32all?)" -- Francis...
4
by: hot.favorite | last post by:
Hi, I'm fairly new to Python so please pardon any dumbness on my part. I plan to write an app in Python that will run on Linux and would need to connect to Oracle and MySQL. I could use...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.