Package json_to_relation :: Module mysqldb :: Class MySQLDB
[hide private]
[frames] | no frames]

Class MySQLDB

source code

object --+
         |
        MySQLDB

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
Instance Methods [hide private]
 
__init__(self, host='127.0.0.1', port=3306, user='root', passwd='', db='mysql')
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
close(self)
Close all cursors that are currently still open.
source code
 
createTable(self, tableName, schema)
Create new table, given its name, and schema.
source code
 
dropTable(self, tableName)
Delete table safely.
source code
 
insert(self, tblName, colnameValueDict)
Given a dictionary mapping column names to column values, insert the data into a specified table
source code
 
ensureSQLTyping(self, colVals)
Given a list of items, return a string that preserves MySQL typing.
source code
 
query(self, queryStr)
Query iterator.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, host='127.0.0.1', port=3306, user='root', passwd='', db='mysql')
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

createTable(self, tableName, schema)

source code 

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:
  • tableName (String) - name of new table
  • schema (Dict<String,String>) - dictionary mapping column names to column types

dropTable(self, tableName)

source code 

Delete table safely. No errors

Parameters:
  • tableName (String) - name of table

insert(self, tblName, colnameValueDict)

source code 

Given a dictionary mapping column names to column values, insert the data into a specified table

Parameters:
  • tblName (String) - name of table to insert into
  • colnameValueDict (Dict<String,Any>) - mapping of column name to column value

ensureSQLTyping(self, colVals)

source code 

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

query(self, queryStr)

source code 

Query iterator. Given a query, return one result for each subsequent call.

Parameters:
  • queryStr (String) - query