Skip to content

Commit 299666d

Browse files
bmalratmgrojo
authored andcommitted
Fix Returning support (#2854)
See issue #2720.
1 parent 3b84d5a commit 299666d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/RowLoader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ void RowLoader::run ()
203203
void RowLoader::process (Task & t)
204204
{
205205
QString sLimitQuery;
206-
if(query.startsWith("PRAGMA", Qt::CaseInsensitive) || query.startsWith("EXPLAIN", Qt::CaseInsensitive))
206+
if(query.startsWith("PRAGMA", Qt::CaseInsensitive) || query.startsWith("EXPLAIN", Qt::CaseInsensitive) ||
207+
// With RETURNING keyword DELETE,INSERT,UPDATE can return rows
208+
// https://www.sqlite.org/lang_returning.html
209+
query.startsWith("DELETE", Qt::CaseInsensitive) || query.startsWith("INSERT", Qt::CaseInsensitive) ||
210+
query.startsWith("UPDATE", Qt::CaseInsensitive))
207211
{
208212
sLimitQuery = query;
209213
} else {

src/RunSql.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,17 @@ bool RunSql::executeNextStatement()
182182
case SQLITE_ROW:
183183
{
184184
// If we get here, the SQL statement returns some sort of data. So hand it over to the model for display. Don't set the modified flag
185-
// because statements that display data don't change data as well.
185+
// because statements that display data don't change data as well, except if the statement are one of INSERT/UPDATE/DELETE that could
186+
// return datas with the RETURNING keyword.
186187

187188
releaseDbAccess();
188189

189190
lk.lock();
191+
192+
// Set the modified flag to true if the statement was one of INSERT/UPDATE/DELETE triggered by a possible RETURNING keyword.
193+
if (query_type == InsertStatement || query_type == UpdateStatement || query_type == DeleteStatement)
194+
modified = true;
195+
190196
may_continue_with_execution = false;
191197

192198
auto time_end = std::chrono::high_resolution_clock::now();

0 commit comments

Comments
 (0)