프로젝트

일반

사용자정보

개정판 43920ad9

ID43920ad96c54c21b81f14bf162d7ee037be6a52d
상위 266826fb
하위 344d4fa2

함의성이(가) 일년 이상 전에 추가함

db save delete cascade

Change-Id: I19421c434ddeb5ee3fd3ce19e724b2982fd1d390

차이점 보기:

DTI_PID/DTI_PID/AppDocData.py
3590 3590
        except Exception as ex:
3591 3591
            # Roll back any change if something goes wrong
3592 3592
            conn.rollback()
3593
            print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3594
                                                      sys.exc_info()[-1].tb_lineno))
3593

  
3594
            from App import App
3595
            message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3596
                        f"{sys.exc_info()[-1].tb_lineno}"
3597
            App.mainWnd().addMessage.emit(MessageType.Error, message)
3595 3598

  
3596 3599
    '''
3597 3600
        @brief      delete data list
......
3612 3615
            except Exception as ex:
3613 3616
                # Roll back any change if something goes wrong
3614 3617
                conn.rollback()
3615
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3616
                                                          sys.exc_info()[-1].tb_lineno))
3618

  
3619
                from App import App
3620
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3621
                          f"{sys.exc_info()[-1].tb_lineno}"
3622
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3617 3623

  
3618 3624
    def get_document_name_list(self):
3619 3625
        """ get document name list """
......
3792 3798
            except Exception as ex:
3793 3799
                # Roll back any change if something goes wrong
3794 3800
                conn.rollback()
3795
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3796
                                                          sys.exc_info()[-1].tb_lineno))
3801

  
3802
                from App import App
3803
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3804
                          f"{sys.exc_info()[-1].tb_lineno}"
3805
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3797 3806

  
3798 3807
    '''
3799 3808
        @brief      delete line data list
......
3817 3826
            except Exception as ex:
3818 3827
                # Roll back any change if something goes wrong
3819 3828
                conn.rollback()
3820
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3821
                                                          sys.exc_info()[-1].tb_lineno))
3829

  
3830
                from App import App
3831
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3832
                          f"{sys.exc_info()[-1].tb_lineno}"
3833
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3822 3834

  
3823 3835
    '''
3824 3836
        @brief      delete line data list
......
3843 3855
            except Exception as ex:
3844 3856
                # Roll back any change if something goes wrong
3845 3857
                conn.rollback()
3846
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3847
                                                          sys.exc_info()[-1].tb_lineno))
3858

  
3859
                from App import App
3860
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3861
                          f"{sys.exc_info()[-1].tb_lineno}"
3862
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3848 3863

  
3849 3864
    '''
3850 3865
        @brief      delete equip data list
......
3868 3883
            except Exception as ex:
3869 3884
                # Roll back any change if something goes wrong
3870 3885
                conn.rollback()
3871
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3872
                                                          sys.exc_info()[-1].tb_lineno))
3886

  
3887
                from App import App
3888
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3889
                          f"{sys.exc_info()[-1].tb_lineno}"
3890
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3873 3891

  
3874 3892
    '''
3875 3893
        @brief      delete inst data list
......
3893 3911
            except Exception as ex:
3894 3912
                # Roll back any change if something goes wrong
3895 3913
                conn.rollback()
3896
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3897
                                                          sys.exc_info()[-1].tb_lineno))
3914

  
3915
                from App import App
3916
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3917
                          f"{sys.exc_info()[-1].tb_lineno}"
3918
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3898 3919

  
3899 3920
    '''
3900 3921
        @brief      delete note data list
......
3918 3939
            except Exception as ex:
3919 3940
                # Roll back any change if something goes wrong
3920 3941
                conn.rollback()
3921
                print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3922
                                                          sys.exc_info()[-1].tb_lineno))
3942

  
3943
                from App import App
3944
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
3945
                          f"{sys.exc_info()[-1].tb_lineno}"
3946
                App.mainWnd().addMessage.emit(MessageType.Error, message)
3923 3947

  
3924 3948
    def get_valve_attributes(self):
3925 3949
        """ return valve attributes """
......
3947 3971
                    res = self._valve_attributes
3948 3972
                # Catch the exception
3949 3973
                except Exception as ex:
3950
                    print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3951
                                                               sys.exc_info()[-1].tb_lineno))
3974
                    from App import App
3975
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
3976
                                                                sys.exc_info()[-1].tb_lineno)
3977
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
3952 3978
        else:
