1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 """MySQL Statement API.
30
31 The Statement API is a way to pre-parse a SQL statement on the server-side, and
32 then reuse that SQL statement without requiring the server to reparse it. It
33 also transfers the data as raw binary data, so there does not need to be an
34 intermediate conversion to and from a string (thus the statement API does not
35 use the `mysql.conversion` code).
36
37 A SQL statement is represented by the `mysql.stmt.Statement` object. Parameters
38 for the statement are stored in a `mysql.stmt.bind_in.Input_Bind` object. You
39 can simply update the value inside the ``Input_Bind`` object and re-execute the
40 query. The position in the SQL statement where you want your bound input value
41 to exist is denoted by a question mark. The question marks are processed in
42 left-to-right order.
43
44 The results are placed into `mysql.stmt.bind_out.Output_Bind` objects. You
45 must prepare these objects before you execute the statement.
46
47 An example of selecting data would be::
48
49 class bar:
50
51 def __init__(self, connection):
52 self.thing = None
53 self.foo = None
54 self.s = connection.new_statement('SELECT foo FROM bar WHERE thing=?')
55 self.s.bind_input(mysql.stmt.bind_in.In_Int(self, 'thing'))
56 self.s.bind_output(mysql.stmt.bind_out.Out_Varchar(self, 'foo'))
57
58 b = bar()
59 b.thing = 7
60 b.s.execute()
61 b.s.fetch()
62 print b.foo
63 b.thing = 8
64 b.s.execute()
65 b.s.fetch()
66 print b.foo
67
68 BLOB and TEXT columns can optionally use a streaming API for setting and
69 retrieving information. For input parameters, it automatically sets the bound
70 input value to an object which has a ``write`` method. For output parameters,
71 it similarly sets the output value to an object with a ``read`` method.
72
73 If you specified ``store_result`` as False (the default) to the ``execute``
74 method, then the results are buffered on the server side. You can have only 1
75 live unbuffered statement object per connection in this case. If you attempt
76 to execute another statement, then the original statment object will be
77 forcefully closed. This goes for `mysql.result.Result` objects as well, only
78 one live unbuffered Result or Statement object may exist at one time. Result
79 objects are capable of automatically, forcefully closing Statement objects and
80 vice-versa.
81
82 See `mysql.stmt.stmt` for more detail on the Statement object itself.
83
84 See `mysql.stmt.bind_in` for more detail on binding input values.
85
86 See `mysql.stmt.bind_out` for more detail on binding output values.
87
88 """
89
90 __version__ = '$Revision: 1.3 $'
91
92 from mysql.stmt.stmt import Statement
93