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 :-) 1 1905
In article <aa************ *************@p osting.google.c om>, 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.descript ion]
dict_results = [dict(zip(col_na mes, 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 questions:
1. Is there an example of a simple data-entry application written in
Python using a GUI interface? Something like a simple address book app
with a listbox displaying all addresses with the ability to
add/modify/delete.
|
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
networked with the linux box.
Is it possible for python/linux to read data from MS Access
Database ?
|
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 Avila
QOTW (in the popular vote category): "So far, python has been the easiest
language to learn I've ever come across. I tried learning perl, and it
was a disaster.... Too convoluted. Python is a breath of fresh air.
Also, the docs and...
|
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 MySQLdb for MySQL and
cx_oracle for Oracle, but 2 different APIs in the same app is kind of
painful.
So I have unixODBC that gives me ODBC on Linux. The best ODBC access
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |