mysqlwrapper-python

A Python library that converts a class in a MySQL connection
Download

mysqlwrapper-python Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Rodrigo Fuentealba
  • Publisher web site:
  • http://github.com/rfc83/

mysqlwrapper-python Tags


mysqlwrapper-python Description

mysqlwrapper-python is a Python wrapper for connecting with MySQLdb.I wrote this class for convenience, because it did not feel natural for me to connect with Python DB API. Also, I wanted something that I could extend.Standalone usageYou have to include the mysqlwrapper class: from mysqlwrapper import mysqlwrapperThen, call the wrapper: wrapper = mysqlwrapper()Configure a connection. These are the supported parameters: wrapper.configure_connection({ "host": "localhost", "port": 3306, "db": "fidelizador", "user": "root", "passwd": "", "use_unicode": True, "charset": "utf8", "compress": False, "cursor": "DictCursor", })Cursor can also be "Cursor".If you want to execute a SELECT, you must capture an exception: try: wrapper.execute_select("SELECT version()") except Exception, e: print e.messageThe following is a list of methods: wrapper.execute_insert("your insert statement") wrapper.execute_update("your update statement") wrapper.execute_delete("your delete statement") wrapper.execute_select_one("your select statement") wrapper.execute_many("your statement", params=dict())To pass a query with parameters, it must be in the following form: sql = "SELECT a, b FROM table WHERE id = %d" % table_idThe execute_many function does not require it, though. It can justbe written in the following form: sql = "INSERT INTO table (f1, f2) VALUES (%d, %d)"And the parameters are in a list. For the query above: ((1, 2), (1, 3), (1, 4))Usage as an extended classAs long as you don't touch the execute_* functions, it is pretty much the same thing. Also, you can define your own way to receive parameters and add these to the class.SourceThe source can be browsed at http://github.com/rfc83/mysqlwrapper-pythonProduct's homepage


mysqlwrapper-python Related Software