Cursor.execute

Execute a SQL query against the database.

For an overview see page Python Cursor Class

Prototype

 
    Cursor.execute(query [,args])
 

Arguments

query The select statement to be executed
args A tuple of one or more parameters to be inserted wherever a question mark appears in the query string.

Description

This method executes a SQL query against the database. This is a DB API compliant call. Parameters are substituted using question marks, e.g. "SELECT name FROM table WHERE id=?". The parameter args is a tuple. It returns None on success or raises an exception in the case of an error.

Returns

None The query was executed successfully

Example

     
    conn = db.connect()
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM Metatable WHERE TableName='%s'" % clsname)
    res = cursor.fetchall()
    ...
    cursor.close()
    conn.rollback()