Updates the row with the given id.
(self, id, *args, **kwargs)
| 961 | return self._insert_id() |
| 962 | |
| 963 | def update(self, id, *args, **kwargs): |
| 964 | """ Updates the row with the given id. |
| 965 | """ |
| 966 | # Table.update(1, age=3) |
| 967 | # Table.update(1, {"age":3}) |
| 968 | # Table.update(all(filter(field="name", value="Taxi")), age=3) |
| 969 | commit = kwargs.pop("commit", True) # As fieldname, use abs(Table.name, "commit"). |
| 970 | if len(args) == 0 and len(kwargs) == 1 and isinstance(kwargs.get("values"), dict): |
| 971 | kwargs = kwargs["values"] |
| 972 | if len(args) == 1 and isinstance(args[0], dict): |
| 973 | a=args[0]; a.update(kwargs); kwargs=a |
| 974 | kv = ", ".join("`%s`=%s" % (k, self.db.escape(v)) for k, v in kwargs.items()) |
| 975 | q = "update `%s` set %s where %s;" % (self.name, kv, |
| 976 | not isinstance(id, Group) and cmp(self.primary_key, id, "=", self.db.escape) \ |
| 977 | or id.SQL(escape=self.db.escape)) |
| 978 | self.db.execute(q, commit) |
| 979 | |
| 980 | def delete(self, id, commit=True): |
| 981 | """ Removes the row which primary key equals the given id. |