writequery (function)

fundamentals.mysql.writequery(log, sqlQuery, dbConn, Force=False, manyValueList=False)[source][source]

Execute a MySQL write command given a sql query

Key Arguments

  • sqlQuery – the MySQL command to execute

  • dbConn – the db connection

  • Force – do not exit code if error occurs, move onto the next command

  • manyValueList – a list of value tuples if executing more than one insert

Return

  • message – error/warning message

Usage

Here’s an example of how to create a table using the database connection passed to the function:

``python from fundamentals.mysql import writequery sqlQuery = “CREATE TABLE `testing_table (id INT NOT NULL, PRIMARY KEY (id))” message = writequery(

log=log, sqlQuery=sqlQuery, dbConn=dbConn, Force=False, manyValueList=False

)

Here’s a many value insert example:

```python from fundamentals.mysql import writequery sqlQuery = “INSERT INTO testing_table (id) values (%s)” message = writequery(

log=log, sqlQuery=sqlQuery, dbConn=dbConn, Force=False, manyValueList=[(1,), (2,), (3,), (4,), (5,), (6,), (7,),

(8,), (9,), (10,), (11,), (12,), ]

)