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
1=== modified file 'storm/databases/oracle.py'
2--- storm/databases/oracle.py 2008-11-12 21:03:56 +0000
3+++ storm/databases/oracle.py 2009-05-16 17:20:10 +0000
4@@ -55,6 +55,12 @@
5 install_exceptions(oracle)
6 compile = compile.create_child()
7
8+def alias_names():
9+ ct = 0
10+ while 1:
11+ yield '_%x' % ct
12+ ct += 1
13+
14 @compile.when(type)
15 def compile_type(compile, expr, state):
16 cls_info = get_cls_info(expr)
17@@ -100,6 +106,9 @@
18
19 @compile.when(SetExpr)
20 def compile_set_expr_oracle(compile, expr, state):
21+
22+ names = alias_names()
23+
24 if isinstance(expr, Minus):
25 # Build new set expression without arguments (order_by, etc).
26 new_expr = expr.__class__()
27@@ -124,7 +133,7 @@
28 for i, column in enumerate(columns):
29 if column not in aliases:
30 if isinstance(column, Column):
31- aliases[column] = columns[i] = Alias(column)
32+ aliases[column] = columns[i] = Alias(column, name=names.next())
33 elif isinstance(column, Alias):
34 aliases[column.expr] = column
35 subexpr.columns = columns
36@@ -143,12 +152,14 @@
37 order_by_stmt = Undef
38
39 # Build wrapping select statement.
40- select = Select(SQLRaw("*"), tables=Alias(set_stmt), limit=expr.limit,
41+ select = Select(SQLRaw("*"), tables=Alias(set_stmt, name=names.next()), limit=expr.limit,
42 offset=expr.offset, order_by=order_by_stmt)
43
44 return compile_select(compile, select, state)
45 return compile_set_expr(compile, expr, state)
46
47+
48+
49 @compile.when(Select)
50 def compile_select_oracle(compile, select, state):
51 limit = select.limit
52@@ -156,6 +167,8 @@
53 # make sure limit is Undef'ed
54 select.offset = select.limit = Undef
55
56+ names = alias_names()
57+
58 if select.default_tables is Undef:
59 select.default_tables = ['DUAL']
60
61@@ -170,16 +183,16 @@
62 for i, column in enumerate(columns):
63 if column not in aliases:
64 if isinstance(column, Column):
65- aliases[column] = columns[i] = Alias(column)
66+ aliases[column] = columns[i] = Alias(column, name=names.next())
67 elif isinstance(column, Alias):
68 aliases[column.expr] = column
69 select.columns = columns
70 # /copied from expr.py's compile_set_expr
71 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))
72- select = Select(SQLRaw('*'), tables=Alias(stmt))
73+ select = Select(SQLRaw('*'), tables=Alias(stmt, name=names.next()))
74
75 if (limit is not Undef) and (offset is not Undef):
76- rownum_alias = Alias(SQLRaw('ROWNUM'))
77+ rownum_alias = Alias(SQLRaw('ROWNUM'), name=names.next())
78
79 # if we have an SQLRaw here that is because we are dealing
80 # with a subquery
81@@ -195,7 +208,7 @@
82 select.where = And(select.where, where_expr)
83
84 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))
85- select = Select(SQLRaw('*'), tables=Alias(stmt), where = Gt(rownum_alias, offset))
86+ select = Select(SQLRaw('*'), tables=Alias(stmt, names.next()), where = Gt(rownum_alias, offset))
87 elif limit is not Undef:
88 expr = Le(SQLRaw('ROWNUM'), limit)
89 if select.where is Undef:
90@@ -203,7 +216,7 @@
91 else:
92 select.where = And(select.where, expr)
93 elif offset is not Undef:
94- rownum_alias = Alias(SQLRaw('ROWNUM'))
95+ rownum_alias = Alias(SQLRaw('ROWNUM'), name=names.next())
96
97 # if we have an SQLRaw here that is because we are dealing
98 # with a subquery
99@@ -213,7 +226,7 @@
100 select.columns.append(rownum_alias)
101
102 stmt = SQLRaw("(%s)" % compile_select(compile, select, state))
103- select = Select(SQLRaw('*'), tables=Alias(stmt), where = Gt(rownum_alias, offset))
104+ select = Select(SQLRaw('*'), tables=Alias(stmt, name=names.next()), where = Gt(rownum_alias, offset))
105
106 return compile_select(compile, select, state)
107
108@@ -225,6 +238,10 @@
109 SQLRaw("DEFAULT")))
110 return compile_insert(compile, insert, state)
111
112+@compile.when(Sequence)
113+def compile_sequence_oracle(compile, sequence, state):
114+ return "%s.nextval" % sequence.name
115+
116 class currval(FuncExpr):
117
118 name = "currval"
119@@ -400,7 +417,7 @@
120
121 if isinstance(value, unicode):
122 value = value.encode("UTF-8")
123- elif isinstance(value, str) and isinstance(variable, PickleVariable):
124+ elif isinstance(value, str) and isinstance(param, PickleVariable):
125 value = base64.encodestring(value)
126
127 new_params.append(value)
128@@ -431,7 +448,18 @@
129 (isolation,))
130
131
132- self._dsn = oracle.makedsn(uri.host, uri.port, uri.database)
133+ # Optionally set ORACLE_HOME and TNS_ADMIN environment
134+ # variables for controlling tnsnames.ora lookup
135+ oracle_home = uri.options.get('oracle_home')
136+ if oracle_home:
137+ os.environ['ORACLE_HOME'] = oracle_home
138+ tns_admin = uri.options.get('tns_admin')
139+ if tns_admin:
140+ os.environ['TNS_ADMIN'] = tns_admin
141+
142+ self._dsn = uri.options.get('dsn')
143+ if not self._dsn:
144+ self._dsn = oracle.makedsn(uri.host, uri.port, uri.database)
145 self._username = uri.username
146 self._password = uri.password
147

Subscribers

People subscribed via source and target branches

to all changes: