Skip to content

Notes of MySQLdb in python

LTaoist edited this page May 22, 2012 · 3 revisions

Documents

API in tornado.database

from https://github.com/facebook/tornado/blob/master/tornado/database.py

def query(self, query, *parameters):
    """Returns a row list for the given query and parameters."""
#
# Notice that can be with para.
# eg: self.query("SELECT * FROM table WHERE tid = %s",tid)
#

def get(self, query, *parameters):
    """Returns the first row returned for the given query."""
# Notice the following in the source code :
#
# if len(rows) > 1:
#            raise Exception("Multiple rows returned for Database.get() query")

def execute(self, query, *parameters):
    """Executes the given query, returning the lastrowid from the query."""
#
# eg.  obj_id = self.execute("INSERT INTO tablename VALUES (%s,%s,%s)",val1,val2,val3)
# 
def execute_lastrowid(self, query, *parameters):
    """Executes the given query, returning the lastrowid from the query."""
def execute_rowcount(self, query, *parameters):
    """Executes the given query, returning the rowcount from the query."""
def executemany(self, query, parameters):
    """Executes the given query against all the given param sequences.
    We return the lastrowid from the query.
    """
def executemany_lastrowid(self, query, parameters):
    """Executes the given query against all the given param sequences.
    We return the lastrowid from the query.
    """
def executemany_rowcount(self, query, parameters):
    """Executes the given query against all the given param sequences.
    We return the rowcount from the query.
    """

paramstyle

String constant stating the type of parameter marker formatting expected by the interface. Set to 'format' = ANSI C printf format codes, e.g. '...WHERE name=%s'. If a mapping object is used for conn.execute(), then the interface actually uses 'pyformat' = Python extended format codes, e.g. '...WHERE name=%(name)s'. However, the API does not presently allow the specification of more than one style in paramstyle.

Note that any literal percent signs in the query string passed to execute() must be escaped, i.e. %%.

Parameter placeholders can only be used to insert column values. They can not be used for other parts of SQL, such as table names, statements, etc.

-- from MySQLdb User's Guide