def __init__(self, name, parent=None): settings = SettingsParser() # avoid overwriting connections that ain't finished yet while QSqlDatabase.contains(name): if name[-1].isdigit(): name = name[0:-1] + str( int(name[-1]) + 1 ) else: name = name + str(2) self._db = QSqlDatabase.addDatabase("QPSQL", name) self._db.setHostName(settings.get_value("Database", "hostname")) self._db.setDatabaseName("seareiros_bd") self._db.setUserName("seareiros") self._db.setPassword("localadm")
def _sql_version(self): '''internal init function to check version of SQLite driver in-use by QtSql module''' con='LiteyVersionCheck' db = QSqlDatabase.addDatabase("QSQLITE",con) db.setDatabaseName(':memory:') db.open() ver=db.exec_('select sqlite_version()') assert ver.next() result=str(ver.value(0)) ver.finish() del ver db.close() del db QSqlDatabase.removeDatabase(con) return result
def __init__(self, database_name): self.database_name = database_name self.db = QSqlDatabase.addDatabase('QSQLITE') self.db.setDatabaseName(self.database_name) if self.open(): if not 'employee' in self.db.tables(): create_tables()
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) database = QSqlDatabase.addDatabase('QSQLITE') database.setDatabaseName('astatsscraper.db') # Better lookup logic needed if not database.open(): print('Error opening database!') model = QSqlTableModel(db=database) model.setTable('steam_apps') table = QTableView() table.setEditTriggers(QAbstractItemView.NoEditTriggers) table.setModel(model) self.setCentralWidget(table) table.show()
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) database = QSqlDatabase.addDatabase('QSQLITE') database.setDatabaseName( 'astatsscraper.db') # Better lookup logic needed if not database.open(): print('Error opening database!') model = QSqlTableModel(db=database) model.setTable('steam_apps') table = QTableView() table.setEditTriggers(QAbstractItemView.NoEditTriggers) table.setModel(model) self.setCentralWidget(table) table.show()
def load_db(self, dbname, modelname=None): self.db = QSqlDatabase.addDatabase(self.dbtype) self.db.setDatabaseName(dbname) if not self.db.open(): QMessageBox.warning(self, "Batabase connection", "Database Error: %s" % (self.db.lastError().text())) return self.dbfile = dbname if modelname not in self.models.model_names: modeldlg = ModelDialog(self.models.model_names) if modeldlg.exec_(): modelname = modeldlg.selected_model() if modelname: self.load_model(modelname)
def InitTable(self): """Funzione che accede al database ed imposta il data model""" db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName(self.myWidget.txtPercorso.text()) db.open() model = QSqlTableModel() model.setTable("contatti") model.setEditStrategy(QSqlTableModel.OnManualSubmit) model.select() model.setHeaderData(0, QtCore.Qt.Horizontal, "Nome") model.setHeaderData(1, QtCore.Qt.Horizontal, "Cognome") model.setHeaderData(2, QtCore.Qt.Horizontal, "Telefono") self.tableModel = model self.myWidget.lstRubrica.setModel(model)
def dbConnect(): db = QSqlDatabase.addDatabase("QSQLITE") filename = "pythonthusiast.db" database = QFile(filename) if not database.exists(): qDebug("Database not found. Creating and opening") db.setDatabaseName(filename) db.open() query = QSqlQuery() query.exec_("create table qtapp_users " "(id integer primary key autoincrement, " "username varchar(30), " "password varchar(255))") query.prepare("insert into qtapp_users(username, password) values(:username, :password)") query.bindValue(":username", "eko") query.bindValue(":password", computeHash("password")) query.exec_() else: qDebug("Database found. Opening") db.setDatabaseName(filename) db.open() return db.isOpen()
self.__conf["mainWindowGeometry"] = self.saveGeometry() self.__conf["mainWindowState"] = self.saveState() if __name__ == "__main__": ret = 0 log = QFile("log") log.open(QIODevice.WriteOnly) try: app = QApplication(sys.argv) locale = QLocale.system().name() translator = QTranslator() translator.load("qt_" + locale, QLibraryInfo.location(QLibraryInfo.TranslationsPath)) app.installTranslator(translator) # Configuration de la base de données db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName('private/gem.db') db.open() # Création de l'_ui principale et boucle principale ui = GestionAbsences() ui.show() ret = app.exec_() except Exception: traceback.print_exc(file=log) log.close() sys.exit(ret)
self.sentSignal.emit(MailSender.MAIL_ERROR_TIMEOUT) except Exception, e: print e self.sentSignal.emit(MailSender.MAIL_ERROR_OTHER) if __name__ == "__main__": """Main de test""" import sys from PySide.QtGui import QApplication from PySide.QtCore import QLibraryInfo, QLocale, QTranslator from PySide.QtSql import QSqlDatabase app = QApplication(sys.argv) locale = QLocale.system().name() translator = QTranslator() translator.load("qt_" + locale, QLibraryInfo.location(QLibraryInfo.TranslationsPath)) app.installTranslator(translator) # Configuration de la base de données db = QSqlDatabase.addDatabase("QSQLITE") db.setDatabaseName('private/gem.db') db.open() ui = MailUI() ui.show() ret = app.exec_() sys.exit(ret)
def cleanup(self, conn_name): """ may not be the same connection name as appointed by 'name' argument See Worker class '__init__' method bellow """ QSqlDatabase.removeDatabase(conn_name)
def connect(self,fi): '''Database connection method''' self.db = QSqlDatabase.addDatabase("QSQLITE") self.db.setDatabaseName(fi) assert self.db.open() self.rehash(LiteyModel.ModelArea.ALL)