示例#1
0
 def setDatabase(self, database):
     self.database = database
     databaseTreeItem = database.getDatabaseTreeItem()
     tableTreeItem = HeidiTreeWidgetItem()
     tableTreeItem.itemType = 'table'
     tableTreeItem.setIcon(0, QIcon('../resources/icons/table.png'))
     tableTreeItem.setText(0, self.name)
     databaseTreeItem.addChild(tableTreeItem)
     database.tables.append(self)
示例#2
0
    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()

        ctypes.windll.LoadLibrary(
            r'D:\wamp64\bin\mysql\mysql5.7.21\lib\libmysql.dll')  # 加载驱动库
        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)
        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
0
    def __init__(self, server, name):
        """
		@type server: DatabaseServer
		@type applicationWindow: MainApplicationWindow
		@type databaseTreeItem: HeidiTreeWidgetItem
		"""
        self.name = name
        self.applicationWindow = server.applicationWindow
        self.server = server
        self.tables = []

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

        serverItem = server.databaseTreeItem
        serverItem.addChild(database)
        serverItem.setExpanded(True)

        self.databaseTreeItem = database