コード例 #1
0
ファイル: main.py プロジェクト: dec1/stackoverflow-egs
def createConnection():
    db = QSqlDatabase.addDatabase('QSQLITE')
    db.setDatabaseName('memory')
    if not db.open():
        QMessageBox.critical(
            None, qApp.tr("Cannot open database"),
            qApp.tr("Unable to establish a database connection.\n"
                    "This example needs SQLite support. Please read "
                    "the Qt SQL driver documentation for information "
                    "how to build it.\n\n"
                    "Click Cancel to exit."), QMessageBox.Cancel)
        return False

    query = QSqlQuery()
    query.exec_("create table person(id int primary key, "
                "firstname varchar(20), lastname varchar(20),"
                "archive BOOLEAN NOT NULL CHECK (archive IN (0,1)))")

    query.exec_("insert into person values(101, 'Danny', 'Young', 1)")
    query.exec_("insert into person values(102, 'Christine', 'Holand', 0)")
    query.exec_("insert into person values(103, 'Lars', 'Gordon', 1)")
    query.exec_("insert into person values(104, 'Roberto', 'Robitaille', 0)")
    query.exec_("insert into person values(105, 'Maria', 'Papadopoulos', 1)")
    query.exec_("insert into person values(106, 'Luisa', 'Papadopoulos', 1)")
    query.exec_("insert into person values(107, 'Luis', 'Papadopoulos', 1)")

    return True
コード例 #2
0
def set_databaseconnection():
    '''
    Setting connection with SQLite
    '''
    filepath = os.path.join(os.path.dirname(__file__), '..', '..', '..',
                            'ResourceFiles', 'Database', 'Intg_osdag.sqlite')
    #     filepath = "D:\EclipseWorkspace\OsdagWorkshop\Database\CleatSections"

    #     db = QSqlDatabase.database("QSQLITE")
    #     if db.IsValid():
    #         return True

    db = QSqlDatabase.addDatabase("QSQLITE")
    db.setDatabaseName(filepath)
    # db.open()
    if not db.open():

        QMessageBox.critical(
            None, qApp.tr("Cannot open database"),
            qApp.tr("Unable to establish a database connection.\n"
                    "This example needs SQLite support. Please read "
                    "the Qt SQL driver documentation for information "
                    "how to build it.\n\n"
                    "Click Cancel to exit."), QMessageBox.Cancel)
        return False
コード例 #3
0
ファイル: tasks_sort.py プロジェクト: titanmet/task
def createConnection():
    db = QSqlDatabase.addDatabase('QSQLITE')
    db.setDatabaseName('task')
    if not db.open():
        QMessageBox.critical(
            None, qApp.tr("Cannot open database"),
            qApp.tr("Unable to establish a database connection."),
            QMessageBox.Cancel)
        return False
    return True
コード例 #4
0
ファイル: model.py プロジェクト: yash-lokhande/Osdag
def set_databaseconnection():
    '''
    Setting connection with SQLite
    '''
    # TODO explicitly close database connection on exit
    filepath = os.path.join(os.path.dirname(__file__), '..', '..', '..', 'ResourceFiles', 'Database', 'Intg_osdag.sqlite')
    db = QSqlDatabase.addDatabase("QSQLITE")
    db.setDatabaseName(filepath)
    if not db.open():
        QMessageBox.critical(None, qApp.tr("Cannot open database"),
                                   qApp.tr("Unable to establish a database connection.\n"
                                                 "This example needs SQLite support. Please read "
                                                 "the Qt SQL driver documentation for information "
                                                 "how to build it.\n\n"
                                                 "Click Cancel to exit."),
                                   QMessageBox.Cancel)
        return False
コード例 #5
0
 def add(self, result: str, nbr_predicted: int):
     if result in self.results_cache:
         pass
     else:
         db: QSqlDatabase = QSqlDatabase.addDatabase("QSQLITE")
         db.setDatabaseName('demo.db')
         if not db.open():
             QMessageBox.critical(None, qApp.tr("无法打开数据库"),
                                  qApp.tr('无法连接数据库'), QMessageBox.Cancel)
             logging.info('数据库连接失败....', hasError=True)
         else:
             logging.info('数据库已连接.....')
         query = QtSql.QSqlQuery()
         query.exec_(
             "update user_face_info set punched=1 where user_id={}".format(
                 nbr_predicted))
         self.results_cache.append(result)
         result = "{0} 打卡成功!".format(result)
         self.punch_signal.emit(result)