mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-06 20:23:18 +01:00
* commit patch for various SQL formatting and conversions issues from Mantis #17188 from LacaK2
with some modifications git-svn-id: trunk@17728 -
This commit is contained in:
parent
5b741f3acc
commit
eb3ccbcb1f
@ -96,11 +96,12 @@ type
|
|||||||
FCharSet : string;
|
FCharSet : string;
|
||||||
FRole : String;
|
FRole : String;
|
||||||
|
|
||||||
FSQLServerFormatSettings : TFormatSettings;
|
|
||||||
function GetPort: cardinal;
|
function GetPort: cardinal;
|
||||||
procedure Setport(const AValue: cardinal);
|
procedure Setport(const AValue: cardinal);
|
||||||
protected
|
protected
|
||||||
FConnOptions : TConnOptions;
|
FConnOptions : TConnOptions;
|
||||||
|
FSQLFormatSettings : TFormatSettings;
|
||||||
procedure GetDBInfo(const ASchemaType : TSchemaType; const ASchemaObjectName, AReturnField : string; AList: TStrings);
|
procedure GetDBInfo(const ASchemaType : TSchemaType; const ASchemaObjectName, AReturnField : string; AList: TStrings);
|
||||||
procedure SetTransaction(Value : TSQLTransaction);virtual;
|
procedure SetTransaction(Value : TSQLTransaction);virtual;
|
||||||
function StrToStatementType(s : string) : TStatementType; virtual;
|
function StrToStatementType(s : string) : TStatementType; virtual;
|
||||||
@ -497,6 +498,29 @@ implementation
|
|||||||
|
|
||||||
uses dbconst, strutils;
|
uses dbconst, strutils;
|
||||||
|
|
||||||
|
var InitialSQLFormatSettings : TFormatSettings = (
|
||||||
|
CurrencyFormat: 1;
|
||||||
|
NegCurrFormat: 5;
|
||||||
|
ThousandSeparator: #0;
|
||||||
|
DecimalSeparator: '.';
|
||||||
|
CurrencyDecimals: 2;
|
||||||
|
DateSeparator: '-';
|
||||||
|
TimeSeparator: ':';
|
||||||
|
ListSeparator: ' ';
|
||||||
|
CurrencyString: '$';
|
||||||
|
ShortDateFormat: 'yyyy-mm-dd';
|
||||||
|
LongDateFormat: '';
|
||||||
|
TimeAMString: '';
|
||||||
|
TimePMString: '';
|
||||||
|
ShortTimeFormat: 'hh:nn:ss';
|
||||||
|
LongTimeFormat: 'hh:nn:ss';
|
||||||
|
ShortMonthNames: ('','','','','','','','','','','','');
|
||||||
|
LongMonthNames: ('','','','','','','','','','','','');
|
||||||
|
ShortDayNames: ('','','','','','','');
|
||||||
|
LongDayNames: ('','','','','','','');
|
||||||
|
TwoDigitYearCenturyWindow: 50;
|
||||||
|
);
|
||||||
|
|
||||||
function TimeIntervalToString(Time: TDateTime): string;
|
function TimeIntervalToString(Time: TDateTime): string;
|
||||||
var
|
var
|
||||||
millisecond: word;
|
millisecond: word;
|
||||||
@ -649,10 +673,11 @@ begin
|
|||||||
Result := -1;
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
constructor TSQLConnection.Create(AOwner: TComponent);
|
constructor TSQLConnection.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FSQLServerFormatSettings.DecimalSeparator:='.';
|
FSQLFormatSettings:=InitialSQLFormatSettings;
|
||||||
FFieldNameQuoteChars:=DoubleQuotes;
|
FFieldNameQuoteChars:=DoubleQuotes;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -678,8 +703,8 @@ begin
|
|||||||
if (not assigned(field)) or field.IsNull then Result := 'Null'
|
if (not assigned(field)) or field.IsNull then Result := 'Null'
|
||||||
else case field.DataType of
|
else case field.DataType of
|
||||||
ftString : Result := '''' + field.asstring + '''';
|
ftString : Result := '''' + field.asstring + '''';
|
||||||
ftDate : Result := '''' + FormatDateTime('yyyy-mm-dd',Field.AsDateTime) + '''';
|
ftDate : Result := '''' + FormatDateTime('yyyy-mm-dd',Field.AsDateTime,FSqlFormatSettings) + '''';
|
||||||
ftDateTime : Result := '''' + FormatDateTime('yyyy-mm-dd hh:mm:ss',Field.AsDateTime) + '''';
|
ftDateTime : Result := '''' + FormatDateTime('yyyy-mm-dd hh:nn:ss',Field.AsDateTime,FSqlFormatSettings) + '''';
|
||||||
ftTime : Result := QuotedStr(TimeIntervalToString(Field.AsDateTime));
|
ftTime : Result := QuotedStr(TimeIntervalToString(Field.AsDateTime));
|
||||||
else
|
else
|
||||||
Result := field.asstring;
|
Result := field.asstring;
|
||||||
@ -690,11 +715,16 @@ function TSQLConnection.GetAsSQLText(Param: TParam) : string;
|
|||||||
begin
|
begin
|
||||||
if (not assigned(param)) or param.IsNull then Result := 'Null'
|
if (not assigned(param)) or param.IsNull then Result := 'Null'
|
||||||
else case param.DataType of
|
else case param.DataType of
|
||||||
ftString : Result := '''' + param.asstring + '''';
|
ftMemo,
|
||||||
ftDate : Result := '''' + FormatDateTime('yyyy-mm-dd',Param.AsDateTime) + '''';
|
ftFixedChar,
|
||||||
ftDateTime : Result := '''' + FormatDateTime('yyyy-mm-dd hh:mm:ss',Param.AsDateTime) + '''';
|
ftString : Result := QuotedStr(Param.AsString);
|
||||||
|
ftDate : Result := '''' + FormatDateTime('yyyy-mm-dd',Param.AsDateTime,FSQLFormatSettings) + '''';
|
||||||
ftTime : Result := QuotedStr(TimeIntervalToString(Param.AsDateTime));
|
ftTime : Result := QuotedStr(TimeIntervalToString(Param.AsDateTime));
|
||||||
ftFloat : Result := '''' + FloatToStr(Param.AsFloat, FSQLServerFormatSettings) + ''''
|
ftDateTime : Result := '''' + FormatDateTime('yyyy-mm-dd hh:nn:ss', Param.AsDateTime, FSQLFormatSettings) + '''';
|
||||||
|
ftCurrency,
|
||||||
|
ftBcd,
|
||||||
|
ftFloat : Result := FloatToStr(Param.AsFloat, FSQLFormatSettings);
|
||||||
|
ftFMTBcd : Result := stringreplace(Param.AsString, DefaultFormatSettings.DecimalSeparator, FSQLFormatSettings.DecimalSeparator, []);
|
||||||
else
|
else
|
||||||
Result := Param.asstring;
|
Result := Param.asstring;
|
||||||
end; {case}
|
end; {case}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user