mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Make views show their data again in data tab. Fixes issue #1515.
This commit is contained in:
@ -228,6 +228,7 @@ type
|
||||
function GetTableSize(Results: TMySQLQuery): Int64;
|
||||
function GetLightness(AColor: TColor): Byte;
|
||||
procedure ParseTableStructure(CreateTable: WideString; Columns: TObjectList=nil; Keys: TObjectList=nil; ForeignKeys: TObjectList=nil);
|
||||
procedure ParseViewStructure(ViewName: WideString; Columns: TObjectList);
|
||||
|
||||
var
|
||||
MainReg : TRegistry;
|
||||
@ -3126,6 +3127,33 @@ begin
|
||||
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 }
|
||||
|
||||
|
@ -6145,9 +6145,16 @@ begin
|
||||
newDbObject := SelectedTable.Text;
|
||||
tabEditor.TabVisible := True;
|
||||
tabData.TabVisible := SelectedTable.NodeType in [lntTable, lntCrashedTable, lntView];
|
||||
if SelectedTable.NodeType in [lntTable, lntCrashedTable, lntView] then
|
||||
SelectedTableCreateStatement := Connection.GetVar('SHOW CREATE TABLE '+Mainform.mask(SelectedTable.Text), 1);
|
||||
ParseTableStructure(SelectedTableCreateStatement, SelectedTableColumns, SelectedTableKeys, SelectedTableForeignKeys);
|
||||
SelectedTableColumns.Clear;
|
||||
SelectedTableKeys.Clear;
|
||||
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
|
||||
actEditObjectExecute(Sender);
|
||||
// When a table is clicked in the tree, and the current
|
||||
|
Reference in New Issue
Block a user