equal
deleted
inserted
replaced
19 from cubicweb import Binary, ConfigurationError |
19 from cubicweb import Binary, ConfigurationError |
20 from cubicweb.common.uilib import remove_html_tags |
20 from cubicweb.common.uilib import remove_html_tags |
21 from cubicweb.server import SQL_CONNECT_HOOKS |
21 from cubicweb.server import SQL_CONNECT_HOOKS |
22 from cubicweb.server.utils import crypt_password |
22 from cubicweb.server.utils import crypt_password |
23 |
23 |
|
24 |
24 db.USE_MX_DATETIME = False |
25 db.USE_MX_DATETIME = False |
|
26 SQL_PREFIX = 'cw_' |
|
27 |
25 |
28 |
26 def sqlexec(sqlstmts, cursor_or_execute, withpb=True, delimiter=';'): |
29 def sqlexec(sqlstmts, cursor_or_execute, withpb=True, delimiter=';'): |
27 """execute sql statements ignoring DROP/ CREATE GROUP or USER statements |
30 """execute sql statements ignoring DROP/ CREATE GROUP or USER statements |
28 error. If a cnx is given, commit at each statement |
31 error. If a cnx is given, commit at each statement |
29 """ |
32 """ |
60 w('') |
63 w('') |
61 if text_index: |
64 if text_index: |
62 indexer = get_indexer(driver) |
65 indexer = get_indexer(driver) |
63 w(indexer.sql_grant_user(user)) |
66 w(indexer.sql_grant_user(user)) |
64 w('') |
67 w('') |
65 w(grant_schema(schema, user, set_owner, skip_entities=skip_entities)) |
68 w(grant_schema(schema, user, set_owner, skip_entities=skip_entities, prefix=SQL_PREFIX)) |
66 return '\n'.join(output) |
69 return '\n'.join(output) |
67 |
70 |
68 |
71 |
69 def sqlschema(schema, driver, text_index=True, |
72 def sqlschema(schema, driver, text_index=True, |
70 user=None, set_owner=False, |
73 user=None, set_owner=False, |
81 if text_index: |
84 if text_index: |
82 indexer = get_indexer(driver) |
85 indexer = get_indexer(driver) |
83 w(indexer.sql_init_fti()) |
86 w(indexer.sql_init_fti()) |
84 w('') |
87 w('') |
85 dbhelper = get_adv_func_helper(driver) |
88 dbhelper = get_adv_func_helper(driver) |
86 w(schema2sql(dbhelper, schema, |
89 w(schema2sql(dbhelper, schema, prefix=SQL_PREFIX, |
87 skip_entities=skip_entities, skip_relations=skip_relations)) |
90 skip_entities=skip_entities, skip_relations=skip_relations)) |
88 if dbhelper.users_support and user: |
91 if dbhelper.users_support and user: |
89 w('') |
92 w('') |
90 w(sqlgrants(schema, driver, user, text_index, set_owner, |
93 w(sqlgrants(schema, driver, user, text_index, set_owner, |
91 skip_relations, skip_entities)) |
94 skip_relations, skip_entities)) |
103 w('') |
106 w('') |
104 if text_index: |
107 if text_index: |
105 indexer = get_indexer(driver) |
108 indexer = get_indexer(driver) |
106 w(indexer.sql_drop_fti()) |
109 w(indexer.sql_drop_fti()) |
107 w('') |
110 w('') |
108 w(dropschema2sql(schema, |
111 w(dropschema2sql(schema, prefix=SQL_PREFIX, |
109 skip_entities=skip_entities, skip_relations=skip_relations)) |
112 skip_entities=skip_entities, skip_relations=skip_relations)) |
110 return '\n'.join(output) |
113 return '\n'.join(output) |
111 |
114 |
112 try: |
115 try: |
113 from mx.DateTime import DateTimeType, DateTimeDeltaType |
116 from mx.DateTime import DateTimeType, DateTimeDeltaType |
194 return results |
197 return results |
195 |
198 |
196 |
199 |
197 def preprocess_entity(self, entity): |
200 def preprocess_entity(self, entity): |
198 """return a dictionary to use as extra argument to cursor.execute |
201 """return a dictionary to use as extra argument to cursor.execute |
199 to insert/update an entity |
202 to insert/update an entity into a SQL database |
200 """ |
203 """ |
201 attrs = {} |
204 attrs = {} |
202 eschema = entity.e_schema |
205 eschema = entity.e_schema |
203 for attr, value in entity.items(): |
206 for attr, value in entity.items(): |
204 rschema = eschema.subject_relation(attr) |
207 rschema = eschema.subject_relation(attr) |
213 value = value.getvalue() |
216 value = value.getvalue() |
214 else: |
217 else: |
215 value = crypt_password(value) |
218 value = crypt_password(value) |
216 elif isinstance(value, Binary): |
219 elif isinstance(value, Binary): |
217 value = self.binary(value.getvalue()) |
220 value = self.binary(value.getvalue()) |
218 attrs[str(attr)] = value |
221 attrs[SQL_PREFIX+str(attr)] = value |
219 return attrs |
222 return attrs |
220 |
223 |
221 |
224 |
222 from logging import getLogger |
225 from logging import getLogger |
223 from cubicweb import set_log_methods |
226 from cubicweb import set_log_methods |