python - QSqlDatabase failing to open with no useful information using lastError() -


i'm having trouble opening qsqldatabase (qsqlite) in pyqt, , don't seem getting useful error telling me why it's failing. i'm using python 3.4.3 , pyqt 4.11.3.

here's snippet of code hacked try , thing working:

def __init__(self):     self.__database = qtsql.qsqldatabase.adddatabase("qsqlite")      if self.__database.isvalid():         print("db valid")     else:         print("db not valid")      if not self.__database.open():         print("could not open database.")         print("text: " + self.__database.lasterror().text())         print("type: " + str(self.__database.lasterror().type()))         print("number: " + str(self.__database.lasterror().number()))      query = qtsql.qsqlquery(self.__database)     query.exec("create table person (id int primary key, firstname varchar(20), lastname varchar(20))");     query.exec("insert person values(101, 'danny', 'young')");     query.exec("insert person values(102, 'christine', 'holand')");     query.exec("insert person values(103, 'lars', 'gordon')"); 

and here's output when above ran:

db valid

could not open database.

text:

type: 0

number: -1

qsqlquery::exec: database not open

qsqlquery::exec: database not open

qsqlquery::exec: database not open

qsqlquery::exec: database not open

any direction appreciated! it's frustrating error messages aren't useful @ all.

dumb mistake me. fixed setting database name using qtsql.qsqldatabase.setdatabasename("name_here.db")


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -