From 76aa605d337b4bb1124d497ff49acec0c6bb9784 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Thu, 3 Oct 2013 04:16:39 +0000 Subject: [PATCH] Shorten long SELECT query in data grid, using '*' when all columns are involved. --- source/main.pas | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/main.pas b/source/main.pas index d3bc2508..01531f88 100644 --- a/source/main.pas +++ b/source/main.pas @@ -4486,7 +4486,7 @@ var vt: TVirtualStringTree; Select: String; RefreshingData, IsKeyColumn: Boolean; - i, Offset, ColLen, ColWidth, VisibleColumns, MaximumRows: Integer; + i, Offset, ColLen, ColWidth, VisibleColumns, MaximumRows, FullColumns: Integer; KeyCols, ColWidths, WantedColumnOrgnames: TStringList; WantedColumns: TTableColumnList; c: TTableColumn; @@ -4597,14 +4597,21 @@ begin ngMSSQL: Select := Select + ' LEFT(CAST(' + DBObj.Connection.QuoteIdent(c.Name) + ' AS NVARCHAR('+IntToStr(GRIDMAXDATA)+')), ' + IntToStr(GRIDMAXDATA) + '), '; ngMySQL: Select := Select + ' LEFT(' + DBObj.Connection.QuoteIdent(c.Name) + ', ' + IntToStr(GRIDMAXDATA) + '), '; end; - end else + end else begin Select := Select + ' ' + DBObj.Connection.QuoteIdent(c.Name) + ', '; + Inc(FullColumns); + end; WantedColumns.Add(c); WantedColumnOrgnames.Add(c.Name); end; end; // Cut last comma Delete(Select, Length(Select)-1, 2); + + // Shorten the whole query if all columns are involved + if FullColumns = SelectedTableColumns.Count then + Select := '*'; + // Include db name for cases in which dbtree is switching databases and pending updates are in process Select := Select + ' FROM '+DBObj.QuotedDbAndTableName;