From 418dc669fc343254a2f8ead7bf42b193cf180b1b Mon Sep 17 00:00:00 2001 From: zxyle Date: Wed, 7 Aug 2019 16:21:24 +0800 Subject: [PATCH] insert last row id --- tinycrud/mysql.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tinycrud/mysql.py b/tinycrud/mysql.py index 96b0822..c347edb 100644 --- a/tinycrud/mysql.py +++ b/tinycrud/mysql.py @@ -44,7 +44,7 @@ def insert(self, tb, doc): fields_sql = ", ".join(fields) values_sql = ", ".join(["%s" for _ in range(len(values))]) sql = f"INSERT INTO `{tb}` ({fields_sql}) VALUES ({values_sql});" - self.execute(sql, values) + return self.execute(sql, values) def insert_many(self, tb, doc_list): """ @@ -79,6 +79,8 @@ def execute(self, sql, data=None): return rows[0] elif len(rows) > 1: return rows + elif len(rows) == 0: + return cursor.lastrowid def create_db(self, db_name=""): """Create Database operation"""