[CalendarServer-changes] [15169] twext/trunk/twext/enterprise/dal/parseschema.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 7 09:30:40 PDT 2015
Revision: 15169
http://trac.calendarserver.org//changeset/15169
Author: cdaboo at apple.com
Date: 2015-10-07 09:30:40 -0700 (Wed, 07 Oct 2015)
Log Message:
-----------
Handle Oracle style pl/sql create function blocks.
Modified Paths:
--------------
twext/trunk/twext/enterprise/dal/parseschema.py
Modified: twext/trunk/twext/enterprise/dal/parseschema.py
===================================================================
--- twext/trunk/twext/enterprise/dal/parseschema.py 2015-10-06 17:36:59 UTC (rev 15168)
+++ twext/trunk/twext/enterprise/dal/parseschema.py 2015-10-07 16:30:40 UTC (rev 15169)
@@ -763,6 +763,12 @@
This function was written to allow execution of pl/sql during Oracle schema
upgrades.
"""
+
+ # Oracle uses "/" characters at the end of PL/SQL blocks to delineate functions. sqlparse
+ # does not cope with those, so we need to remove them from the stream
+ sqlString = "\n".join([line for line in sqlString.splitlines() if line != "/"])
+
+ # Parse statements and do some additional aggregation
aggregated = ''
inPlSQL = None
parsed = parse(sqlString)
@@ -779,12 +785,23 @@
rex = compile("\n +")
aggregated = rex.sub('\n', aggregated)
yield aggregated.strip()
+ aggregated = ''
continue
aggregated += agg
continue
if inPlSQL is None:
- # if 'begin'.lower() in str(stmt).split()[0].lower():
- if str(stmt).lower().strip().startswith('begin'):
+ test_stmt = str(stmt).lower().strip()
+ # Look for the start of a pl/sql block we need to start aggregation of. Note that
+ # a postgres "create function" statement is properly handled by sqlparse so we
+ # explicitly skip additional aggregation of those (by spotting the $$ delimiter
+ # which Oracle does not use).
+ if (
+ test_stmt.startswith('begin') or
+ (
+ test_stmt.startswith('create function') or
+ test_stmt.startswith('create or replace function')
+ ) and ("$$" not in test_stmt)
+ ):
inPlSQL = True
aggregated += str(stmt)
continue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151007/cbef12a8/attachment.html>
More information about the calendarserver-changes
mailing list