writequery (function) ∞
-
writequery
(log, sqlQuery, dbConn, Force=False, manyValueList=False)[source] ∞ Execute a MySQL write command given a sql query
Key Arguments
sqlQuery
– the MySQL command to executedbConn
– the db connectionForce
– do not exit code if error occurs, move onto the next commandmanyValueList
– 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:
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:
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,), ] )