129 w(dropschema2sql(schema, prefix=SQL_PREFIX, |
129 w(dropschema2sql(schema, prefix=SQL_PREFIX, |
130 skip_entities=skip_entities, |
130 skip_entities=skip_entities, |
131 skip_relations=skip_relations)) |
131 skip_relations=skip_relations)) |
132 return '\n'.join(output) |
132 return '\n'.join(output) |
133 |
133 |
134 try: |
|
135 from mx.DateTime import DateTimeType, DateTimeDeltaType |
|
136 except ImportError: |
|
137 DateTimeType = DateTimeDeltaType = None |
|
138 |
134 |
139 class SQLAdapterMixIn(object): |
135 class SQLAdapterMixIn(object): |
140 """Mixin for SQL data sources, getting a connection from a configuration |
136 """Mixin for SQL data sources, getting a connection from a configuration |
141 dictionary and handling connection locking |
137 dictionary and handling connection locking |
142 """ |
138 """ |
197 if not confirm(' [Failed] Continue anyway?', default='n'): |
193 if not confirm(' [Failed] Continue anyway?', default='n'): |
198 raise Exception('Failed command: %s' % cmd) |
194 raise Exception('Failed command: %s' % cmd) |
199 |
195 |
200 def merge_args(self, args, query_args): |
196 def merge_args(self, args, query_args): |
201 if args is not None: |
197 if args is not None: |
202 args = dict(args) |
198 newargs = {} |
203 for key, val in args.items(): |
199 for key, val in args.iteritems(): |
204 # convert cubicweb binary into db binary |
200 # convert cubicweb binary into db binary |
205 if isinstance(val, Binary): |
201 if isinstance(val, Binary): |
206 val = self.binary(val.getvalue()) |
202 val = self.binary(val.getvalue()) |
207 # XXX <3.2 bw compat |
203 newargs[key] = val |
208 elif type(val) is DateTimeType: |
|
209 warn('found mx date time instance, please update to use datetime', |
|
210 DeprecationWarning) |
|
211 val = datetime(val.year, val.month, val.day, |
|
212 val.hour, val.minute, int(val.second)) |
|
213 elif type(val) is DateTimeDeltaType: |
|
214 warn('found mx date time instance, please update to use datetime', |
|
215 DeprecationWarning) |
|
216 val = timedelta(0, int(val.seconds), 0) |
|
217 args[key] = val |
|
218 # should not collide |
204 # should not collide |
219 args.update(query_args) |
205 newargs.update(query_args) |
220 return args |
206 return newargs |
221 return query_args |
207 return query_args |
222 |
208 |
223 def process_result(self, cursor): |
209 def process_result(self, cursor): |
224 """return a list of CubicWeb compliant values from data in the given cursor |
210 """return a list of CubicWeb compliant values from data in the given cursor |
225 """ |
211 """ |