X-Git-Url: https://git.jsancho.org/?p=mojodb.git;a=blobdiff_plain;f=MySQL.py;h=f5f888828b83109b43b41d7b8d109ee066b5742b;hp=39c34354cae256b496811befd649e0042e04f90c;hb=aed397c34f0bcc9eeb12e42256cc47e79e049971;hpb=f63673b9ed08886c9ac1582f94f0e63103985497 diff --git a/MySQL.py b/MySQL.py index 39c3435..f5f8888 100644 --- a/MySQL.py +++ b/MySQL.py @@ -19,7 +19,7 @@ # ############################################################################## -import mojo +import connection import MySQLdb SQL_FIELD_TYPES = { @@ -28,7 +28,7 @@ SQL_FIELD_TYPES = { 'float': 'DOUBLE', } -class Connection(mojo.Connection): +class Connection(connection.Connection): def __init__(self, *args, **kwargs): self._db_con = MySQLdb.connect(*args, **kwargs) self._db_con_autocommit = MySQLdb.connect(*args, **kwargs) @@ -92,7 +92,7 @@ class Connection(mojo.Connection): elif type(field) is dict: return "(%s)" % self._get_sql_query(db_name, field) else: - return "'%s'" % str(field) + return "'%s'" % str(field).replace("'", "''") def _get_sql_query(self, db_name, query): sql = "SELECT " @@ -124,8 +124,8 @@ class Connection(mojo.Connection): vals = [] for k, v in values.iteritems(): keys.append(k) - if type(v) in (str, unicode): - vals.append("'%s'" % v) + if type(v) is str: + vals.append("'%s'" % v.replace("'", "''")) else: vals.append(str(v)) sql = "INSERT INTO `%s`.`%s`(%s) VALUES (%s)" % (db_name, table_name, ",".join(keys), ",".join(vals))