3953 3979
            res = self._valve_attributes
3954 3980

  
......
4033 4059
                    res = self._inst_attributes
4034 4060
                # Catch the exception
4035 4061
                except Exception as ex:
4036
                    print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
4037
                                                               sys.exc_info()[-1].tb_lineno))
4062
                    from App import App
4063
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
4064
                                                                sys.exc_info()[-1].tb_lineno)
4065
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
4038 4066
        else:
4039 4067
            res = self._inst_attributes
4040 4068

  
......
4120 4148
                    res = self._note_attributes
4121 4149
                # Catch the exception
4122 4150
                except Exception as ex:
4123
                    print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
4124
                                                               sys.exc_info()[-1].tb_lineno))
4151
                    from App import App
4152
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
4153
                                                                sys.exc_info()[-1].tb_lineno)
4154
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
4125 4155
        else:
4126 4156
            res = self._note_attributes
4127 4157

  
......
4170 4200
    def clearAllDrawingDataFromDatabase(self):
4171 4201
        """ clear all drawing data from database """
4172 4202

  
4173
        drawings = self.getDrawings()
4203
        sql = ''
4174 4204

  
4175 4205
        with self.project.database.connect() as conn:
4176 4206
            try:
......
4270 4300
                                                                    sys.exc_info()[-1].tb_lineno)
4271 4301
                App.mainWnd().addMessage.emit(MessageType.Error, message)
4272 4302

  
4303
    def checkDatabaseCascade(self):
4304
        if self.project.database.db_type == 'SQLite':
4305
            return True
4306
        
4307
        #configs = self.getConfigs('Database', 'Cascade')
4308
        #if 1 == len(configs):
4309
        #    return True
4310
        
4311
        with self.project.database.connect() as conn:
4312
            try:
4313
                # Get a cursor object
4314
                cursor = conn.cursor()
4315
                sql = "select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS where DELETE_RULE ='CASCADE'"
4316
                cursor.execute(sql)
4317
                rows = cursor.fetchall()
4318
                if rows:
4319
                    return True
4320
                else:
4321
                    return False
4322

  
4323
            # Catch the exception
4324
            except Exception as ex:
4325
                from App import App
4326
                message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
4327
                          f"{sys.exc_info()[-1].tb_lineno}"
4328
                App.mainWnd().addMessage.emit(MessageType.Error, message)
4329
        
4330
        return False
4331

  
4332
    def setDatabaseCascade(self):
4333
        # temp not finished
4334
        with self.project.database.connect() as conn:
4335
            try:
4336
                # Get a cursor object
4337
                cursor = conn.cursor()
4338
                sql = "select * from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS "
4339
                cursor.execute(sql)
4340
                rows = cursor.fetchall()
4341
                if rows:
4342
                    return True
4343
                else:
4344
                    return False
4345

  
4346
            # Catch the exception
4347
            except Exception as ex:
4348
                # Roll back any change if something goes wrong
4349
                conn.rollback()
4350

  
4351
                from App import App
4352
                message = 'error occurred({}\\n{}) in {}:{}'.format(repr(ex), sql,
4353
                                                                    sys.exc_info()[-1].tb_frame.f_code.co_filename,
4354
                                                                    sys.exc_info()[-1].tb_lineno)
4355
                App.mainWnd().addMessage.emit(MessageType.Error, message)
4356

  
4273 4357

  
4274 4358
    def saveToDatabase(self, items, rect: QRectF, show_progress=None):
4275 4359
        """ save given items to database """
......
4278 4362
        # delete all datas of current drawing
4279 4363
        drawing_name = self.activeDrawing.name
4280 4364
        drawing_uid = self.activeDrawing.UID
4365
        sql = ''
4366

  
4367
        isCascade = self.checkDatabaseCascade()
4281 4368

  
4282 4369
        queries = {'first': [], 'second': []}
4283 4370
        for item in items:
......
4338 4425
                    sql = "delete from Stream_Line_List where Drawing_UID='{}'".format(drawing_uid)
4339 4426
                    cursor.execute(sql)
4340 4427
                else:
4341
                    sql = f"delete from LINE_DATA_LIST where PNID_NO = '{drawing_name}'" \
4342
                        f"delete from TitleBlockValues where Drawings_UID = '{drawing_uid}'" \
4343
                        f"delete from LineNoAttributes where Components_UID in " \
4344
                        f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4345
                        f"delete from Attributes where Components_UID in " \
4346
                        f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4347
                        f"delete from Associations where Components_UID in " \
