Created
November 2, 2012 12:23
-
-
Save azyobuzin/4001017 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import MySQLdb | |
from wop_core import * | |
class MySqlWrapping: | |
def __init__(self): | |
self.db = MySQLdb.connect(user = db_name, passwd = db_password, db = db_name, charset = "utf8") | |
self.c = db.cursor() | |
def execute(self, query, args = None): | |
self.c.execute(query, args) | |
def fetchone(self, query, args = None): | |
self.execute(query, args) | |
return self.c.fetchone() | |
def fetchall(self, query, args = None): | |
self.execute(query, args) | |
return self.c.fetchall() | |
def commit(self): | |
self.db.commit() | |
def close(self): | |
self.c.close() | |
self.db.close() | |
def __enter__(self): | |
return self | |
def __exit__(self, exc_type, exc_value, traceback): | |
self.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment