From b2aa75938442877a6c70dc1a19db2c6073d917ee Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 17 Jun 2014 00:50:08 +0300 Subject: [PATCH] sqlite3: Reliably detect data query vs modification SQL statements. --- sqlite3/sqlite3.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sqlite3/sqlite3.py b/sqlite3/sqlite3.py index b73fd1db..7c34d13c 100644 --- a/sqlite3/sqlite3.py +++ b/sqlite3/sqlite3.py @@ -89,8 +89,10 @@ class Cursor: self.num_cols = sqlite3_column_count(self.stmnt) print("num_cols", self.num_cols) # If it's not select, actually execute it here - if not sql.startswith("SELECT"): - self.fetchone() + # num_cols == 0 for statements which don't return data (=> modify it) + if not self.num_cols: + v = self.fetchone() + assert v is None def close(self): s = sqlite3_finalize(self.stmnt)