John of York
John of York

Reputation: 93

pyodbc "commit" command not recognised in Python 3.2

Has anybody got pyodbc installed with Python 3.2? I have, and all is well except that the interpreter doesn't recognise "commit()". Anyone else got the same problem? Anyone know if I'm doing something wrong? Thanks, John R

Upvotes: 0

Views: 893

Answers (2)

Thomas
Thomas

Reputation: 1208

here is an example of my code using commit() :

   cnxn = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=F:\\computing\\Payroll v2 2\\\employees.accdb')
   cursor = cnxn.cursor()
   cursor.execute("insert into Medication(ID, Doctor, NameOfMedication, Dosage, DateStart, DateEnd, Notes, LastUpdated) values (?,?,?,?,?,?,?,?)",self.ui.residentComboBox.currentText().split()[0], self.ui.doctorLineEdit.text(), self.ui.nameOfMedicationLineEdit.text(), self.ui.dosageLineEdit.text(), self.ui.dateStartDateEdit.text(), self.ui.dateEndDateEdit.text(), self.ui.notesTextEdit.document().toPlainText(), self.ui.lastUpdatedDateTimeEdit.dateTime().toString("dd/MM/yyyy, hh:mm:ss")) 
   cursor.execute("update Medication set MedEndMonth=? where ((ID=?)) ",month,resID)                
   cnxn.commit()
   self.close()

Upvotes: 0

John of York
John of York

Reputation: 93

I've found a way round it. Still couldn't get commit() to work but in the pyodbc.connect() function, if "autocommit=True" is included, all the inserts get committed automatically and you don't need to use the commit() function. e.g.

conx = pyodbc.connect("""Driver={Microsoft Access Driver (*.mdb, *.accdb)};
                         DBQ=C:\Documents and Settings\Owner\My Documents\
                         Database2.accdb;""", autocommit = True)

Upvotes: 1

Related Questions