Merge lp:~djfroofy/storm/oracle-support-patches into lp:~kov-alfaiati/storm/oracle-support

Proposed by Drew Smathers
Status: Needs review
Proposed branch: lp:~djfroofy/storm/oracle-support-patches
Merge into: lp:~kov-alfaiati/storm/oracle-support
Diff against target: 146 lines
To merge this branch: bzr merge lp:~djfroofy/storm/oracle-support-patches
Reviewer Review Type Date Requested Status
Storm Developers Pending
Review via email: mp+6649@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Drew Smathers (djfroofy) wrote :

This branch contains patches for the following bug reports:

#377312 play nicely with statement caching by using consistent Aliases in query compilation
#371859 allow dsn to be set in uri options
#309382 add Sequence compilation
#307516 NameError ("variable" should be "param")

Unmerged revisions

278. By Drew Smathers <drew@kieru>

play nicely with statement caching by using consistent Aliases in query compilation [f=377312]

277. By Drew Smathers <drew@kieru>

allow dsn to be set in uri options [f=371859]

276. By Drew Smathers <drew@kieru>

add Sequence compilation to oracle-support [f=309382]

275. By Drew Smathers <drew@kieru>

NameError (param') [f=307516]

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'storm/databases/oracle.py'
--- storm/databases/oracle.py 2008-11-12 21:03:56 +0000
+++ storm/databases/oracle.py 2009-05-16 17:20:10 +0000
@@ -55,6 +55,12 @@
55install_exceptions(oracle)55install_exceptions(oracle)
56compile = compile.create_child()56compile = compile.create_child()
5757
58def alias_names():
59 ct = 0
60 while 1:
61 yield '_%x' % ct
62 ct += 1
63
58@compile.when(type)64@compile.when(type)
59def compile_type(compile, expr, state):65def compile_type(compile, expr, state):
60 cls_info = get_cls_info(expr)66 cls_info = get_cls_info(expr)
@@ -100,6 +106,9 @@
100106
101@compile.when(SetExpr)107@compile.when(SetExpr)
102def compile_set_expr_oracle(compile, expr, state):108def compile_set_expr_oracle(compile, expr, state):
109
110 names = alias_names()
111
103 if isinstance(expr, Minus):112 if isinstance(expr, Minus):
104 # Build new set expression without arguments (order_by, etc).113 # Build new set expression without arguments (order_by, etc).
105 new_expr = expr.__class__()114 new_expr = expr.__class__()
@@ -124,7 +133,7 @@
124 for i, column in enumerate(columns):133 for i, column in enumerate(columns):
125 if column not in aliases:134 if column not in aliases:
126 if isinstance(column, Column):135 if isinstance(column, Column):
127 aliases[column] = columns[i] = Alias(column)136 aliases[column] = columns[i] = Alias(column, name=names.next())
128 elif isinstance(column, Alias):137 elif isinstance(column, Alias):
129 aliases[column.expr] = column138 aliases[column.expr] = column
130 subexpr.columns = columns139 subexpr.columns = columns
@@ -143,12 +152,14 @@
143 order_by_stmt = Undef152 order_by_stmt = Undef
144153
145 # Build wrapping select statement.154 # Build wrapping select statement.
146 select = Select(SQLRaw("*"), tables=Alias(set_stmt), limit=expr.limit,155 select = Select(SQLRaw("*"), tables=Alias(set_stmt, name=names.next()), limit=expr.limit,
147 offset=expr.offset, order_by=order_by_stmt)156 offset=expr.offset, order_by=order_by_stmt)
148157
149 return compile_select(compile, select, state)158 return compile_select(compile, select, state)
150 return compile_set_expr(compile, expr, state)159 return compile_set_expr(compile, expr, state)
151160
161
162
152@compile.when(Select)163@compile.when(Select)
153def compile_select_oracle(compile, select, state):164def compile_select_oracle(compile, select, state):
154 limit = select.limit165 limit = select.limit
@@ -156,6 +167,8 @@
156 # make sure limit is Undef'ed167 # make sure limit is Undef'ed
157 select.offset = select.limit = Undef168 select.offset = select.limit = Undef
158169
170 names = alias_names()
171
159 if select.default_tables is Undef:172 if select.default_tables is Undef:
160 select.default_tables = ['DUAL']173 select.default_tables = ['DUAL']
161174
@@ -170,16 +183,16 @@
170 for i, column in enumerate(columns):183 for i, column in enumerate(columns):
171 if column not in aliases:184 if column not in aliases:
172 if isinstance(column, Column):185 if isinstance(column, Column):
173 aliases[column] = columns[i] = Alias(column)186 aliases[column] = columns[i] = Alias(column, name=names.next())
174 elif isinstance(column, Alias):187 elif isinstance(column, Alias):
175 aliases[column.expr] = column188 aliases[column.expr] = column
176 select.columns = columns189 select.columns = columns
177 # /copied from expr.py's compile_set_expr190 # /copied from expr.py's compile_set_expr
178 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))191 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))
179 select = Select(SQLRaw('*'), tables=Alias(stmt))192 select = Select(SQLRaw('*'), tables=Alias(stmt, name=names.next()))
180193
181 if (limit is not Undef) and (offset is not Undef):194 if (limit is not Undef) and (offset is not Undef):
182 rownum_alias = Alias(SQLRaw('ROWNUM'))195 rownum_alias = Alias(SQLRaw('ROWNUM'), name=names.next())
183196
184 # if we have an SQLRaw here that is because we are dealing197 # if we have an SQLRaw here that is because we are dealing
185 # with a subquery198 # with a subquery
@@ -195,7 +208,7 @@
195 select.where = And(select.where, where_expr)208 select.where = And(select.where, where_expr)
196209
197 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))210 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))
198 select = Select(SQLRaw('*'), tables=Alias(stmt), where = Gt(rownum_alias, offset))211 select = Select(SQLRaw('*'), tables=Alias(stmt, names.next()), where = Gt(rownum_alias, offset))
199 elif limit is not Undef:212 elif limit is not Undef:
200 expr = Le(SQLRaw('ROWNUM'), limit)213 expr = Le(SQLRaw('ROWNUM'), limit)
201 if select.where is Undef:214 if select.where is Undef:
@@ -203,7 +216,7 @@
203 else:216 else:
204 select.where = And(select.where, expr)217 select.where = And(select.where, expr)
205 elif offset is not Undef:218 elif offset is not Undef:
206 rownum_alias = Alias(SQLRaw('ROWNUM'))219 rownum_alias = Alias(SQLRaw('ROWNUM'), name=names.next())
207220
208 # if we have an SQLRaw here that is because we are dealing221 # if we have an SQLRaw here that is because we are dealing
209 # with a subquery222 # with a subquery
@@ -213,7 +226,7 @@
213 select.columns.append(rownum_alias)226 select.columns.append(rownum_alias)
214227
215 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))228 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))
216 select = Select(SQLRaw('*'), tables=Alias(stmt), where = Gt(rownum_alias, offset))229 select = Select(SQLRaw('*'), tables=Alias(stmt, name=names.next()), where = Gt(rownum_alias, offset))
217230
218 return compile_select(compile, select, state)231 return compile_select(compile, select, state)
219232
@@ -225,6 +238,10 @@
225 SQLRaw("DEFAULT")))238 SQLRaw("DEFAULT")))
226 return compile_insert(compile, insert, state)239 return compile_insert(compile, insert, state)
227240
241@compile.when(Sequence)
242def compile_sequence_oracle(compile, sequence, state):
243 return "%s.nextval" % sequence.name
244
228class currval(FuncExpr):245class currval(FuncExpr):
229246
230 name = "currval"247 name = "currval"
@@ -400,7 +417,7 @@
400417
401 if isinstance(value, unicode):418 if isinstance(value, unicode):
402 value = value.encode("UTF-8")419 value = value.encode("UTF-8")
403 elif isinstance(value, str) and isinstance(variable, PickleVariable):420 elif isinstance(value, str) and isinstance(param, PickleVariable):
404 value = base64.encodestring(value)421 value = base64.encodestring(value)
405422
406 new_params.append(value)423 new_params.append(value)
@@ -431,7 +448,18 @@
431 (isolation,))448 (isolation,))
432449
433450
434 self._dsn = oracle.makedsn(uri.host, uri.port, uri.database)451 # Optionally set ORACLE_HOME and TNS_ADMIN environment
452 # variables for controlling tnsnames.ora lookup
453 oracle_home = uri.options.get('oracle_home')
454 if oracle_home:
455 os.environ['ORACLE_HOME'] = oracle_home
456 tns_admin = uri.options.get('tns_admin')
457 if tns_admin:
458 os.environ['TNS_ADMIN'] = tns_admin
459
460 self._dsn = uri.options.get('dsn')
461 if not self._dsn:
462 self._dsn = oracle.makedsn(uri.host, uri.port, uri.database)
435 self._username = uri.username463 self._username = uri.username
436 self._password = uri.password464 self._password = uri.password
437465

Subscribers

People subscribed via source and target branches

to all changes: