Installation guide
7. mxODBC Cursor Objects
Depending on the current
.paramstyle setting, parameters must be
provided as sequence
14
or mapping:
'qmark'(default)
With the 'qmark' parameter style (default) a sequence is expected and
parameters be bound to variables found in the
sqlcmd string on a
positional basis. Variables in the
sqlcmd string are specified using the
ODBC variable question mark placeholder
'?', e.g. 'SELECT name,id
FROM table WHERE amount > ? AND amount < ?',
and get bound in
the order they appear in the SQL statement
sqlcmd from left to right.
'named'
With 'named' parameter style a mapping is expected and parameters be
bound to variables found in the
sqlcmd string based on the values of the
referenced named entries in the mapping. Variables in the
sqlcmd string
are specified using the Oracle style variable marks placeholder
':name',
e.g.
'SELECT name,id FROM table WHERE amount > :minamount AND
amount < :maxamount',
and get bound to the values defined in the
parameters mapping. It is possible to use multiple references to the same
named parameter in
sqlcmd.
A reference to the
sqlcmd string will be retained by the cursor and made
available to Python as
cursor.command. If the same sqlcmd object is passed
in again, the cursor will optimize its behavior by reusing the previously
prepared statement. This is most effective for algorithms where the same
sqlcmd is used, but different parameters are bound to it, e.g. in loops iterating
over input data items.
Use
.executemany()if you want to apply the sqlcmd to a sequence or
iterator/generator of parameters in one call, e.g. to insert multiple rows in a
single call.
sqlcmd may be a Unicode object in case the ODBC driver and/or database
support this.
direct specifies whether to use direct, unprepared execution or not (see
.executedirect() for details). It defaults to -1, meaning that direct execution
is used if no parameters are given, non-direct otherwise.
If
parametertypes is given, it defines the parameter types of the parameters
used in the
sqlcmd. The sequence has to provide one integer entry per
parameter. Possible values are
SQL.PARAM_INPUT (input parameter), SQL.
PARAM_OUTPUT
(output parameter) and SQL.PARAM_INPUT_OUTPUT
(input/output parameter). If
parametertypes is not given, default is to assume
input parameter types for all parameters. Please see section 5.6 Stored
Procedures for more details on how to use this parameter.
14
Note that in mxODBC 3.0 and earlier, the .execute() methods used to work like
.executemany() when passing a list of tuples as parameter (a feature inherited from
Python DB-API 1.0). Starting with mxODBC 3.1 this behavior was removed to avoid
confusion.
105