当前位置: 首页>>代码示例>>Python>>正文


Python QSqlDatabase.addDatabase方法代码示例

本文整理汇总了Python中PyQt4.QtSql.QSqlDatabase.addDatabase方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlDatabase.addDatabase方法的具体用法?Python QSqlDatabase.addDatabase怎么用?Python QSqlDatabase.addDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtSql.QSqlDatabase的用法示例。


在下文中一共展示了QSqlDatabase.addDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createConnection

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
def createConnection():
    mdb = QSqlDatabase.addDatabase("QMYSQL")
    mdb.setHostName("localhost")
    mdb.setDatabaseName("vim")
    mdb.setUserName("vim")
    mdb.setPassword("ViM")
    if not mdb.open():
        QMessageBox.warning(None, "Edit MySQL Vim", QString("Database Error: %1").arg(mdb.lastError().text()))
        sys.exit(-1)
开发者ID:jedamus,项目名称:vim-python,代码行数:11,代码来源:edit_mysql_vim.py

示例2: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
	def __init__(self, name, applicationWindow, hostname, username, password, port):
		"""
		@type name: str
		@type connection: MySQLdb.Connection
		@type applicationWindow: MainApplicationWindow
		"""
		self.name = name
		self.hostname = hostname
		self.username = username
		self.password = password
		self.port = port
		self.applicationWindow = applicationWindow
		self.databases = list()
		self.currentDatabase = None
		self.collations = list()

		self.connection = MySQLdb.connect(host = hostname, user = username, passwd = password, port = port, cursorclass = MySQLdb.cursors.DictCursor)
		db = QSqlDatabase.addDatabase('QMYSQL', name)
		db.setHostName(hostname)
		db.setUserName(username)
		db.setPassword(password)
		print db.open()

		self.db = db

		serverItem = HeidiTreeWidgetItem()
		serverItem.setText(0, name)
		serverItem.setIcon(0, QIcon('../resources/icons/server.png'))
		serverItem.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
		serverItem.setChildIndicatorPolicy(QTreeWidgetItem.DontShowIndicatorWhenChildless)
		serverItem.itemType = 'server'

		self.databaseTreeItem = serverItem

		applicationWindow.mainWindow.databaseTree.addTopLevelItem(serverItem)
开发者ID:Fapiko,项目名称:pyHeidi,代码行数:37,代码来源:database_server.py

示例3: globaldb

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
def globaldb():
    db = QSqlDatabase.addDatabase("QSQLITE")
    db.setDatabaseName("caracate.db")
    if not db.open():
        QMessageBox.warning(None, "Phone Log",  "Database Error: %s" % db.lastError().text())
        sys.exit(1)
    return db
开发者ID:iefan,项目名称:caracategui,代码行数:9,代码来源:resources.py

示例4: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
    def __init__(self, header=None, db=None, parent=None):
        super(FilterDialog, self).__init__(parent)

        self.setupUi(self)

        self.dbi = ""
        if not db:
            filename = ":memory:"
            self.dbi = QSqlDatabase.addDatabase("QSQLITE")
            self.dbi.setDatabaseName(filename)
            self.dbi.open()

        self.creaStrutturaDB(header)

        self.sModel = QSqlTableModel(self)
        self.sModel.setTable(QString("filtertable"))
        self.sModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
        self.sModel.select()

        self.filterTableView.setModel(self.sModel)
        self.filterTableView.setColumnHidden(0, True)
        self.filterTableView.setAlternatingRowColors(True)

        self.connect(self.sModel, SIGNAL("primeInsert (int,QSqlRecord&)"),
                self.updRows)
        self.connect(self.addFilterPushButton, SIGNAL("clicked()"),
                self.accept)
        self.connect(self.addLinePushButton, SIGNAL("clicked()"),
                self.addLine)

        self.sModel.insertRows(0, 10)
        self.sModel.submitAll()
        self.restoreSettings()
        self.resultFilter = None
开发者ID:L0cutus,项目名称:Gestione-Magazzino,代码行数:36,代码来源:filterdialog.py

示例5: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.ui = sm.Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.table_studentList

        # Call DB
        self.db = QSqlDatabase.addDatabase("QSQLITE")
        self.db.setDatabaseName("studentInformation001.db")
        self.db.open()
        # End of call DB

        # student info into table view
        projectModel = QSqlQueryModel()
        projectModel.setQuery("SELECT schoolNumber, Name FROM Student ORDER BY schoolNumber ASC",self.db)

        projectView = self.ui.table_studentList
        projectView.setModel(projectModel)
        projectView.show()
        #end of student info into table view

        # QTableView Click Event
        self.qTableView = self.ui.table_studentList
        self.qTableView.clicked.connect(self.showInfo)
        
        # click and connection update
        self.ui.Btn_Update.clicked.connect(self.cont)
        
        # click and connection grade
        self.ui.Btn_Grade.clicked.connect(self.contGrade)
开发者ID:bongbong3,项目名称:Python,代码行数:32,代码来源:InitiatingTask.py

示例6: addConnection

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
 def addConnection(self, driver, dbName, user, password, host, port):
     """
     Public method to add a database connection.
     
     @param driver name of the Qt database driver (QString)
     @param dbName name of the database (QString)
     @param user user name (QString)
     @param password password (QString)
     @param host host name (QString)
     @param port port number (integer)
     """
     err = QSqlError()
     
     self.__class__.cCount += 1
     db = QSqlDatabase.addDatabase(driver.toUpper(), 
                                   QString("Browser%1").arg(self.__class__.cCount))
     db.setDatabaseName(dbName)
     db.setHostName(host)
     db.setPort(port)
     if not db.open(user, password):
         err = db.lastError()
         db = QSqlDatabase()
         QSqlDatabase.removeDatabase(QString("Browser%1").arg(self.__class__.cCount))
     
     self.connections.refresh()
     
     return err
