Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > MySQLdb

Reply
Thread Tools

MySQLdb

 
 
pavloutefkros@gmail.com
Guest
Posts: n/a
 
      01-29-2008
hello,
i have problem manipulating mySQL data. When i add values in a Table,
i can recieve them instantly but when i check the table from another
script, the new values dont exist.

i'm not experienced in sql dbses so the problem might be something
outside python.

example (i do this to add values, and then i check and values have
been added):

################################################## ##################
import MySQLdb
conn = MySQLdb.connect (host = 'localhost',
user = 'root',
passwd = 'MYPASHERE',
db = 'test')
cursor = conn.cursor ()

cursor.execute ("""
INSERT INTO testsignin (user, pass, secretcode)
VALUES
('dkiauser', 'dkiapass', 'dkiacode'),
('gmtuser', 'gmtpass', 'gmtcode')
""")

print "Number of rows inserted: %d" % cursor.rowcount

cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
row = cursor.fetchone()
print row
################################################## ##################

but then when i try to get them from another script with this:

################################################## ##################
import MySQLdb
conn = MySQLdb.connect (host = 'localhost',
user = 'root',
passwd = 'MYPASHERE',
db = 'test')
cursor = conn.cursor ()

cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
row = cursor.fetchone()
print row
################################################## ##################

i get a None
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-29-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> hello,
> i have problem manipulating mySQL data. When i add values in a Table,
> i can recieve them instantly but when i check the table from another
> script, the new values dont exist.
>
> i'm not experienced in sql dbses so the problem might be something
> outside python.
>
> example (i do this to add values, and then i check and values have
> been added):
>
> ################################################## ##################
> import MySQLdb
> conn = MySQLdb.connect (host = 'localhost',
> user = 'root',
> passwd = 'MYPASHERE',
> db = 'test')
> cursor = conn.cursor ()
>
> cursor.execute ("""
> INSERT INTO testsignin (user, pass, secretcode)
> VALUES
> ('dkiauser', 'dkiapass', 'dkiacode'),
> ('gmtuser', 'gmtpass', 'gmtcode')
> """)
>
> print "Number of rows inserted: %d" % cursor.rowcount
>
> cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
> row = cursor.fetchone()
> print row
> ################################################## ##################
>
> but then when i try to get them from another script with this:
>
> ################################################## ##################
> import MySQLdb
> conn = MySQLdb.connect (host = 'localhost',
> user = 'root',
> passwd = 'MYPASHERE',
> db = 'test')
> cursor = conn.cursor ()
>
> cursor.execute ('SELECT * FROM testsignin WHERE user="gmtuser"')
> row = cursor.fetchone()
> print row
> ################################################## ##################
>
> i get a None


You need to commit your changes, using

conn.commit()

after doing them.

Diez
 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      01-29-2008
> i have problem manipulating mySQL data. When i add values in a Table,
> i can recieve them instantly but when i check the table from another
> script, the new values dont exist.


Depending on your transaction settings (both on your mysql
connection object in code, and the engine used for the table(s)
in mysql's DB), you may have to commit your transaction to make
it visible in other connections. This helps prevent partial
transactions from being visible when they're in inconsistent states.

-tkc


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using like and % in MySQLdb Dave Harrison Python 0 08-07-2003 04:43 AM
MySQLdb and egenix mxDateTime dumps core Dave Harrison Python 0 08-05-2003 10:49 PM
Python2.3 and MySQLdb on Windows Mike M Python 1 07-31-2003 08:52 AM
Re: Problem with MySQLdb on Mac OS X... Skip Montanaro Python 5 07-16-2003 04:46 AM
can't import MySQldb on OS X Alan Little Python 0 06-25-2003 09:46 PM



Advertisments