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 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 }