开发者ID:usc-bbdl,项目名称:R01_HSC_cadaver_system,代码行数:29,代码来源:SqlBrowserWidget.py

示例7: create_connection

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
 def create_connection(self):
     """Create connection to progressions.db, Create if not exists
     @return: QSqlDatabase"""
     db = QSqlDatabase.addDatabase("QSQLITE")  # QSqlDriver = SQLITE, default connection
     db.setDatabaseName(DATABASE_NAME)
     if not db.open():
         pass  # Should raise a some kind of Error
     return db
开发者ID:vkolehmainen,项目名称:PyMusicGen,代码行数:10,代码来源:databasemanager.py

示例8: openDatabase

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
 def openDatabase(self):
     self.db = None
     self.db = QSqlDatabase.addDatabase('QMYSQL')
     self.db.setHostName(connectionInfo['host'])
     self.db.setPort(connectionInfo['port'])
     self.db.setDatabaseName(connectionInfo['database'])
     self.db.setUserName(connectionInfo['user'])
     self.db.setPassword(connectionInfo['password'])
     self.db.open()
开发者ID:w12x,项目名称:homework,代码行数:11,代码来源:Application.py

示例9: db_connect

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
 def db_connect(self):
     #print "db_connect", self.server
     self.db = QSqlDatabase.addDatabase("QMYSQL")
     self.db.setHostName(self.server['server'])
     self.db.setUserName(self.server['user'])
     self.db.setPassword(self.server['passwd'])
     
     ok = self.db.open()
     print "open", ok
开发者ID:pedromorgan,项目名称:PyQtDb,代码行数:11,代码来源:DBBrowser.py

示例10: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
    def __init__(self, driver, dbname, user, passwd):
        self.conn = QSqlDatabase.addDatabase(
            driver, "qtsql_%d" % QtSqlDBConnection.connections)
        QtSqlDBConnection.connections += 1
        self.conn.setDatabaseName(dbname)
        self.conn.setUserName(user)
        self.conn.setPassword(passwd)

        if not self.conn.open():
            raise ConnectionError(self.conn.lastError().databaseText())
开发者ID:Geoneer,项目名称:QGIS,代码行数:12,代码来源:QtSqlDB.py

示例11: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
 def __init__(self):
     '''
     Constructor
     '''
     QSqlDatabase.removeDatabase( 'QMYSQL' )
     self.database = QSqlDatabase.addDatabase( 'QMYSQL' )
     self.database.setDatabaseName( "misimportaciones" )
     self.database.setHostName( "localhost")
     self.database.setUserName( "root" )
     self.database.setPassword( "root" )
开发者ID:joseanm,项目名称:pyqt_billing,代码行数:12,代码来源:database.py

示例12: db

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
 def db(self):
     """
         Get or create the form.db database instance and the needed tables.
     """
     if self._db is None:
         path = os.path.dirname(self.module.__file__)
         dbpath = os.path.join(path, "form.db")
         self._db = QSqlDatabase.addDatabase("QSQLITE")
         self._db.setDatabaseName(dbpath)
         self._db.open()
         self.checkDatabaseTables()
     return self._db
开发者ID:spanc29,项目名称:qmap,代码行数:14,代码来源:forms.py

示例13: connectToDb

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
    def connectToDb( self ):
        self.uidConnection = self.uidConnection + QUuid.createUuid().toString()
        d = QSqlDatabase.addDatabase( "QPSQL",  self.uidConnection)
        d.setHostName( self.host )
        d.setPort( int( self.port ) )
        d.setDatabaseName( self.dbname )
        d.setUserName( self.user )
        d.setPassword( self.passw )
        if not d.open():
            showError(None, 'error', 'error connect DB:  host:' + self.host + ' dbname:' + self.dbname + ' user:' + self.user + ' passw=' + self.passw )
		
        self.createScheme()
开发者ID:antwise,项目名称:QgsPostGIS-Viewer,代码行数:14,代码来源:SqlLayer.py

示例14: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.setupUi(self)
        self.setupMenu()
        self.restoreWinSettings()

        self.editindex = None
        self.filename = None
        self.db = QSqlDatabase.addDatabase("QSQLITE")

        self.loadInitialFile()
        self.setupUiSignals()
开发者ID:L0cutus,项目名称:Gestione-Fatture,代码行数:15,代码来源:fatture.py

示例15: __init__

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import addDatabase [as 别名]
    def __init__(self, parent=None):
        super(CopyrightDatabase, self).__init__(parent)
        settings_folder = str(QDesktopServices.storageLocation(QDesktopServices.DataLocation))
        db_path = os.path.join(settings_folder, 'copyright.db')

        self.db = QSqlDatabase.addDatabase('QSQLITE')
        """@type : QSqlDatabase"""
        self.db.setDatabaseName(db_path)

        self.db.open()

        if not 'copyright' in self.db.tables():
            self.create_copyright_table()
开发者ID:se0siris,项目名称:bing-wallpaper-changer,代码行数:15,代码来源:databases.py


注:本文中的PyQt4.QtSql.QSqlDatabase.addDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。