From c15baee9729ff093932744fb0ea4397760f7e7aa Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 16 Jun 2010 22:30:03 +0000 Subject: [PATCH] Fix recently broken support for views in "Copy table" dialog. --- source/copytable.pas | 13 +++++++++++-- source/helpers.pas | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/source/copytable.pas b/source/copytable.pas index af1e46c8..60d28ff3 100644 --- a/source/copytable.pas +++ b/source/copytable.pas @@ -121,15 +121,24 @@ begin if comboDatabase.ItemIndex = -1 then comboDatabase.ItemIndex := 0; - CreateCode := MainForm.Connection.GetVar('SHOW CREATE TABLE '+MainForm.mask(FDBObj.Name), 1); + // Fetch columns and key structures from table or view FColumns.Clear; FKeys.Clear; FForeignKeys.Clear; - ParseTableStructure(CreateCode, FColumns, FKeys, FForeignKeys); + case FDBObj.NodeType of + lntTable: begin + CreateCode := MainForm.Connection.GetVar('SHOW CREATE TABLE '+MainForm.mask(FDBObj.Name), 1); + ParseTableStructure(CreateCode, FColumns, FKeys, FForeignKeys); + end; + lntView: ParseViewStructure(FDBObj.Name, FColumns); + else raise Exception.Create('Neither table nor view: '+FDBObj.Name); + end; + // Reset options tree TreeElements.Clear; TreeElements.RootNodeCount := 4; + // Load recent WHERE clauses from registry into dropdown menu popupRecentFilters.Items.Clear; OpenRegistry; Values := TStringList.Create; diff --git a/source/helpers.pas b/source/helpers.pas index fd15a6f5..01500c2d 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -2696,7 +2696,7 @@ begin Columns.Clear; rx := TRegExpr.Create; rx.Expression := '^(\w+)(\((.+)\))?'; - Results := Mainform.Connection.GetResults('SHOW COLUMNS FROM '+Mainform.mask(ViewName)); + Results := Mainform.Connection.GetResults('SHOW /*!32332 FULL */ COLUMNS FROM '+Mainform.mask(ViewName)); while not Results.Eof do begin Col := TTableColumn.Create; Columns.Add(Col); @@ -2706,6 +2706,20 @@ begin Col.DataType := GetDatatypeByName(rx.Match[1]); Col.LengthSet := rx.Match[3]; end; + Col.Unsigned := (Col.DataType.Category = dtcInteger) and (Pos('unsigned', Results.Col('Type')) > 0); + Col.AllowNull := UpperCase(Results.Col('Null')) = 'YES'; + Col.Collation := Results.Col('Collation', True); + Col.Comment := Results.Col('Comment', True); + if Col.DataType.Category <> dtcTemporal then + Col.DefaultText := Results.Col('Default'); + if Results.IsNull('Default') and Col.AllowNull then + Col.DefaultType := cdtNull + else if Col.DataType.Index = dtTimestamp then + Col.DefaultType := cdtCurTSUpdateTS + else if (Col.DefaultText = '') and Col.AllowNull then + Col.DefaultType := cdtNothing + else + Col.DefaultType := cdtText; Results.Next; end; rx.Free;