My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
Ideas  
Ideas
Updated Jul 28, 2011 by mkleehammer

Performance

SQLNumResultCols On Demand

Currently, SQLNumResultCols and SQLNumResultCols are both called after every execute. However, the actual rowcount is very seldom used, so we could call it the first time Cursor.rowcount is accessed.

We'll probably need to call SQLNumResultCols to find out if there are results to fetch, though we could try to eliminate that if we see that the SQL starts with INSERT or UPDATE.

Comment by daryl_sc...@live.com, Oct 8, 2012

PEP 249 states that an interface may support several different parameter marker formats including 'qmark', 'format', and 'pyformat'. I currently use regular expressions to convert the 'format' and 'pyformat' parameter style to 'qmark' before calling the cursor.execute method.

import re

def qmark_sql(sql):
    pattern = "%(\(\w+\))?s"
    qmark = re.sub(pattern, "?", sql)
    return qmark

The 'pyformat' parameter style must convert a dictionary to a tuple of values for use with the cursor.execute method.

import re

def qmark_param(sql, d):
    items = []
    pattern = "%(\(\w+\))?s"
    for m in re.finditer(pattern, sql):
        # The regular expression group includes the enclosing parenthesis,
        # which are removed by the [1:-1] index range.
        key = m.group(1)[1:-1]
        items.append(d[key])
    return tuple(items)
Powered by Google Project Hosting