Ejemplo n.º 1
0
 def test_bad_values(self):
     foo = Foo.new()
     foo["foo_id"] = 6
     foo["i1"] = "xyz"
     try:
         sqlgen.update_by_id(Foo, foo, "?")
     except TypeError, e:
         self.assertEquals("IntCol 'i1': int expected, got str", str(e))
Ejemplo n.º 2
0
 def update_by_id(self, table, row):
     # read only check
     self._check_write_ok()
     # gen sql
     sql, values = sqlgen.update_by_id(table, row, self.paramstr)
     # execute sql
     cursor = self._execute(sql, values)
     rc = cursor.rowcount
     if rc == 1:
         return True
     if rc == 0:
         return False
     row_id = values[-1]
     assert False, (
             "update_by_id(): more than 1 row updated", 
             (table.table_name, table.auto_id_col.col_name, row_id, rc)
         )
Ejemplo n.º 3
0
 def test_auto_id(self):
     foo = Foo.new(foo_id=None, i1=25, s1="xyz")
     try:
         sqlgen.update_by_id(Foo, foo, "?")
     except AssertionError, e:
         self.assertEquals("update_by_id(): cannot use None for AutoIdCol", str(e))
Ejemplo n.º 4
0
 def test_no_auto_id_col(self):
     bar = Bar.new(bi=5, bs="abc", bd=datetime.date(2006, 3, 21))
     try:
         sqlgen.update_by_id(Bar, bar, "?")
     except AssertionError, e:
         self.assertEquals("update_by_id(): table 'bar' does not have AutoIdCol", str(e))
Ejemplo n.º 5
0
 def test(self):
     foo = Foo.new(foo_id=4, i1=23, s1="pqr", d1=datetime.date(2006, 5, 4))
     sql, values = sqlgen.update_by_id(Foo, foo, "%s")
     self.assertEquals("UPDATE foo SET i1=%s,s1=%s,d1=%s WHERE foo_id=%s", sql)
     self.assertEquals([23, u"pqr", "2006-05-04", 4], values)