mysql.stmt

Package mysql :: Package stmt |
[hide private]
[frames] | no frames]

# Package stmt

source code

MySQL Statement API.

The Statement API is a way to pre-parse a SQL statement on the server-side, and then reuse that SQL statement without requiring the server to reparse it. It also transfers the data as raw binary data, so there does not need to be an intermediate conversion to and from a string (thus the statement API does not use the mysql.conversion code).

A SQL statement is represented by the mysql.stmt.Statement object. Parameters for the statement are stored in a mysql.stmt.bind_in.Input_Bind object. You can simply update the value inside the `Input_Bind` object and re-execute the query. The position in the SQL statement where you want your bound input value to exist is denoted by a question mark. The question marks are processed in left-to-right order.

The results are placed into mysql.stmt.bind_out.Output_Bind objects. You must prepare these objects before you execute the statement.

An example of selecting data would be:

    class bar:

        def __init__(self, connection):
            self.thing = None
            self.foo = None
            self.s = connection.new_statement('SELECT foo FROM bar WHERE thing=?')
            self.s.bind_input(mysql.stmt.bind_in.In_Int(self, 'thing'))
            self.s.bind_output(mysql.stmt.bind_out.Out_Varchar(self, 'foo'))

    b = bar()
    b.thing = 7
    b.s.execute()
    b.s.fetch()
    print b.foo
    b.thing = 8
    b.s.execute()
    b.s.fetch()
    print b.foo

BLOB and TEXT columns can optionally use a streaming API for setting and retrieving information. For input parameters, it automatically sets the bound input value to an object which has a `write` method. For output parameters, it similarly sets the output value to an object with a `read` method.

If you specified `store_result` as False (the default) to the `execute` method, then the results are buffered on the server side. You can have only 1 live unbuffered statement object per connection in this case. If you attempt to execute another statement, then the original statment object will be forcefully closed. This goes for mysql.result.Result objects as well, only one live unbuffered Result or Statement object may exist at one time. Result objects are capable of automatically, forcefully closing Statement objects and vice-versa.

See mysql.stmt.stmt for more detail on the Statement object itself.

See mysql.stmt.bind_in for more detail on binding input values.

See mysql.stmt.bind_out for more detail on binding output values.

Submodules | [hide private]
mysql.stmt.bind_in: MySQL Statement Input Binding. mysql.stmt.bind_out: MySQL Statement Output Binding. mysql.stmt.stmt: MySQL Statement object.

Variables | [hide private]
`` | __version__ = `'$Revision: 1.3 $'`

Variables Details | [hide private]

    ### __version__ Value:
        '$Revision: 1.3 $'