本文整理汇总了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)
示例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)
示例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
示例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
示例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)
示例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
示例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
示例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()
示例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
示例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())
示例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" )
示例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
示例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()
示例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()
示例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()