Package yum :: Module sqlutils
[hide private]
[frames] | no frames]

Module sqlutils

source code

utility functions to handle differences in pysqlite versions These are from Wichert Akkerman <wichert@deephackmode.org>'s python-dhm http://www.wiggy.net/code/python-dhm

Classes [hide private]
  TokenizeError
Tokenizer error class
Functions [hide private]
sequence of strings
Tokenize(str, whitespace=' \t\r\n', quotes='"', escapes='\\')
String tokenizer
source code
tuple with the new command and a dictionary of arguments
QmarkToPyformat(query, params)
Convert from qmark to pyformat parameter style.
source code
 
executeSQLPyFormat(cursor, query, params=None)
Execute a python < 2.5 (external sqlite module) style query.
source code
 
executeSQLQmark(cursor, query, params=None)
Execute a python 2.5 (sqlite3) style query.
source code
 
executeSQL(cursor, query, params=None)
Execute a python 2.5 (sqlite3) style query.
source code
 
sql_esc(pattern)
Apply SQLite escaping, if needed.
source code
 
sql_esc_glob(patterns)
Converts patterns to SQL LIKE format, if required (or gives up if not possible).
source code
Variables [hide private]
  __package__ = 'yum'
Function Details [hide private]

Tokenize(str, whitespace=' \t\r\n', quotes='"', escapes='\\')

source code 

String tokenizer

This function tokenizes a string while taking quotation and escaping into account.

>>> import dhm.strtools
>>> dhm.strtools.Tokenize("this is a test")
['this', 'is', 'a', 'test']
>>> dhm.strtools.Tokenize("this "is a" test")
['this', 'is a', 'test']
>>> dhm.strtools.Tokenize("this \"is\" a test")
['this', '"is"', 'a', 'test']
>>> dhm.strtools.Tokenize("this "is a test")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.2/site-packages/dhm/strtools.py", line 80, in Tokenize
    raise TokenizeError, "Unexpected end of string in quoted text"
dhm.strtools.TokenizeError: Unexecpted end of string in quoted text
Parameters:
  • str (string) - string to tokenize
  • whitespace (string) - whitespace characters seperating tokens
  • quotes (string) - legal quoting characters
  • escapes (string) - characters which can escape quoting characters
Returns: sequence of strings
list of tokens

QmarkToPyformat(query, params)

source code 

Convert from qmark to pyformat parameter style.

The python DB-API 2.0 specifies four different possible parameter styles that can be used by drivers. This function converts from the qmark style to pyformat style.

Parameters:
  • query (string) - SQL query to transform
  • params (sequence of strings) - arguments to query
Returns: tuple with the new command and a dictionary of arguments
converted query and parameters

executeSQLPyFormat(cursor, query, params=None)

source code 

Execute a python < 2.5 (external sqlite module) style query.

Parameters:
  • cursor - A sqlite cursor
  • query - The query to execute
  • params - An optional list of parameters to the query

executeSQLQmark(cursor, query, params=None)

source code 

Execute a python 2.5 (sqlite3) style query.

Parameters:
  • cursor - A sqlite cursor
  • query - The query to execute
  • params - An optional list of parameters to the query

executeSQL(cursor, query, params=None)

source code 

Execute a python 2.5 (sqlite3) style query.

Parameters:
  • cursor - A sqlite cursor
  • query - The query to execute
  • params - An optional list of parameters to the query

sql_esc(pattern)

source code 

Apply SQLite escaping, if needed. Returns pattern and esc.