Skip to content
Permalink
Browse files

Issue #12: restore compatibility to MySQL pre-5.0 servers, which have…

… no IS.columns table
  • Loading branch information
ansgarbecker committed Jan 9, 2020
1 parent 16b81ab commit c6b4e3e7c4a786e895bfba8ec1662e65a8fc9512
Showing with 55 additions and 0 deletions.
  1. +55 −0 source/dbconnection.pas
@@ -524,6 +524,7 @@ TMySQLConnection = class(TDBConnection)
property LastRawResults: TMySQLRawResults read FLastRawResults;
function MaxAllowedPacket: Int64; override;
function ExplainAnalyzer(SQL, DatabaseName: String): Boolean; override;
function GetTableColumns(Table: TDBObject): TTableColumnList; override;
function GetTableKeys(Table: TDBObject): TTableKeyList; override;
end;

@@ -4730,6 +4731,60 @@ function TDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
end;


function TMySQLConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
var
TableIdx: Integer;
ColQuery: TDBQuery;
Col: TTableColumn;
DefText, ExtraText: String;
begin
TableIdx := InformationSchemaObjects.IndexOf('columns');
if TableIdx > -1 then begin
Result := inherited;
Exit;
end;
// Fallback for old MySQL pre-5.0 servers
Result := TTableColumnList.Create(True);
ColQuery := GetResults('SHOW FULL COLUMNS FROM '+QuoteIdent(Table.Database)+'.'+QuoteIdent(Table.Name));
while not ColQuery.Eof do begin
Col := TTableColumn.Create(Self);
Result.Add(Col);
Col.Name := ColQuery.Col(0);
Col.OldName := Col.Name;
Col.ParseDatatype(ColQuery.Col('Type'));
Col.Collation := ColQuery.Col('Collation');
if Col.Collation.ToLower = 'null' then
Col.Collation := '';
Col.AllowNull := ColQuery.Col('Null').ToLower = 'yes';

DefText := ColQuery.Col('Default');
ExtraText := ColQuery.Col('Extra');
Col.OnUpdateType := cdtNothing;
if ExecRegExpr('^auto_increment$', ExtraText.ToLower) then begin
Col.DefaultType := cdtAutoInc;
Col.DefaultText := 'AUTO_INCREMENT';
end else if ColQuery.IsNull('Default') then begin
Col.DefaultType := cdtNull;
end else if Col.DataType.Category in [dtcText, dtcBinary, dtcTemporal, dtcOther] then begin
Col.DefaultType := cdtText;
Col.DefaultText := DefText;
end else begin
Col.DefaultType := cdtExpression;
Col.DefaultText := DefText;
end;
Col.OnUpdateText := RegExprGetMatch('^on update (.*)$', ExtraText, 1);
if not Col.OnUpdateText.IsEmpty then begin
Col.OnUpdateType := cdtExpression;
end;

Col.Comment := ColQuery.Col('Comment');
ColQuery.Next;
end;
ColQuery.Free;
end;



function TSQLiteConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
var
ColQuery: TDBQuery;

0 comments on commit c6b4e3e

Please sign in to comment.
You can’t perform that action at this time.