Hi,
after a quest for connecting to an odbc data source and after much documentation reading, i finally have a snippet that i can connect and execute a parameterized stored procedure!
The sp is a simple one, getting an integer and returning one colymn of string data
The only 2 questions i have is that if i HAVE to declare the stored procedure parameter type as QVariant(4) or is another way to do this,
and (more important) how i can print non-ascii data that exists in the result set...
I am using Eclipse/PyDev (if that matters) but i print garbage from the snipet below,
and am not sure if the i correctly coded the part about QVariant.toString and QtCore.QString.toUtf8(candidate). (i am propably not...)
In a real app would put the data in a grid but what about now ?? I check the variable"candidate" in the debugger and it correctly contains the Greek characters that came from the database, but how i can...print them ??
Is there something in Qt that i am not doing (or at all...) correcltly ?
Code is below:
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtSql, QtGui
db.setDatabaseName("pm");
f = db.open()
if f:
print "Connected"
query.prepare("{call graduation_fetch(?)}")
query.setForwardOnly(True)
query.
bindValue(0, QtCore.
QVariant(4), QtSql.
QSql.
In) query.exec_()
while query.next():
candidate
= QtCore.
QVariant.
toString(query.
value(0)) print QtCore.
QString.
toUtf8(candidate
)
db.close()
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtSql, QtGui
app = QtGui.QApplication(sys.argv)
db = QtSql.QSqlDatabase.addDatabase("QODBC");
db.setDatabaseName("pm");
f = db.open()
if f:
print "Connected"
query = QtSql.QSqlQuery(db)
query.prepare("{call graduation_fetch(?)}")
query.setForwardOnly(True)
query.bindValue(0, QtCore.QVariant(4), QtSql.QSql.In)
query.exec_()
while query.next():
candidate = QtCore.QVariant.toString(query.value(0))
print QtCore.QString.toUtf8(candidate)
db.close()
To copy to clipboard, switch view to plain text mode
and of course, thanks for any help!
Bookmarks