Ah - my apologies; I think we're using different MySQL libraries. I'm
not familiar with the MySQL-provided lib you're using.
I copy/pasted form an example using the popular MySQLdb module - this
may be acceptable for you if you're not obliged to use the
'MySQL-Python-connector' module. I'm not familar with that connector's
API, so I'm unable to help you with it.
But - using MySQLdb:
import MySQLdb as mdb
con=mdb.connect('172.16.48.9', showtime', 's1000@ma25db', artists_core')
c = con.cursor(mdb.cursors.DictCursor)
c.execute("""SELECT Artist_Name, Artist_ID, Login_ID FROM
artists_core.employee limit 1,10""")
rows = c.fetchall()
for row in rows:
print "%s %s" % (row["Artist_Name"], row["Artist_ID"])
Best wishes
Donal
On 24/08/12 19:25, PBLN RAO wrote:
It gives me error
>>>
conn=mysql.connector.Connect(host='172.16.48.9',user='showtime',password='s1000@ma25db',database='artists_core')
>>> q="SELECT Artist_Name,Artist_ID,Login_ID FROM employee limit 1,10"
>>> c=conn.cursor(mdb.cursors.DictCursor)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'mdb' is not defined
On Friday, August 24, 2012 12:21:54 PM UTC+5:30, Cuchullain wrote:
Try the dictionary cursor - you'd need to modify a line in your
code from this:
c=conn.cursor()
to this:
c=conn.cursor(mdb.cursors.DictCursor)
Your result should then be returned as a dictionary keyed on
column name:
for row in rows:
print "%s %s" % (row["Artist_Name"], row["Artist_ID"])
etc.
Donal
On 24/08/12 18:14, PBLN RAO wrote:
in my post below "c" is a variable which is used to execute the
SQL commands..
we need to send it result in cursor to a variable.
in sqldb it is possible to use below code
x=c.fetchall() - this will save the retrived rows to variable x,
but this method is giving be error in mysql-python connector.
On Friday, August 24, 2012 11:31:09 AM UTC+5:30, Panupat wrote:
Can you do print variable[0][1] ?
On Fri, Aug 24, 2012 at 12:13 PM, PBLN RAO
<[email protected]> wrote:
Hi All,
i am developing a tool which manages the maya files
details in database (for instance i am using MySQL as
database).
the data table looks like the attached image.
I am using MySQL-Python-connector
<http://dev.mysql.com/downloads/connector/python/>from
MySQL Site.
but when i connect and retrieve data i am getting data in
tupils. Is there a way that i can get this data in a
table format and can be retrieved by the column (field)
name/index. as we have in datasets .NET application.
Result from python:
>>> import mysql.connector
>>>
conn=mysql.connector.Connect(host='172.16.48.9',user='showtime',password='s1000@ma25db',database='artists_core')
>>> c=conn.cursor()
>>> c.execute("""SELECT Artist_Name, Artist_ID, Login_ID
FROM artists_core.employee limit 1,10""")
>>> for row in c:
... print row
...
(u'SRINIVASAN G', u'1023', u'srinivasang.1023')
(u'ACSARAVANAN', u'1027', u'saravananac.1027')
(u'REX ANTHONY R', u'1031', u'rex.1031')
(u'SUNIL S', u'1058', u'sunils.1058')
(u'C.SRIDHAR REDDY', u'1071', u'csreddy.1071')
(u'ARUN PRAKASH', u'1308', u'arunprakash.1308')
(u'WINSON A.C.', u'1353', u'winson.1353')
(u'BHASKAR D', u'1422', u'bhaskard.1422')
(u'RAMA KRISHNA VARMA M.S', u'1458', u'sivam.1458')
(u'POORNANANDAM A', u'1510', u'poornanandam.1510')
i need an alternate where i can access the data above
directly as variable(row,col)
so if i print variable(1,0)
it should give me result as 'ACSARAVANAN'
In .NET this can be achieved with datasets. can any one
tell me how can i get this in python.
--
view archives:
http://groups.google.com/group/python_inside_maya
<http://groups.google.com/group/python_inside_maya>
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe
<http://groups.google.com/group/python_inside_maya/subscribe>
--
view archives: http://groups.google.com/group/python_inside_maya
<http://groups.google.com/group/python_inside_maya>
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe
<http://groups.google.com/group/python_inside_maya/subscribe>
--
Donal McMullan
Production Engineer
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe
--
Donal McMullan
Production Engineer
--
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe