Browse Source

[#67] Delete of a relation is implemented now in LeDataSourceSQL

* The two mandatory arguments of the del_relation method are checked
Roland Haroutiounian 9 years ago
parent
commit
492e2c1c25
1 changed files with 18 additions and 1 deletions
  1. 18
    1
      leobject/datasources/ledatasourcesql.py

+ 18
- 1
leobject/datasources/ledatasourcesql.py View File

@@ -204,7 +204,7 @@ class LeDataSourceSQL(DummyDatasource):
204 204
             #not a rel2type but have some relation attribute
205 205
             raise AttributeError("No relation attributes allowed for non rel2type relations")
206 206
 
207
-        with self.connection() as cur:
207
+        with self.connection as cur:
208 208
             sql = insert(self.datasource_utils.relations_table_name, {'id_sup': lesup.lodel_id, 'id_sub': lesub.lodel_id, 'nature': nature, 'rank': rank, 'depth': depth})
209 209
             if cur.execute(sql) != 1:
210 210
                 raise RuntimeError("Unknow SQL error")
@@ -221,7 +221,24 @@ class LeDataSourceSQL(DummyDatasource):
221 221
     # @param lesup LeObject : a LeObject
222 222
     # @param lesub LeObject : a LeObject
223 223
     # @param nature str|None : The relation nature
224
+    # @return bool
224 225
     def del_relation(self, lesup, lesub, nature=None):
226
+
227
+        if lesup is None or lesub is None:
228
+            raise AttributeError("Missing member(s) of the relation to delete")
229
+        
230
+        delete_params = {'id_sup': lesup.lodel_id, 'id_sub': lesub.lodel_id}
231
+        if nature is not None:
232
+            delete_params['nature'] = nature
233
+
234
+        sql = delete(self.datasource_utils.relations_table_name, delete_params)
235
+
236
+        with self.connection as cur:
237
+            if cur.execute(sql) != 1:
238
+                raise RuntimeError("Unknown SQL Error")
239
+
240
+        return True
241
+
225 242
         raise NotImplementedError()
226 243
 
227 244
     ## @brief Return all relation of a lodel_id given a position and a nature

Loading…
Cancel
Save