Cursor.execute_many

Execute a SQL query against the database applying a set of parameters.

For an overview see page Python Cursor Class

Prototype

 
    Cursor.execute_many(query [,args])
 

Arguments

query The select statement to be executed
args A list of tuples each containing a set 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 list of tuples each containing a set of one or more parameters. The query will be executed for each set of parameters in the list. 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()
    sql = "INSERT INTO Quote(ikey, symbol, stamp, low, high, open, close, volume) VALUES (?,?,?,?,?,?,?,?)"
    params = []
    for i in xrange(N_QUOTES / 2, N_QUOTES):
        params.append((i, 'AA%s' % i, datetime.datetime(2017, 8, 16, 9, 30+i), 1.0, 4.0, 2.0, 3.0, i*1000))
    cursor.execute_many(sql, params)
    ...
    cursor.close()
    conn.rollback()