Ejemplo n.º 1
0
    def Connect(self):
        self._type = self.connections.get(self.dbType.currentIndex())
        self._host = self.host_in.text()
        self._port = self.port_in.text()
        self._user = self.user_in.text()
        self._pass = self.pass_in.text()
        self.buffered_c = self.buffered.isChecked()

        try:
            if self._type == 'mysql':
                MYSQL_Engine.connect(self._host, self._port, self._user,
                                     self._pass, self.buffered_c)
            if self._type == 'mssql':
                MSSQL_Engine.connect(self._host, self._user, self._pass)
            if self._type == 'postgre':
                POSTG_Engine.connect("postgres", self._host, self._port,
                                     self._user, self._pass)

            self.manager = ManagerWindow(self._host, self._port, self._user,
                                         self._pass, self.buffered_c,
                                         self._type)
            self.cf.save_config()
            self.hide()
        except Exception as error:
            QMessageBox.critical(self, "CRITICAL ERROR", str(error),
                                 QMessageBox.Ok)
            traceback.print_exc()
Ejemplo n.º 2
0
    def __init__(self, hs, pt, us, ps, bfr, _type, parent=None):
        super(ManagerWindow, self).__init__(parent)
        self.setupUi(self)

        self.cf = ConfigHandler(self)
        self.cf.load_theme()

        toolsManager = ManagerTools(self)
        toolsManager.SetIcons()
        toolsManager.AddVerticalToolbar()

        self.showMaximized()

        self.hs = hs
        self.pt = pt
        self.us = us
        self.ps = ps
        self.bfred = bfr
        self.type = _type

        if self.type == 'mysql':
            self.mydb = MYSQL_Engine.connect(self.hs, self.pt, self.us,
                                             self.ps, self.bfred)
        if self.type == 'mssql':
            self.mydb = MSSQL_Engine.connect(self.hs, self.us, self.ps)
        if self.type == 'postgre':
            self.mydb = POSTG_Engine.connect("postgres", self.hs, self.pt,
                                             self.us, ps)

        self.refresh_database()
        self.get_server_dbs()

        self.tables_out.itemDoubleClicked.connect(self.ItemDoubleClicked)
Ejemplo n.º 3
0
    def get_table_data(self, tb):
        """get_table_data ('Tablename')"""
        table = str(tb)
        cursor = self.mydb.cursor()

        try:
            if self.type == 'mysql':
                allSQLRows = MYSQL_Engine.Get_Data(cursor, table)
            if self.type == 'mssql':
                allSQLRows = MSSQL_Engine.Get_Data(cursor, table)
            if self.type == 'postgre':
                allSQLRows = POSTG_Engine.Get_Data(cursor, table)

            lenRow = len(allSQLRows)
            lenCol = len(allSQLRows[0])

            self.data_result.setRowCount(lenRow)
            self.data_result.setColumnCount(lenCol)

            if allSQLRows is not None:
                for lin in range(0, lenRow):
                    for col in range(0, lenCol):
                        data = QTableWidgetItem(str(allSQLRows[lin][col]))
                        self.data_result.setItem(lin, col, data)
            columns = cursor.description
            for col in range(0, lenCol):
                headerName = QTableWidgetItem(columns[col][0])
                self.data_result.setHorizontalHeaderItem(col, headerName)

            self.data_result.resizeColumnsToContents()
        except IndexError:
            pass  # NO RESULT TO FETCH
        except Exception as error:
            traceback.print_exc()
