MCPcopy Index your code
hub / github.com/clips/pattern / insert

Method insert

pattern/db/__init__.py:945–961  ·  view source on GitHub ↗

Inserts a new row from the given field parameters, returns id.

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

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.

Callers 6

parse_xmlFunction · 0.45
insertMethod · 0.45
__setitem__Method · 0.45
insertMethod · 0.45
insertMethod · 0.45
insertMethod · 0.45

Calls 9

_insert_idMethod · 0.95
lenFunction · 0.85
popMethod · 0.45
getMethod · 0.45
updateMethod · 0.45
keysMethod · 0.45
escapeMethod · 0.45
valuesMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected