Skip to content

Commit

Permalink
boulder-oracle-sprint: Fixed unicode bind param handling. Only 3 test…
Browse files Browse the repository at this point in the history
…s fail

now...


git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4085 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
Boulder Sprinters committed Nov 17, 2006
1 parent 677aa10 commit 174463e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 8 additions & 0 deletions django/db/backends/oracle/base.py
Expand Up @@ -74,6 +74,14 @@ class FormatStylePlaceholderCursor(Database.Cursor):
def _rewrite_args(self, query, params=None):
if params is None:
params = []
else:
# cx_Oracle can't handle unicode parameters, so cast to str for now
for i, param in enumerate(params):
if type(param) == unicode:
try:
params[i] = param.encode('utf-8')
except UnicodeError:
params[i] = str(param)
args = [(':arg%d' % i) for i in range(len(params))]
query = query % tuple(args)
# cx_Oracle cannot execute a query with the closing ';'
Expand Down
2 changes: 0 additions & 2 deletions django/db/backends/oracle/creation.py
Expand Up @@ -81,8 +81,6 @@ def destroy_test_db(settings, connection, backend, old_database_name, verbosity=
settings.DATABASE_NAME = old_database_name
#settings.DATABASE_USER = 'old_user'
#settings.DATABASE_PASSWORD = 'old_password'
settings.DATABASE_USER = 'mboersma'
settings.DATABASE_PASSWORD = 'password'

cursor = connection.cursor()
time.sleep(1) # To avoid "database is being accessed by other users" errors.
Expand Down
17 changes: 9 additions & 8 deletions django/db/backends/oracle/query.py
Expand Up @@ -199,14 +199,15 @@ def _get_sql_clause(self):
limit_and_offset_clause = "WHERE rn > %s" % (offset)

if len(limit_and_offset_clause) > 0:
full_query = """SELECT * FROM
(SELECT %s
%s,
ROW_NUMBER() %s AS rn
%s
)
%s
""" % (distinct, select_clause, order_by_clause, " ".join(sql), limit_and_offset_clause)
fmt = \
"""SELECT * FROM
(SELECT %s%s,
ROW_NUMBER()%s AS rn
%s)
%s"""
full_query = fmt % (distinct, select_clause,
order_by_clause, ' '.join(sql).strip(),
limit_and_offset_clause)
else:
full_query = None

Expand Down

0 comments on commit 174463e

Please sign in to comment.