Permalink
Browse files

Support newer MariaDB syntax for column default:

* "DEFAULT current_timestamp()" without precision
* "DEFAULT 0" without quotes around numbers
Closes #68
  • Loading branch information...
ansgarbecker committed Jan 8, 2018
1 parent 26ec06e commit f5d9603549f877e030c166577e67fa3204c20955
Showing with 24 additions and 1 deletion.
  1. +3 −1 source/dbconnection.pas
  2. +21 −0 source/helpers.pas
View
@@ -4999,7 +4999,7 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
// Default value
Col.DefaultType := cdtNothing;
Col.DefaultText := '';
rxCol.Expression := '(NULL|CURRENT_TIMESTAMP(\(\d+\))?|\''[^\'']+\'')(\s+ON\s+UPDATE\s+CURRENT_TIMESTAMP(\(\d+\))?)?';
rxCol.Expression := '(NULL|CURRENT_TIMESTAMP(\(\d*\))?|\''[^\'']+\'')(\s+ON\s+UPDATE\s+CURRENT_TIMESTAMP(\(\d*\))?)?';
if UpperCase(Copy(ColSpec, 1, 14)) = 'AUTO_INCREMENT' then begin
Col.DefaultType := cdtAutoInc;
Col.DefaultText := 'AUTO_INCREMENT';
@@ -5024,6 +5024,8 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
end else begin
Col.DefaultType := cdtText;
Col.DefaultText := ExtractLiteral(ColSpec, '');
if Col.DefaultText.IsEmpty then
Col.DefaultText := RegExprGetMatch('\s*(\S+)', ColSpec, 1, True);
if rxCol.Match[3] <> '' then
Col.DefaultType := cdtTextUpdateTS;
end;
View
@@ -277,6 +277,7 @@ TAppSettings = class(TObject)
function FormatNumber( flt: Double; decimals: Integer = 0; Thousands: Boolean=True): String; Overload;
procedure ShellExec(cmd: String; path: String=''; params: String='');
function getFirstWord(text: String; MustStartWithWordChar: Boolean=True): String;
function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum: Integer; DeleteFromSource: Boolean): String;
function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload;
function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload;
function FormatTimeNumber(Seconds: Cardinal; DisplaySeconds: Boolean): String;
@@ -1012,6 +1013,26 @@ function getFirstWord(text: String; MustStartWithWordChar: Boolean=True): String
end;
function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum: Integer; DeleteFromSource: Boolean): String;
var
rx: TRegExpr;
begin
Result := '';
rx := TRegExpr.Create;
rx.Expression := Expression;
if rx.Exec(Input) then begin
if rx.SubExprMatchCount >= ReturnMatchNum then begin
Result := rx.Match[ReturnMatchNum];
if DeleteFromSource then begin
Delete(Input, rx.MatchPos[ReturnMatchNum], rx.MatchLen[ReturnMatchNum]);
Input := Trim(Input);
end;
end;
end;
rx.Free;
end;
{**
Format a filesize to automatically use the best fitting expression
16 100 000 Bytes -> 16,1 MB

0 comments on commit f5d9603

Please sign in to comment.