]> git.jsancho.org Git - mojodb.git/blobdiff - MySQL.py
Allow to save dictionaries, lists, tuples, etc, as document ids
[mojodb.git] / MySQL.py
index 39c34354cae256b496811befd649e0042e04f90c..3ee09aef346bea3cb0e46a9bc9a296c5029a4e67 100644 (file)
--- 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 "
@@ -125,7 +125,7 @@ class Connection(mojo.Connection):
         for k, v in values.iteritems():
             keys.append(k)
             if type(v) in (str, unicode):
-                vals.append("'%s'" % v)
+                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))