本文整理汇总了Python中PyQt4.QtSql.QSqlDatabase.removeDatabase方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlDatabase.removeDatabase方法的具体用法?Python QSqlDatabase.removeDatabase怎么用?Python QSqlDatabase.removeDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlDatabase
的用法示例。
在下文中一共展示了QSqlDatabase.removeDatabase方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addConnection
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [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
示例2: __init__
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [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" )
示例3: __del__
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [as 别名]
def __del__(self):
self.db.commit()
for q in self.query_set:
logger.debug("cleaning up query: {0}".format(q.lastQuery()))
q.finish()
del q
self.query_set = set()
logger.debug("cleaning out db connection: {0}".format(self.db.connectionName()))
self.db.close()
QSqlDatabase.removeDatabase(self.db.connectionName())
self.db = None
示例4: newconfiguration
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [as 别名]
def newconfiguration( cfg ):
settings = QSettings()
dbconfig = dlgDatabaseConfig()
dbconfig.txtDatabase.setText( settings.value( "%s/DBName" % cfg ).toString() )
dbconfig.txtServer.setText( settings.value( "%s/DBServer" % cfg ).toString() )
dbconfig.txtReports.setText( settings.value( "%s/DBReports" % cfg ).toString() )
dbconfig.txtUser.setText( settings.value( "%s/DBUser" % cfg ).toString() )
if dbconfig.exec_() == QDialog.Accepted:
QSqlDatabase.removeDatabase( 'QMYSQL' )
database = QSqlDatabase.addDatabase( 'QMYSQL' )
database.setDatabaseName( dbconfig.txtDatabase.text() )
database.setHostName( dbconfig.txtServer.text() )
database.setUserName( dbconfig.txtUser.text() )
database.setPassword( dbconfig.txtPassword.text() )
#guardar en el archivo de configuracion
settings.setValue( "%s/DBName" % cfg, dbconfig.txtDatabase.text() )
settings.setValue( "%s/DBServer" % cfg, dbconfig.txtServer.text() )
settings.setValue( "%s/DBUser" % cfg, dbconfig.txtUser.text() )
settings.setValue( "%s/DBPassword" % cfg, dbconfig.txtPassword.text() )
settings.setValue( "%s/DBReports" % cfg, dbconfig.txtReports.text() )
reports.Reports.url = dbconfig.txtReports.text()
示例5: endConnection
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [as 别名]
def endConnection():
DB = Database
DB.qtpiDB.close()
DB.qtpiDB = None
QSqlDatabase.removeDatabase(DB.connection)
示例6: DatabaseInteraction
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [as 别名]
class DatabaseInteraction(object):
"""Handles all interactions with the database"""
def __init__(self, test=False):
if test:
filename = os.path.join(CONFIG_TEST_DATABASE_PATH, CONFIG_DATABASE_NAME)
else:
filename = os.path.join(CONFIG_DATABASE_PATH, CONFIG_DATABASE_NAME)
self.conn = QSqlDatabase.addDatabase("QSQLITE")
self.conn.setDatabaseName(filename)
result = self.conn.open()
# Check that the db opened successfully, close program if it didn't
# TODO: handle this better?
if result == False:
print "Failed to open database " + filename + \
" with error: " + self.conn.lastError().text()
sys.exit(1)
self.setupModels()
def setupModels(self):
# Participant
self.participantModel = QSqlTableModel(db=self.conn)
self.participantModel.setTable("participants")
self.participantModel.setSort(9, Qt.DescendingOrder)
self.participantModel.select()
# set headers
self.participantModel.setHeaderData(0, Qt.Horizontal, "First")
self.participantModel.setHeaderData(1, Qt.Horizontal, "Last")
self.participantModel.setHeaderData(2, Qt.Horizontal, "Address")
self.participantModel.setHeaderData(3, Qt.Horizontal, "Town")
self.participantModel.setHeaderData(4, Qt.Horizontal, "Postal Code")
self.participantModel.setHeaderData(5, Qt.Horizontal, "Home Phone")
self.participantModel.setHeaderData(6, Qt.Horizontal, "Cell Phone")
self.participantModel.setHeaderData(7, Qt.Horizontal, "Email")
self.participantModel.setHeaderData(9, Qt.Horizontal, "Date of Birth")
self.participantModel.setHeaderData(10, Qt.Horizontal, "School Attending")
self.participantModel.setHeaderData(11, Qt.Horizontal, "Parent")
self.participantModel.setHeaderData(12, Qt.Horizontal, "School Grade")
self.participantModel.setHeaderData(13, Qt.Horizontal, "Group Name")
self.participantModel.setHeaderData(14, Qt.Horizontal, "Group Size")
self.participantModel.setHeaderData(15, Qt.Horizontal, "Earliest Performance Time")
self.participantModel.setHeaderData(16, Qt.Horizontal, "Latest Performance Time")
self.participantModel.setHeaderData(17, Qt.Horizontal, "Participants") # TODO display names
self.participantModel.setHeaderData(18, Qt.Horizontal, "Average Age")
self.participantModel.setHeaderData(19, Qt.Horizontal, "Contact") # TODO display name
# TODO display first piece title for groups
# Teacher
self.teacherModel = QSqlTableModel(db=self.conn)
self.teacherModel.setTable("teachers")
self.teacherModel.setSort(0, Qt.DescendingOrder)
self.teacherModel.select()
# set headers
self.teacherModel.setHeaderData(1, Qt.Horizontal, "First")
self.teacherModel.setHeaderData(2, Qt.Horizontal, "Last")
self.teacherModel.setHeaderData(3, Qt.Horizontal, "Address")
self.teacherModel.setHeaderData(4, Qt.Horizontal, "Town")
self.teacherModel.setHeaderData(5, Qt.Horizontal, "Postal Code")
self.teacherModel.setHeaderData(6, Qt.Horizontal, "Daytime Phone")
self.teacherModel.setHeaderData(7, Qt.Horizontal, "Evening Phone")
self.teacherModel.setHeaderData(8, Qt.Horizontal, "Email")
# Entry
self.entryModel = QSqlTableModel(db=self.conn)
self.entryModel.setTable("entries")
self.entryModel.setSort(0, Qt.DescendingOrder)
self.entryModel.select()
# set headers
self.entryModel.setHeaderData(1, Qt.Horizontal, "Participant") # TODO display name
self.entryModel.setHeaderData(2, Qt.Horizontal, "Teacher") # TODO display name
self.entryModel.setHeaderData(3, Qt.Horizontal, "Discipline")
self.entryModel.setHeaderData(4, Qt.Horizontal, "Level")
self.entryModel.setHeaderData(5, Qt.Horizontal, "Class Number")
self.entryModel.setHeaderData(6, Qt.Horizontal, "Class Name")
self.entryModel.setHeaderData(7, Qt.Horizontal, "Instrument")
self.entryModel.setHeaderData(8, Qt.Horizontal, "Years of Instruction")
self.entryModel.setHeaderData(9, Qt.Horizontal, "Scheduling Requirements")
# Piece
self.pieceModel = QSqlTableModel(db=self.conn)
self.pieceModel.setTable("selections")
self.pieceModel.setSort(0, Qt.DescendingOrder)
self.pieceModel.select()
# set headers
self.pieceModel.setHeaderData(1, Qt.Horizontal, "Title")
self.pieceModel.setHeaderData(2, Qt.Horizontal, "Performance Time")
self.pieceModel.setHeaderData(3, Qt.Horizontal, "Composer/Arranger")
self.pieceModel.setHeaderData(5, Qt.Horizontal, "Title of Musical")
def close(self):
"""Clean everything up and close the connection"""
connName = self.conn.connectionName()
self.conn.close()
self.conn = QSqlDatabase()
self.conn.removeDatabase(connName)
global dbInteractionInstance
dbInteractionInstance = None
def backupDb(self):
#.........这里部分代码省略.........
示例7: __del__
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import removeDatabase [as 别名]
def __del__(self):
QSqlDatabase.removeDatabase(self.uidConnection)