|
@@ -139,29 +139,34 @@ class LeDataSourceSQL(DummyDatasource):
|
139
|
139
|
# @param rel_filters list : List of relationnal filters (see @ref leobject_filters)
|
140
|
140
|
# @param **datas : Datas in kwargs
|
141
|
141
|
# @return the number of updated components
|
|
142
|
+ # @todo implement other filters than lodel_id
|
142
|
143
|
def update(self, target_cls, filters, rel_filters, **datas):
|
143
|
|
- query_table_name = self.datasource_utils.get_table_name_from_class(target_cls.__name__)
|
144
|
|
- prep_filters = self._prepare_filters(filters, query_table_name)
|
145
|
|
- set_data = datas
|
146
|
|
- if rel_filters is not None:
|
147
|
|
- prep_rel_filters = self._prepare_rel_filters(rel_filters)
|
148
|
|
- for prep_rel_filter in prep_rel_filters:
|
149
|
|
- query += "%s INNER JOIN %s ON (%s.%s = %s.%s)" % (
|
150
|
|
- self.datasource_utils.relations_table_name,
|
151
|
|
- query_table_name,
|
152
|
|
- self.datasource_utils.relations_table_name,
|
153
|
|
- prep_rel_filter['position'],
|
154
|
|
- query_table_name,
|
155
|
|
- self.datasource_utils.field_lodel_id
|
156
|
|
- )
|
|
144
|
+ print(target_cls, filters, rel_filters, datas)
|
|
145
|
+ # it is a LeType
|
|
146
|
+ if not target_cls.is_letype():
|
|
147
|
+ raise AttributeError("'%s' is not a LeType, it is not possible to update it" % target_cls)
|
157
|
148
|
|
158
|
|
- if prep_rel_filter['condition_key'][0] is not None:
|
159
|
|
- prep_filters[("%s.%s" % (self.datasource_utils.relations_table_name, prep_rel_filter['condition_key'][0]), prep_rel_filter['condition_key'][1])] = prep_rel_filter['condition_value']
|
|
149
|
+ # find main table and main table datas
|
|
150
|
+ main_table = self.datasource_utils.objects_table_name
|
|
151
|
+ main_datas = {self.datasource_utils.field_lodel_id: raw(self.datasource_utils.field_lodel_id)} # be sure to have one SET clause
|
|
152
|
+ for main_column_name in common_fields:
|
|
153
|
+ if main_column_name in datas:
|
|
154
|
+ main_datas[main_column_name] = datas[main_column_name]
|
|
155
|
+ del(datas[main_column_name])
|
160
|
156
|
|
161
|
|
- query = update(table=query_table_name, where=prep_filters, set=set_data)
|
162
|
|
- with self.connection as cur:
|
163
|
|
- result = cur.execute(query)
|
164
|
|
- return result
|
|
157
|
+ wheres = {(name, op):value for name,op,value in filters}
|
|
158
|
+ query = update(main_table, wheres, main_datas)
|
|
159
|
+ #print(query)
|
|
160
|
+ self.datasource_utils.query(self.connection, query)
|
|
161
|
+
|
|
162
|
+ # update on class table
|
|
163
|
+ if datas:
|
|
164
|
+ class_table = self.datasource_utils.get_table_name_from_class(target_cls._leclass.__name__)
|
|
165
|
+ query = update(class_table, wheres, datas)
|
|
166
|
+ #print(query)
|
|
167
|
+ self.datasource_utils.query(self.connection, query)
|
|
168
|
+
|
|
169
|
+ return True
|
165
|
170
|
|
166
|
171
|
## @brief inserts a new lodel editorial component
|
167
|
172
|
# @param target_cls LeCrud(class) : The component class concerned by the insert (a LeCrud child class (not instance !) )
|