|
@@ -73,7 +73,7 @@ class LeQuery(object):
|
73
|
73
|
self._target_class,
|
74
|
74
|
ret)
|
75
|
75
|
return ret
|
76
|
|
-
|
|
76
|
+
|
77
|
77
|
##@brief Childs classes implements this method to execute the query
|
78
|
78
|
# @param **datas
|
79
|
79
|
# @return query result
|
|
@@ -89,14 +89,8 @@ class LeQuery(object):
|
89
|
89
|
return ret.format(
|
90
|
90
|
classname=self.__class__.__name__,
|
91
|
91
|
target_class = self._target_class)
|
92
|
|
-
|
93
|
92
|
|
94
|
93
|
##@brief Abstract class handling query with filters
|
95
|
|
-#
|
96
|
|
-#@todo add handling of inter-datasource queries
|
97
|
|
-#
|
98
|
|
-#@warning relationnal filters on multiple classes from different datasource
|
99
|
|
-# will generate a lot of subqueries
|
100
|
94
|
class LeFilteredQuery(LeQuery):
|
101
|
95
|
|
102
|
96
|
##@brief The available operators used in query definitions
|
|
@@ -487,8 +481,9 @@ class LeInsertQuery(LeQuery):
|
487
|
481
|
|
488
|
482
|
## @brief Implements an insert query operation, with only one insertion
|
489
|
483
|
# @param new_datas : datas to be inserted
|
490
|
|
- def __query(self, new_datas):
|
491
|
|
- nb_inserted = self._rw_datasource.insert(self._target_class,new_datas)
|
|
484
|
+ def __query(self, datas):
|
|
485
|
+ datas = self._target_class.prepare_datas(datas, True, False)
|
|
486
|
+ nb_inserted = self._rw_datasource.insert(self._target_class,datas)
|
492
|
487
|
if nb_inserted < 0:
|
493
|
488
|
raise LeQueryError("Insertion error")
|
494
|
489
|
return nb_inserted
|
|
@@ -504,9 +499,10 @@ class LeInsertQuery(LeQuery):
|
504
|
499
|
"""
|
505
|
500
|
|
506
|
501
|
## @brief Execute the insert query
|
507
|
|
- def execute(self, new_datas):
|
508
|
|
- return super().execute(new_datas)
|
509
|
|
-
|
|
502
|
+ def execute(self, datas):
|
|
503
|
+ return super().execute(datas = datas)
|
|
504
|
+
|
|
505
|
+
|
510
|
506
|
##@brief A query to update datas for a given object
|
511
|
507
|
class LeUpdateQuery(LeFilteredQuery):
|
512
|
508
|
|
|
@@ -516,19 +512,34 @@ class LeUpdateQuery(LeFilteredQuery):
|
516
|
512
|
def __init__(self, target_class, query_filter):
|
517
|
513
|
super().__init__(target_class, query_filter)
|
518
|
514
|
|
|
515
|
+ ##@brief Called by __query to do severals checks before running the update
|
|
516
|
+ #@warning Optimization issue : each time this method is called we do
|
|
517
|
+ #a LeGetQuery to fetch ALL datas and construct instances for being able to
|
|
518
|
+ #construct datas and check consistency
|
|
519
|
+ #@todo implementation (waiting for LeApi to be plugged to LeQuery)
|
|
520
|
+ def __fetch_construct_check_update(self, filters, rel_filters, datas):
|
|
521
|
+ """
|
|
522
|
+ instances = self._target_class.get(filters, rel_filters)
|
|
523
|
+ for instance in instances:
|
|
524
|
+ instance.check_datas_value(instance.
|
|
525
|
+ """
|
|
526
|
+ pass
|
|
527
|
+
|
|
528
|
+
|
519
|
529
|
##@brief Implements an update query
|
520
|
530
|
#@param filters list : see @ref LeFilteredQuery
|
521
|
531
|
#@param rel_filters list : see @ref LeFilteredQuery
|
522
|
|
- #@param updated_datas dict : datas to update
|
|
532
|
+ #@param datas dict : datas to update
|
523
|
533
|
#@returns the number of updated items
|
524
|
|
- def __query(self, filters, rel_filters, updated_datas):
|
|
534
|
+ def __query(self, filters, rel_filters, datas):
|
|
535
|
+ self.__fetch_construct_check_update(filters, rel_filters, datas)
|
525
|
536
|
nb_updated = self._rw_datasource.update(
|
526
|
|
- self._target_class, filters, rel_filters, update_datas)
|
|
537
|
+ self._target_class, filters, rel_filters, datas)
|
527
|
538
|
return nb_updated
|
528
|
539
|
|
529
|
540
|
## @brief Execute the update query
|
530
|
|
- def execute(self, updated_datas):
|
531
|
|
- return super().execute(updated_datas)
|
|
541
|
+ def execute(self, datas):
|
|
542
|
+ return super().execute(datas = datas)
|
532
|
543
|
|
533
|
544
|
##@brief A query to delete an object
|
534
|
545
|
class LeDeleteQuery(LeFilteredQuery):
|