Make views show their data again in data tab. Fixes issue #1515.

This commit is contained in:
Ansgar Becker
2009-12-09 21:08:38 +00:00
parent 4d7ed2303c
commit 1f1e771fa6
2 changed files with 38 additions and 3 deletions

View File

@ -228,6 +228,7 @@ type
function GetTableSize(Results: TMySQLQuery): Int64; function GetTableSize(Results: TMySQLQuery): Int64;
function GetLightness(AColor: TColor): Byte; function GetLightness(AColor: TColor): Byte;
procedure ParseTableStructure(CreateTable: WideString; Columns: TObjectList=nil; Keys: TObjectList=nil; ForeignKeys: TObjectList=nil); procedure ParseTableStructure(CreateTable: WideString; Columns: TObjectList=nil; Keys: TObjectList=nil; ForeignKeys: TObjectList=nil);
procedure ParseViewStructure(ViewName: WideString; Columns: TObjectList);
var var
MainReg : TRegistry; MainReg : TRegistry;
@ -3126,6 +3127,33 @@ begin
end; end;
procedure ParseViewStructure(ViewName: WideString; Columns: TObjectList);
var
rx: TRegExpr;
Col: TTableColumn;
Results: TMySQLQuery;
begin
// Views reveal their columns only with a SHOW COLUMNS query.
// No keys available in views - SHOW KEYS always returns an empty result
Columns.Clear;
rx := TRegExpr.Create;
rx.Expression := '^(\w+)(\((.+)\))?';
Results := Mainform.Connection.GetResults('SHOW COLUMNS FROM '+Mainform.mask(ViewName));
while not Results.Eof do begin
Col := TTableColumn.Create;
Columns.Add(Col);
Col.Name := Results.Col('Field');
Col.AllowNull := Results.Col('Null') = 'YES';
if rx.Exec(Results.Col('Type')) then begin
Col.DataType := GetDatatypeByName(rx.Match[1]);
Col.LengthSet := rx.Match[2];
end;
Results.Next;
end;
rx.Free;
end;
{ *** TTableColumn } { *** TTableColumn }

View File

@ -6145,9 +6145,16 @@ begin
newDbObject := SelectedTable.Text; newDbObject := SelectedTable.Text;
tabEditor.TabVisible := True; tabEditor.TabVisible := True;
tabData.TabVisible := SelectedTable.NodeType in [lntTable, lntCrashedTable, lntView]; tabData.TabVisible := SelectedTable.NodeType in [lntTable, lntCrashedTable, lntView];
if SelectedTable.NodeType in [lntTable, lntCrashedTable, lntView] then SelectedTableColumns.Clear;
SelectedTableCreateStatement := Connection.GetVar('SHOW CREATE TABLE '+Mainform.mask(SelectedTable.Text), 1); SelectedTableKeys.Clear;
ParseTableStructure(SelectedTableCreateStatement, SelectedTableColumns, SelectedTableKeys, SelectedTableForeignKeys); SelectedTableForeignKeys.Clear;
case SelectedTable.NodeType of
lntTable, lntCrashedTable: begin
SelectedTableCreateStatement := Connection.GetVar('SHOW CREATE TABLE '+Mainform.mask(SelectedTable.Text), 1);
ParseTableStructure(SelectedTableCreateStatement, SelectedTableColumns, SelectedTableKeys, SelectedTableForeignKeys);
end;
lntView: ParseViewStructure(SelectedTable.Text, SelectedTableColumns);
end;
if tabEditor.TabVisible then begin if tabEditor.TabVisible then begin
actEditObjectExecute(Sender); actEditObjectExecute(Sender);
// When a table is clicked in the tree, and the current // When a table is clicked in the tree, and the current