Inserts a new row from the given field parameters, returns id.
(self, *args, **kwargs)
| 943 | return list(self.db.execute("select last_insert_rowid();"))[0][0] or None |
| 944 | |
| 945 | def insert(self, *args, **kwargs): |
| 946 | """ Inserts a new row from the given field parameters, returns id. |
| 947 | """ |
| 948 | # Table.insert(name="Taxi", age=2, type="cat") |
| 949 | # Table.insert({"name":"Fricassée", "age":2, "type":"cat"}) |
| 950 | commit = kwargs.pop("commit", True) # As fieldname, use abs(Table.name, "commit"). |
| 951 | if len(args) == 0 and len(kwargs) == 1 and isinstance(kwargs.get("values"), dict): |
| 952 | kwargs = kwargs["values"] |
| 953 | elif len(args) == 1 and isinstance(args[0], dict): |
| 954 | a=args[0]; a.update(kwargs); kwargs=a |
| 955 | if len(self.default) > 0: |
| 956 | kwargs.update(self.default) |
| 957 | k = ", ".join("`%s`" % k for k in kwargs.keys()) |
| 958 | v = ", ".join(self.db.escape(v) for v in kwargs.values()) |
| 959 | q = "insert into `%s` (%s) values (%s);" % (self.name, k, v) |
| 960 | self.db.execute(q, commit) |
| 961 | return self._insert_id() |
| 962 | |
| 963 | def update(self, id, *args, **kwargs): |
| 964 | """ Updates the row with the given id. |
no test coverage detected