Ejemplo n.º 4
0
    def get_table_types(self, tb):
        """get_table_types ('Table name')"""
        table = str(tb)
        cursor = self.mydb.cursor()
        try:
            if self.type == 'mysql':
                allSQLRows = MYSQL_Engine.Get_Struct(cursor, table)
            if self.type == 'mssql':
                allSQLRows = MSSQL_Engine.Get_Struct(cursor, table)
            if self.type == 'postgre':
                allSQLRows = POSTG_Engine.Get_Struct(cursor, table)

            lenRow = len(allSQLRows)
            lenCol = len(allSQLRows[0])

            self.desc_result.setRowCount(lenRow)  ##set number of rows
            self.desc_result.setColumnCount(
                lenCol
            )  ##this is fixed for result_out, ensure that both of your tables, sql and qtablewidged have the same number of columns
            if allSQLRows is not None:
                for lin in range(0, lenRow):
                    for col in range(0, lenCol):
                        data = QTableWidgetItem(str(allSQLRows[lin][col]))
                        self.desc_result.setItem(lin, col, data)
            columns = cursor.description
            for col in range(0, lenCol):
                headerName = QTableWidgetItem(columns[col][0])
                self.desc_result.setHorizontalHeaderItem(col, headerName)
            self.desc_result.resizeColumnsToContents()
            self.processEvents()
        except IndexError:
            pass  # NO RESULT TO FETCH
        except Exception as error:
            traceback.print_exc()
Ejemplo n.º 5
0
    def get_tables_from_db(self, _cDb):
        """get_tables_from_db("Current Database")"""

        cursor = self.mydb.cursor()
        if self.type == 'mysql':
            self.tables = MYSQL_Engine.tables(cursor, _cDb)
            self.views = MYSQL_Engine.views(cursor, _cDb)

        if self.type == 'mssql':
            self.tables = MSSQL_Engine.tables(cursor)
            self.views = MSSQL_Engine.views(cursor)

        if self.type == 'postgre':
            self.tables = sorted(POSTG_Engine.tables(cursor))

        top_level_items = self.tables_out.topLevelItemCount()
        for i in range(top_level_items):
            top_item = self.tables_out.topLevelItem(i)
            item_name = top_item.text(0)
            if item_name == str(_cDb):
                table_folder = self.FolderItem(top_item, "Tables", ui_folder)
                views_folder = self.FolderItem(top_item, "Views", ui_folder)

                for tb in self.tables:
                    table_name = "%s" % tb
                    self.TreeItem(table_folder, table_name, table_name, ui_tb)
                for vw in self.views:
                    view_name = "%s" % vw
                    self.TreeItem(views_folder, view_name, view_name, ui_field)

                #if find toplevel then stop
                break
Ejemplo n.º 6
0
    def refresh_database(self):
        """refresh_database("Database Name")"""
        cursor = self.mydb.cursor()

        if self.type == 'mysql': db = MYSQL_Engine.Database(cursor)
        if self.type == 'mssql': db = MSSQL_Engine.Database(cursor)
        if self.type == 'postgre': db = POSTG_Engine.Database(cursor)

        if not db == None:
            self.tables_out.clear()
            self.get_server_dbs()
            self.get_tables_from_db(db)
            self.tables_out.expandAll()
Ejemplo n.º 7
0
    def get_server_dbs(self):
        """ get_server_dbs () """
        self.tables_out.clear()
        _dict = {}

        cursor = self.mydb.cursor()

        if self.type == 'mysql':
            self.databases = MYSQL_Engine.databases(cursor)
        if self.type == 'mssql':
            self.databases = MSSQL_Engine.databases(cursor)
        if self.type == 'postgre':
            self.databases = POSTG_Engine.databases(cursor)

        for db in self.databases:
            parent = QTreeWidgetItem(self.tables_out)
            parent.setText(0, "%s" % db)
            parent.setIcon(0, QIcon(ui_db))
            parent.setFlags(parent.flags())
Ejemplo n.º 8
0
    def ItemDoubleClicked(self):
        "ItemDoubleClicked()"
        index = self.tables_out.currentIndex()
        data = self.tables_out.model().data(index)
        _selected = str(data)

        cursor = self.mydb.cursor()

        if _selected in self.databases:
            if self.type == 'mysql':
                MYSQL_Engine.Set_Database(cursor, _selected)
            if self.type == 'mssql':
                MSSQL_Engine.Set_Database(cursor, _selected)
            if self.type == 'postgre':
                self.mydb = POSTG_Engine.connect(str(_selected), self.hs,
                                                 self.pt, self.us, self.ps)
            self.refresh_database()

        if _selected in self.tables:
            self.get_table_types(_selected)
            self.get_table_data(_selected)