diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-11-04 17:28:26 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-11-04 17:28:26 +0000 |
commit | c38e5d043f3d340f8e3cb3c82d2013739f35fc78 (patch) | |
tree | 9b63eb16b82b53392cbb0fd322836be57022695a /lib/sqlalchemy/databases/postgres.py | |
parent | 3f1e5e213d65375e89a23ecb4d50566c1f34b7b0 (diff) | |
download | sqlalchemy-c38e5d043f3d340f8e3cb3c82d2013739f35fc78.tar.gz |
- Simplified the check for ResultProxy "autoclose without results"
to be based solely on presence of cursor.description.
All the regexp-based guessing about statements returning rows
has been removed [ticket:1212].
Diffstat (limited to 'lib/sqlalchemy/databases/postgres.py')
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 47 |
1 files changed, 6 insertions, 41 deletions
diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index c8abeb6db..69fad230d 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -225,60 +225,25 @@ ischema_names = { 'interval':PGInterval, } +# TODO: filter out 'FOR UPDATE' statements SERVER_SIDE_CURSOR_RE = re.compile( r'\s*SELECT', re.I | re.UNICODE) -SELECT_RE = re.compile( - r'\s*(?:SELECT|FETCH|(UPDATE|INSERT))', - re.I | re.UNICODE) - -RETURNING_RE = re.compile( - 'RETURNING', - re.I | re.UNICODE) - -# This finds if the RETURNING is not inside a quoted/commented values. Handles string literals, -# quoted identifiers, dollar quotes, SQL comments and C style multiline comments. This does not -# handle correctly nested C style quotes, lets hope no one does the following: -# UPDATE tbl SET x=y /* foo /* bar */ RETURNING */ -RETURNING_QUOTED_RE = re.compile( - """\s*(?:UPDATE|INSERT)\s - (?: # handle quoted and commented tokens separately - [^'"$/-] # non quote/comment character - | -(?!-) # a dash that does not begin a comment - | /(?!\*) # a slash that does not begin a comment - | "(?:[^"]|"")*" # quoted literal - | '(?:[^']|'')*' # quoted string - | \$(?P<dquote>[^$]*)\$.*?\$(?P=dquote)\$ # dollar quotes - | --[^\\n]*(?=\\n) # SQL comment, leave out line ending as that counts as whitespace - # for the returning token - | /\*([^*]|\*(?!/))*\*/ # C style comment, doesn't handle nesting - )* - \sRETURNING\s""", re.I | re.UNICODE | re.VERBOSE) - class PGExecutionContext(default.DefaultExecutionContext): - def returns_rows_text(self, statement): - m = SELECT_RE.match(statement) - return m and (not m.group(1) or (RETURNING_RE.search(statement) - and RETURNING_QUOTED_RE.match(statement))) - - def returns_rows_compiled(self, compiled): - return isinstance(compiled.statement, expression.Selectable) or \ - ( - (compiled.isupdate or compiled.isinsert) and "postgres_returning" in compiled.statement.kwargs - ) - def create_cursor(self): - self.__is_server_side = \ + # TODO: coverage for server side cursors + select.for_update() + is_server_side = \ self.dialect.server_side_cursors and \ - ((self.compiled and isinstance(self.compiled.statement, expression.Selectable)) \ + ((self.compiled and isinstance(self.compiled.statement, expression.Selectable) and not self.compiled.statement.for_update) \ or \ ( (not self.compiled or isinstance(self.compiled.statement, expression._TextClause)) and self.statement and SERVER_SIDE_CURSOR_RE.match(self.statement)) ) - if self.__is_server_side: + self.__is_server_side = is_server_side + if is_server_side: # use server-side cursors: # http://lists.initd.org/pipermail/psycopg/2007-January/005251.html ident = "c_%s_%s" % (hex(id(self))[2:], hex(random.randint(0, 65535))[2:]) |