From 3cb7f8ecafe0487f78aba90327da187ea2bbfa37 Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 19 Feb 2013 21:18:28 +0000 Subject: [PATCH] Sql: MassInsert now allows empty EndRow (with possible delete) #409 git-svn-id: svn://ultimatepp.org/upp/trunk@5841 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Sql/MassInsert.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/uppsrc/Sql/MassInsert.cpp b/uppsrc/Sql/MassInsert.cpp index 0ca694970..1a2641f7a 100644 --- a/uppsrc/Sql/MassInsert.cpp +++ b/uppsrc/Sql/MassInsert.cpp @@ -29,6 +29,8 @@ SqlMassInsert& SqlMassInsert::operator()(SqlId col, const Value& val) SqlMassInsert& SqlMassInsert::EndRow(SqlBool remove) { cache.Top().remove = remove; + if(pos == 0) + return *this; if(cache.GetCount() && cache[0].value.GetCount() * cache.GetCount() > 5000) Flush(); ASSERT(column.GetCount() == pos); @@ -66,15 +68,17 @@ void SqlMassInsert::Flush() insert << ") values "; for(int i = 0; i < cache.GetCount(); i++) { Row& r = cache[i]; - if(i) - insert << ", "; - insert << "("; - for(int i = 0; i < r.value.GetCount(); i++) { + if(r.value.GetCount()) { if(i) insert << ", "; - insert << SqlCompile(dialect, SqlFormat(r.value[i])); + insert << "("; + for(int i = 0; i < r.value.GetCount(); i++) { + if(i) + insert << ", "; + insert << SqlCompile(dialect, SqlFormat(r.value[i])); + } + insert << ")"; } - insert << ")"; } } else @@ -95,7 +99,7 @@ void SqlMassInsert::Flush() bool nextsel = false; for(int i = ii; i < cache.GetCount(); i++) { Row& r = cache[i]; - if(r.nulls == nulls) { + if(r.nulls == nulls && r.value.GetCount()) { r.nulls = DONE; if(nextsel) insert << " union all";