프로젝트

일반

사용자정보

개정판 2c6addcb

ID2c6addcbf70506b5fa0be17b34058dd1837e4e2d
상위 554fef55
하위 0dac3819, 156ab08b

김연진이(가) 4년 이상 전에 추가함

issue #1212 Mixed Type 결과 저장 테이블에 2개의 컬럼 추가 (Homo_Den@PressureVariation , Homo_Vel@PressureVariation)

Change-Id: Ib6c8a54e2b9cf50bf08dbe0632fd11c7a50e9422

차이점 보기:

HYTOS/HYTOS/AppDocData.py
1763 1763

  
1764 1764
        return category
1765 1765

  
1766
    def add_column(self, column_name, column_type, table_name):
1767
        try:
1768
            # Creates or opens a file called mydb with a SQLite3 DB
1769
            conn = sqlite3.connect(self.activeDrawing.path)
1770
            conn.execute('PRAGMA foreign_keys = ON')
1771
            # Get a cursor object
1772
            cursor = conn.cursor()
1773

  
1774
            sql = "Alter Table " + table_name + " Add Column '" + column_name + "' " + column_type
1775
            cursor.execute(sql)
1776

  
1777
            conn.commit()
1778
        # Catch the exception
1779
        except Exception as ex:
1780
            from App import App
1781
            # Roll back any change if something goes wrong
1782
            conn.rollback()
1783

  
1784
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1785
                                                           sys.exc_info()[-1].tb_lineno)
1786
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1787
        finally:
1788
            # Close the db connection
1789
            conn.close()
1790

  
1791
    def get_column_names(self, table_name):
1792
        res = []
1793

  
1794
        # Creates or opens a file called mydb with a SQLite3 DB
1795
        conn = sqlite3.connect(self.activeDrawing.path)
1796
        with conn:
1797
            try:
1798
                # Get a cursor object
1799
                cursor = conn.cursor()
1800

  
1801
                sql = "PRAGMA Table_Info ('" + table_name + "')"
1802
                cursor.execute(sql)
1803
                rows = cursor.fetchall()
1804
                for row in rows:
1805
                    res.append(row[1])
1806
            # Catch the exception
1807
            except Exception as ex:
1808
                from App import App
1809

  
1810
                # Roll back any change if something goes wrong
1811
                conn.rollback()
1812

  
1813
                message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
1814
                                                               sys.exc_info()[-1].tb_lineno)
1815
                App.mainWnd().addMessage.emit(MessageType.Error, message)
1816
        return res
1817

  
1766 1818
    '''
1767 1819
        @brief  getter of activeDrawing
1768 1820
        @author humkyung
HYTOS/HYTOS/MainWindow.py
2163 2163
                with open(file_path, 'rb') as file:
2164 2164
                    scripts = file.read().decode('utf-8')
2165 2165
                    app_doc_data.apply_path_data(scripts)
2166

  
2167
            find_column_names = ['Homo_Den', 'Homo_Vel']
2168
            column_names = app_doc_data.get_column_names('PressureVariation')
2169
            for column_name in find_column_names:
2170
                if column_name not in column_names:
2171
                    app_doc_data.add_column(column_name, 'REAL', 'PressureVariation')
2172

  
2166 2173
        except Exception as ex:
2167 2174
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
2168 2175
                      f"{sys.exc_info()[-1].tb_lineno}"

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)