Fix recently broken support for views in "Copy table" dialog.

This commit is contained in:
Ansgar Becker
2010-06-16 22:30:03 +00:00
parent 074978be5e
commit c15baee972
2 changed files with 26 additions and 3 deletions

View File

@@ -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;

View File

@@ -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;