Beispiel #1
0
 def test_bad_values(self):
     foo = Foo.new()
     foo["foo_id"] = 6
     foo["i1"] = "xyz"
     try:
         sqlgen.update(Foo, foo, Foo.q.i1 == 23, sqlgen.DIALECT_SQLITE, "?")
     except TypeError, e:
         self.assertEquals("IntCol 'i1': int expected, got str", str(e))
Beispiel #2
0
 def test(self):
     foo = Foo.new(foo_id=4, i1=23, s1="pqr", d1=datetime.date(2006, 5, 4))
     bar = Bar.new(
         bi=5, bs="abc", bd=datetime.date(2006, 3, 21), bdt1=datetime.datetime(2005, 11, 22, 0, 43, 12), bb=True
     )
     # no where condition
     sql, values = sqlgen.update(Foo, foo, None, sqlgen.DIALECT_SQLITE, "?")
     self.assertEquals("UPDATE foo SET foo_id=?,i1=?,s1=?,d1=?", sql)
     self.assertEquals([4, 23, u"pqr", "2006-05-04"], values)
     # AutoIdCol
     sql, values = sqlgen.update(Foo, foo, Foo.q.foo_id == 2, sqlgen.DIALECT_MYSQL, "%s")
     self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=%s WHERE foo_id=%s", sql)
     self.assertEquals([4, 23, u"pqr", "2006-05-04", 2], values)
     # IntCol
     sql, values = sqlgen.update(Foo, foo, Foo.q.i1 == 32, sqlgen.DIALECT_SQLITE, "?")
     self.assertEquals("UPDATE foo SET foo_id=?,i1=?,s1=?,d1=? WHERE i1=?", sql)
     self.assertEquals([4, 23, u"pqr", "2006-05-04", 32], values)
     # IntCol AND UnicodeCol
     sql, values = sqlgen.update(Foo, foo, AND(Foo.q.i1 == 12, Foo.q.s1 == "aeiou"), sqlgen.DIALECT_MYSQL, "%s")
     self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=%s WHERE i1=%s AND s1=%s", sql)
     self.assertEquals([4, 23, u"pqr", "2006-05-04", 12, "aeiou"], values)
     # IntCol AND DateCol / NULL
     sql, values = sqlgen.update(Bar, bar, AND(Bar.q.bi == 12, Bar.q.bd == None), sqlgen.DIALECT_SQLITE, "?")
     self.assertEquals("UPDATE bar SET bi=?,bs=?,bd=?,bdt1=?,bb=? WHERE bi=? AND bd is NULL", sql)
     self.assertEquals([5, u"abc", "2006-03-21", "2005-11-22T00:43:12Z", 1, 12], values)
     # IntCol OR UnicodeCol
     sql, values = sqlgen.update(Foo, foo, OR(Foo.q.i1 == 12, Foo.q.s1 == "aeiou"), sqlgen.DIALECT_MYSQL, "%s")
     self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=%s WHERE i1=%s OR s1=%s", sql)
     self.assertEquals([4, 23, u"pqr", "2006-05-04", 12, "aeiou"], values)
     # IntCol OR DateCol / NULL
     sql, values = sqlgen.update(Bar, bar, OR(Bar.q.bi == 12, Bar.q.bd == None), sqlgen.DIALECT_SQLITE, "?")
     self.assertEquals("UPDATE bar SET bi=?,bs=?,bd=?,bdt1=?,bb=? WHERE bi=? OR bd is NULL", sql)
     self.assertEquals([5, u"abc", "2006-03-21", "2005-11-22T00:43:12Z", 1, 12], values)
Beispiel #3
0
 def update(self, table, row, where):
     # read only check
     self._check_write_ok()
     # gen sql
     sql, values = sqlgen.update(
         table, row, where, self.dialect, self.paramstr
         )
     # execute sql
     cursor = self._execute(sql, values)
     rowcount = cursor.rowcount
     return rowcount
Beispiel #4
0
 def test_auto_id(self):
     foo = Foo.new(foo_id=None, i1=25, s1="xyz")
     try:
         sqlgen.update(Foo, foo, Foo.q.i1 == 12, sqlgen.DIALECT_SQLITE, "?")
     except AssertionError, e:
         self.assertEquals("update(): cannot use None for AutoIdCol", str(e))
Beispiel #5
0
 def test_null(self):
     foo = Foo.new(foo_id=4, i1=23, s1="pqr", d1=None)
     sql, values = sqlgen.update(Foo, foo, Foo.q.i1 == 434, sqlgen.DIALECT_MYSQL, "%s")
     self.assertEquals("UPDATE foo SET foo_id=%s,i1=%s,s1=%s,d1=NULL WHERE i1=%s", sql)
     self.assertEquals([4, 23, u"pqr", 434], values)