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

Source Code for Package mysql.stmt

 1  # $Header: /home/cvs2/mysql/mysql/stmt/__init__.py,v 1.3 2006/08/26 20:19:52 ehuss Exp $ 
 2  # Copyright (c) 2006, Eric Huss 
 3  # All rights reserved. 
 4  # 
 5  # Redistribution and use in source and binary forms, with or without 
 6  # modification, are permitted provided that the following conditions are met: 
 7  # 
 8  # 1. Redistributions of source code must retain the above copyright notice, 
 9  #    this list of conditions and the following disclaimer. 
10  # 2. Redistributions in binary form must reproduce the above copyright notice, 
11  #    this list of conditions and the following disclaimer in the documentation 
12  #    and/or other materials provided with the distribution. 
13  # 3. Neither the name of Eric Huss nor the names of any contributors may be 
14  #    used to endorse or promote products derived from this software without 
15  #    specific prior written permission. 
16  # 
17  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
18  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
19  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
20  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
21  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
22  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
23  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
24  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
25  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
26  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
27  # POSSIBILITY OF SUCH DAMAGE. 
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