[Zope] quick question - database connections in python methods & return types?
Lee
lee.reilly@ntlworld.com
Thu, 22 Feb 2001 00:25:42 +0000
Hi there,
I have a quick question that I need answered concerning the return types
of SQL queries executed in Python methods.
I am querying/updating a database using Python methods as follows:
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# make a database connection string
try:
db_conn = self.MySQL_database_connection()
except Exception:
return "A connection to the database could not be made. <a
href='./'>
Recover</a>."
try:
SQL = "some SELECT query"
result=db_conn.query(SQL)
except Exception:
return "The class could not be created.<a href='./'> Recover</a>."
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
When this is executed and I "return result[1]" it outputs the data in a
format like:
[(1, 16, 9, 1)]
* return result[0] gives me:
[{'name': 'PRACTICALS', 'type': 's', 'null': None, 'width': None},
{'name': 'TUTORIALS', 'type': 's', 'null': None, 'width': None},
{'name': 'ASSIGNMENTS', 'type': 's', 'null': None, 'width': None},
{'name': 'BONUS', 'type': 's', 'null': None, 'width': None}]
- the exact details aren't neccessary here I think. At first I had
problems trying to use this data i.e. parse it an store it in an array,
list, etc. but I overcome that by by first converting "result" to a
string using `result[1]`.
I was just wondering how to classify the original return type? It is
*not* a list, tuple, array or combination of either so what is it?
I'm writing a report on my project you see and I can't say that my
method returns an *cough* *cough* value ;-)
Thanks very much in advance if you can help.
Cheers,
Lee