4348
                        f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4349
                        f"delete from Points where Components_UID in " \
4350
                        f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4351
                        f"delete from PipeRunItems where PipeRuns_UID in " \
4352
                        f"(select UID from PipeRuns where Drawings_UID='{drawing_uid}')" \
4353
                        f"delete from PipeRuns where Drawings_UID='{drawing_uid}'" \
4354
                        f"delete from Components where Drawings_UID='{drawing_uid}'" \
4355
                        f"delete from Stream_Line_List where Drawing_UID='{drawing_uid}'"
4356
                    cursor.execute(sql)
4428
                    #import timeit
4429
                    #_start = timeit.default_timer()
4430
                    if not isCascade:
4431
                        #print('origin')
4432
                        sql = f"delete from LINE_DATA_LIST where PNID_NO = '{drawing_name}'" \
4433
                            f"delete from TitleBlockValues where Drawings_UID = '{drawing_uid}'" \
4434
                            f"delete from LineNoAttributes where Components_UID in " \
4435
                            f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4436
                            f"delete from Attributes where Components_UID in " \
4437
                            f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4438
                            f"delete from Associations where Components_UID in " \
4439
                            f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4440
                            f"delete from Points where Components_UID in " \
4441
                            f"(select UID from Components where Drawings_UID='{drawing_uid}')" \
4442
                            f"delete from PipeRunItems where PipeRuns_UID in " \
4443
                            f"(select UID from PipeRuns where Drawings_UID='{drawing_uid}')" \
4444
                            f"delete from PipeRuns where Drawings_UID='{drawing_uid}'" \
4445
                            f"delete from Components where Drawings_UID='{drawing_uid}'" \
4446
                            f"delete from Stream_Line_List where Drawing_UID='{drawing_uid}'"
4447
                        cursor.execute(sql)
4448
                        #_stop = timeit.default_timer()
4449
                        #seconds = _stop - _start
4450
                        #print(seconds)
4451
                    else:
4452
                        #print('cascade')
4453
                        sql = f"delete from LINE_DATA_LIST where PNID_NO = '{drawing_name}'" \
4454
                            f"delete from TitleBlockValues where Drawings_UID = '{drawing_uid}'" \
4455
                            f"delete from Components where Drawings_UID='{drawing_uid}'" \
4456
                            f"delete from Stream_Line_List where Drawing_UID='{drawing_uid}'"
4457
                        cursor.execute(sql)
4458
                        #_stop = timeit.default_timer()
4459
                        #seconds = _stop - _start
4460
                        #print(seconds)
4357 4461
                
4358 4462
                progress = 0
4359 4463
                length = len(queries['first']) + len(queries['second'])
DTI_PID/DTI_PID/Scripts/MSSQL/ID2.sql
2240 2240
    UID            NVARCHAR (37) PRIMARY KEY
2241 2241
                                NOT NULL,
2242 2242
    Type           NVARCHAR(MAX)         NOT NULL,
2243
    Components_UID NVARCHAR(37)         REFERENCES Components (UID) 
2243
    Components_UID NVARCHAR(37)         REFERENCES Components (UID) ON DELETE CASCADE 
2244 2244
                                NOT NULL,
2245 2245
    Association    NVARCHAR(37)         REFERENCES Components (UID) 
