summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py
diff options
context:
space:
mode:
Diffstat (limited to 'kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py')
-rw-r--r--kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py56
1 files changed, 28 insertions, 28 deletions
diff --git a/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py b/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py
index 40d1a317..76e544a6 100644
--- a/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py
+++ b/kexi/plugins/scripting/scripts/copycenter/CopyCenterPluginQtSQL.py
@@ -28,9 +28,9 @@ class CopyCenterPlugin:
def _init(self,copierer):
self.copierer = copierer
if not self.widget.connectClicked():
- raise "Failed to connect with database."
+ raise Exception("Failed to connect with database.")
if self.database == None or not self.database.isOpen():
- raise "Database is not initialized or not opened."
+ raise Exception("Database is not initialized or not opened.")
self.copierer.appendProgressMessage("Connected: %s %s@%s:%i %s" %
(str(self.database.driverName()),str(self.database.userName()),str(self.database.hostName()),self.database.port(),str(self.database.databaseName())) )
self.isfinished = False
@@ -66,25 +66,25 @@ class CopyCenterPlugin:
self.cursor = qtsql.TQSqlCursor(tablename,True,self.database)
self.cursor.setFilter(wherestatement)
if not self.cursor.select():
- raise "Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) )
+ raise Exception("Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) ))
self.fieldlist = []
for fieldname in str(self.widget.fieldedit.text()).split(","):
fn = fieldname.strip()
if fn != "":
field = self.cursor.field(fn)
if not field:
- raise "There exists no such field \"%s\" in the table \"%s\"." % (fn,tablename)
+ raise Exception("There exists no such field \"%s\" in the table \"%s\"." % (fn,tablename))
self.fieldlist.append(str(field.name()))
if len(self.fieldlist) < 1:
- raise "No fields for table \"%s\" defined." % tablename
+ raise Exception("No fields for table \"%s\" defined." % tablename)
copierer.appendProgressMessage("SQL: %s" % str(self.cursor.executedQuery()))
def read(self):
- if not self.cursor.next():
+ if not next(self.cursor):
return None
record = []
for fieldname in self.fieldlist:
- record.append( unicode(self.cursor.value(fieldname).toString()).encode("latin-1") )
+ record.append( str(self.cursor.value(fieldname).toString()).encode("latin-1") )
#print "read record: %s" % record
return record
@@ -124,14 +124,14 @@ class CopyCenterPlugin:
def initInsert(self):
self.write = self.writeInsert
if not self.cursor.select():
- raise "Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) )
+ raise Exception("Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) ))
for fieldname in self.fieldlist: # check fieldlist
field = self.cursor.field(fieldname)
- if not field: raise "There exists no such field \"%s\" in the table \"%s\"." % (fieldname, self.cursor.name())
+ if not field: raise Exception("There exists no such field \"%s\" in the table \"%s\"." % (fieldname, self.cursor.name()))
self.copierer.appendProgressMessage("Insert SQL: %s" % str(self.cursor.executedQuery()))
def writeInsert(self, record):
- print "insert record: %s" % record
+ print("insert record: %s" % record)
from TQt import qt
cursorrecord = self.cursor.primeInsert()
count = len(record)
@@ -145,9 +145,9 @@ class CopyCenterPlugin:
cursorrecord.setValue(self.fieldlist[i], v)
rowcount = self.cursor.insert()
if rowcount < 1:
- drv = unicode(self.cursor.lastError().driverText()).encode("latin-1")
- db = unicode(self.cursor.lastError().databaseText()).encode("latin-1")
- print "failed: %s %s" % (drv,db)
+ drv = str(self.cursor.lastError().driverText()).encode("latin-1")
+ db = str(self.cursor.lastError().databaseText()).encode("latin-1")
+ print("failed: %s %s" % (drv,db))
self.copierer.writeFailed(record)
else:
self.copierer.writeSuccess(record,rowcount)
@@ -158,9 +158,9 @@ class CopyCenterPlugin:
def initUpdate(self):
self.write = self.writeUpdate
self.indexfieldname = str(self.widget.indexedit.text()).strip()
- if self.indexfieldname == "": raise "No index-field defined."
+ if self.indexfieldname == "": raise Exception("No index-field defined.")
pkindex = self.cursor.index(self.indexfieldname)
- if not pkindex: raise "Invalid index-field defined."
+ if not pkindex: raise Exception("Invalid index-field defined.")
self.cursor.setPrimaryIndex(pkindex)
#self.cursor.setMode( qtsql.TQSqlCursor.Insert | qtsql.TQSqlCursor.Update )
self.copierer.appendProgressMessage("Update SQL: %s" % str(self.cursor.executedQuery()))
@@ -173,13 +173,13 @@ class CopyCenterPlugin:
indexvalue = record[idx]
except:
import traceback
- print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
- raise "Failed to determinate the value for the primary key."
+ print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
+ raise Exception("Failed to determinate the value for the primary key.")
# select cursor and go to matching record.
wherestatement = "%s = \"%s\"" % (self.indexfieldname, indexvalue)
if not self.cursor.select(wherestatement):
- raise "Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) )
- if not self.cursor.next():
+ raise Exception("Select on cursor failed.<br>%s<br>%s" % ( str(self.cursor.lastError().driverText()),str(self.cursor.lastError().databaseText()) ))
+ if not next(self.cursor):
#print "No such record to update !"
return False
# Prepare updating the record.
@@ -202,7 +202,7 @@ class CopyCenterPlugin:
self.copierer.writeFailed(record)
else:
self.copierer.writeSuccess(record,rowcount)
- print "updated record (rowcount %s): %s" % (rowcount,record)
+ print("updated record (rowcount %s): %s" % (rowcount,record))
return True
def __init__(self, copycenter):
@@ -441,21 +441,21 @@ class CopyCenterPlugin:
if optionname == 'indexfield': return str(self.indexedit.text())
except:
import traceback
- print "".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) )
+ print("".join( traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]) ))
return ""
def connectClicked(self):
if self.plugin.database != None and self.plugin.database.isOpen():
- print "already connected. not needed to reconnect..."
+ print("already connected. not needed to reconnect...")
self.updateConnectState()
return True
- print "trying to connect..."
+ print("trying to connect...")
from TQt import qtsql
drivername = str(self.driveredit.currentText())
- print "drivername: %s" % drivername
+ print("drivername: %s" % drivername)
connectionname = "CopyCenter%s" % self.plugin.plugintype
- print "connectionname: %s" % connectionname
+ print("connectionname: %s" % connectionname)
self.plugin.database = qtsql.TQSqlDatabase.addDatabase(drivername,connectionname)
if not self.plugin.database:
qt.TQMessageBox.critical(self,"Failed to connect","<qt>Failed to create database for driver \"%s\"</qt>" % drivername)
@@ -479,16 +479,16 @@ class CopyCenterPlugin:
if not self.plugin.database.open():
qt.TQMessageBox.critical(self,"Failed to connect","<qt>%s<br><br>%s</qt>" % (self.plugin.database.lastError().driverText(),self.plugin.database.lastError().databaseText()))
return False
- print "database is opened now!"
+ print("database is opened now!")
self.updateConnectState()
return True
def disconnectClicked(self):
- print "trying to disconnect..."
+ print("trying to disconnect...")
if self.plugin.database:
self.plugin.database.close()
self.plugin.database = None
- print "database is closed now!"
+ print("database is closed now!")
self.updateConnectState()
plugin.widget = MainWidget(plugin,self.dialog,parent)