Created on Sep 24, 2013
@author: paepcke
Bases: object
Shallow interface to MySQL databases. Some niceties nonetheless. The query() method is an iterator. So:
for result in mySqlObj.query('SELECT * FROM foo'):
print result
Inserts large number of rows into given table. Strategy: write the values to a temp file, then generate a LOAD INFILE LOCAL MySQL command. Execute that command via subprocess.call(). Using a cursor.execute() fails with error ‘LOAD DATA LOCAL is not supported in this MySQL version...’ even though MySQL is set up to allow the op (load-infile=1 for both mysql and mysqld in my.cnf).
Parameters: |
|
---|
Close all cursors that are currently still open.
Create new table, given its name, and schema. The schema is a dict mappingt column names to column types. Example: {‘col1’ : ‘INT’, ‘col2’ : ‘TEXT’}
Parameters: |
|
---|
Delete table safely. No errors
Parameters: | tableName (String) – name of table |
---|
Given a list of items, return a string that preserves MySQL typing. Example: (10, ‘My Poem’) —> ‘10, “My Poem”’ Note that ‘,’.join(map(str,myList)) won’t work: (10, ‘My Poem’) —> ‘10, My Poem’
Parameters: | colVals (<any>) – list of column values destined for a MySQL table |
---|
Execute an arbitrary query, including MySQL directives.
Parameters: | query (String) – query or directive |
---|
Executes arbitrary query that is parameterized as in the Python string format statement. Ex: executeParameterized(‘SELECT %s FROM myTable’, (‘col1’, ‘col3’))
Parameters: |
|
---|
Given a dictionary mapping column names to column values, insert the data into a specified table
Parameters: |
|
---|
Query iterator. Given a query, return one result for each subsequent call.
Parameters: | queryStr (String) – query |
---|
Goes through the iterable. For each element, tries to turn into a string, part of which attempts encoding with the ‘ascii’ codec. Then encountering a unicode char, that char is UTF-8 encoded.
Acts as an iterator! Use like: for element in stringifyList(someList):
print(element)
Parameters: | iterable ([<any>]) – mixture of items of any type, including Unicode strings. |
---|
Delete all table rows. No errors
Parameters: | tableName (String) – name of table |
---|
Update one column with a new value.
Parameters: |
|
---|
Created on Sep 24, 2013
@author: paepcke
Bases: unittest.case.TestCase
o CREATE USER unittest; o CREATE DATABASE unittest;
o GRANT SELECT ON unittest.* TO 'unittest'@'localhost‘; o GRANT INSERT ON unittest.* TO 'unittest'@'localhost‘;o GRANT DROP ON unittest.* TO 'unittest'@'localhost‘; o GRANT CREATE ON unittest.* TO 'unittest'@'localhost‘;