cursor.execute("INSERT INTO rjhtest2 (name,age) SELECT Name ,age from rjhtest3 ");
connection.commit
cursor.close
connection.close
Data is not getting saved.This code works fine when i use it with SQLyog(a mySQL GUI)
I found that even when I use a normal insert statment ( ie with out Select statemnt)it is not getting saved
Is this a bug or is it that i am not using the correct libraries
I also want to know what is the correct code if i am using tables from two different databases(since two different cursor will be used )
Venkatesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Real thanks for pointing it out.I was using all functions like this eg cursor.fetchall etc .Though there wer no compiling errors data was not getting saved
You saved me a lot of time by pointing it out.Thanks once again
Venkatesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found the answer from other threads
If i do connection.autocommit after
connection = MySQLdb.connect(host='localhost', db='CNS' ,user= 'root',passwd='')
The data is getting updated correctly
Venkatesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using Python 2.41 with mysql 4.1 & MySQL-python.exe-.2.0.win32-py2.4 versions
I am having the following code & am using Commit also
import MySQLdb
connection = MySQLdb.connect(host='localhost', db='CNS' ,user= 'root',passwd='')
cursor = connection.cursor()
cursor.execute("INSERT INTO rjhtest2 (name,age) SELECT Name ,age from rjhtest3 ");
connection.commit
cursor.close
connection.close
Data is not getting saved.This code works fine when i use it with SQLyog(a mySQL GUI)
I found that even when I use a normal insert statment ( ie with out Select statemnt)it is not getting saved
Is this a bug or is it that i am not using the correct libraries
I also want to know what is the correct code if i am using tables from two different databases(since two different cursor will be used )
Venkatesh
Real thanks for pointing it out.I was using all functions like this eg cursor.fetchall etc .Though there wer no compiling errors data was not getting saved
You saved me a lot of time by pointing it out.Thanks once again
Venkatesh
Right. Leaving the parenthesis off is not a syntax error; it is merely a reference. For example:
row = cursor.fetchone
doesn't actually fetch anything. It simply makes row be a reference to the fetchone method on cursor. You could subsequently do this:
data = row()
which is equilvalent to:
data = cursor.fetchone()
Simply doing:
cursor.fetchone
gets a reference to the bound fetchone method, which immediately goes away, since it doesn't get assigned to anything.
The Pythonism that applies here (I think) is: Explicit is better than implicit.
I found the answer from other threads
If i do connection.autocommit after
connection = MySQLdb.connect(host='localhost', db='CNS' ,user= 'root',passwd='')
The data is getting updated correctly
Venkatesh
Oh, you've managed to screw it up in a new and interesting way I haven't seen:
connection.commit
is only a reference to the commit method; it does not cause it to be called. You need:
connection.commit()
cursor.close()
connection.close()
This is not perl, after all.