Exemplo n.º 1
0
 def delete(self, table, where=None):
     # read only check
     self._check_write_ok()
     # gen sql
     sql, values = sqlgen.delete(
         table, where, self.dialect, self.paramstr
         )
     # execute sql
     cursor = self._execute(sql, values)
     rowcount = cursor.rowcount
     return rowcount
Exemplo n.º 2
0
 def test(self):
     # AutoIdCol
     sql, values = sqlgen.delete(Foo, Foo.q.foo_id == 2, sqlgen.DIALECT_SQLITE, "?")
     self.assertEquals("DELETE FROM foo WHERE foo_id=?", sql)
     self.assertEquals([2], values)
     # UnicodeCol
     sql, values = sqlgen.delete(Foo, Foo.q.i1 == 32, sqlgen.DIALECT_MYSQL, "%s")
     self.assertEquals("DELETE FROM foo WHERE i1=%s", sql)
     self.assertEquals([32], values)
     # IntCol AND UnicodeCol
     sql, values = sqlgen.delete(Foo, AND(Foo.q.i1 == 12, Foo.q.s1 == "aeiou"), sqlgen.DIALECT_MYSQL, "?")
     self.assertEquals("DELETE FROM foo WHERE i1=? AND s1=?", sql)
     self.assertEquals([12, "aeiou"], values)
     # IntCol AND DateCol / NULL
     sql, values = sqlgen.delete(Bar, AND(Bar.q.bi == 12, Bar.q.bd == None), sqlgen.DIALECT_MYSQL, "%s")
     self.assertEquals("DELETE FROM bar WHERE bi=%s AND bd is NULL", sql)
     self.assertEquals([12], values)
     # IntCol OR UnicodeCol
     sql, values = sqlgen.delete(Foo, OR(Foo.q.i1 == 12, Foo.q.s1 == "aeiou"), sqlgen.DIALECT_SQLITE, "?")
     self.assertEquals("DELETE FROM foo WHERE i1=? OR s1=?", sql)
     self.assertEquals([12, "aeiou"], values)
Exemplo n.º 3
0
 def test_bad_values(self):
     try:
         sqlgen.delete(Foo, Foo.q.i1 == "xyz", sqlgen.DIALECT_SQLITE, "?")
     except TypeError, e:
         self.assertEquals("IntCol 'i1': int expected, got str", str(e))
Exemplo n.º 4
0
 def test_no_where(self):
     sql, values = sqlgen.delete(Foo, None, True, "?")
     self.assertEquals("DELETE FROM foo", sql)
     self.assertEquals([], values)