2246 2246
);
......
2409 2409
CREATE TABLE Attributes (
2410 2410
    UID                 NVARCHAR (37) PRIMARY KEY,
2411 2411
    Components_UID      NVARCHAR (37) NOT NULL
2412
                                     REFERENCES Components (UID),
2412
                                     REFERENCES Components (UID) ON DELETE CASCADE, 
2413 2413
    SymbolAttribute_UID NVARCHAR (37) NOT NULL,
2414 2414
    Value               NVARCHAR (1024),
2415 2415
    Association_UID     NVARCHAR (37) NULL,
......
2911 2911
CREATE TABLE LineNoAttributes (
2912 2912
    UID                NVARCHAR (37) PRIMARY KEY,
2913 2913
    Components_UID     NVARCHAR (37) NOT NULL
2914
                                    REFERENCES Components (UID),
2914
                                    REFERENCES Components (UID) ON DELETE CASCADE, 
2915 2915
    LineProperties_UID NVARCHAR (37) NOT NULL,
2916 2916
    Value              NVARCHAR(MAX),
2917 2917
    UNIQUE (
......
3122 3122
    Drawings_UID NVARCHAR (37) REFERENCES Drawings (UID) 
3123 3123
                              NOT NULL,
3124 3124
    Type         NVARCHAR(MAX),
3125
    Owner        NVARCHAR (37) REFERENCES Components (UID) 
3125
    Owner        NVARCHAR (37) REFERENCES Components (UID) ON DELETE CASCADE 
3126 3126
                              NOT NULL,
3127 3127
    [Index]      INTEGER      NOT NULL
3128 3128
);
......
3134 3134
    PipeRuns_UID   NVARCHAR (37) REFERENCES PipeRuns (UID) 
3135 3135
                                NOT NULL,
3136 3136
    [Index]        INTEGER      NOT NULL,
3137
    Components_UID NVARCHAR (37) REFERENCES Components (UID) 
3137
    Components_UID NVARCHAR (37) REFERENCES Components (UID) ON DELETE CASCADE 
3138 3138
                                NOT NULL
3139 3139
);
3140 3140

  
......
3166 3166
    CONSTRAINT FK_Components_UID FOREIGN KEY (
3167 3167
        Components_UID
3168 3168
    )
3169
    REFERENCES Components (UID),
3169
    REFERENCES Components (UID) ON DELETE CASCADE, 
3170 3170
    UNIQUE (
3171 3171
        Components_UID,
3172 3172
        [Index]
......
3276 3276
	[Y]	REAL DEFAULT (0),
3277 3277
	[Width]	REAL DEFAULT (0),
3278 3278
	[Height]	REAL DEFAULT (0),
3279
	FOREIGN KEY([Drawings_UID]) REFERENCES [Drawings]([UID]) ON DELETE CASCADE,
3279
	-- FOREIGN KEY([Drawings_UID]) REFERENCES [Drawings]([UID]) ON DELETE CASCADE,
3280
    FOREIGN KEY([Drawings_UID]) REFERENCES [Drawings]([UID]),
3280 3281
	PRIMARY KEY([Drawings_UID])
3281 3282
);
3282 3283

  
......
3315 3316
	[To_Component_UID] NVARCHAR ( 37 ), 
3316 3317
	[Stream_No] NVARCHAR ( 100 ), 
3317 3318
	[Case] NVARCHAR ( 100 ), 
3318
	FOREIGN KEY([Drawing_UID]) REFERENCES [Drawings]([UID]) ON DELETE CASCADE, 
3319
	-- FOREIGN KEY([Drawing_UID]) REFERENCES [Drawings]([UID]) ON DELETE CASCADE, 
3320
    FOREIGN KEY([Drawing_UID]) REFERENCES [Drawings]([UID]), 
3319 3321
	PRIMARY KEY([UID])
3320 3322
);
3321 3323

  
......
3335 3337
	[Value]	NVARCHAR ( 37 ),
3336 3338
	[Case]	NVARCHAR ( 37 ),
3337 3339
	PRIMARY KEY([UID]),
3338
	FOREIGN KEY([Stream_No_UID]) REFERENCES [Stream_No]([UID]) ON DELETE CASCADE,
3339
	FOREIGN KEY([HMB_LIST_UID]) REFERENCES [HMB_LIST]([UID]) ON DELETE CASCADE
3340
	-- FOREIGN KEY([Stream_No_UID]) REFERENCES [Stream_No]([UID]) ON DELETE CASCADE,
3341
	-- FOREIGN KEY([HMB_LIST_UID]) REFERENCES [HMB_LIST]([UID]) ON DELETE CASCADE
3342
    FOREIGN KEY([Stream_No_UID]) REFERENCES [Stream_No]([UID]),
3343
	FOREIGN KEY([HMB_LIST_UID]) REFERENCES [HMB_LIST]([UID])
3340 3344
);
3341 3345

  
3342 3346
CREATE TABLE Stream_Line_List (
......
3354 3358
	[Stream_No]	NVARCHAR ( 100 ),
3355 3359
	[Case]	NVARCHAR ( 100 ),
3356 3360
	[Index]	INTEGER,
3357
	FOREIGN KEY([Drawing_UID]) REFERENCES [Drawings]([UID]) ON DELETE CASCADE,
3361
	-- FOREIGN KEY([Drawing_UID]) REFERENCES [Drawings]([UID]) ON DELETE CASCADE,
3362
    FOREIGN KEY([Drawing_UID]) REFERENCES [Drawings]([UID]),
3358 3363
	PRIMARY KEY([UID])
3359 3364
);

내보내기 Unified diff

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