1 {*********************************************************}
3 { Zeos Database Objects }
4 { Variables classes and interfaces }
6 { Originally written by Sergey Seroukhov }
8 {*********************************************************}
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
13 { License Agreement: }
15 { This library is distributed in the hope that it will be }
16 { useful, but WITHOUT ANY WARRANTY; without even the }
17 { implied warranty of MERCHANTABILITY or FITNESS FOR }
18 { A PARTICULAR PURPOSE. See the GNU Lesser General }
19 { Public License for more details. }
21 { The source code of the ZEOS Libraries and packages are }
22 { distributed under the Library GNU General Public }
23 { License (see the file COPYING / COPYING.ZEOS) }
24 { with the following modification: }
25 { As a special exception, the copyright holders of this }
26 { library give you permission to link this library with }
27 { independent modules to produce an executable, }
28 { regardless of the license terms of these independent }
29 { modules, and to copy and distribute the resulting }
30 { executable under terms of your choice, provided that }
31 { you also meet, for each linked independent module, }
32 { the terms and conditions of the license of that module. }
33 { An independent module is a module which is not derived }
34 { from or based on this library. If you modify this }
35 { library, you may extend this exception to your version }
36 { of the library, but you are not obligated to do so. }
37 { If you do not wish to do so, delete this exception }
38 { statement from your version. }
41 { The project web site is located on: }
42 { http://zeos.firmos.at (FORUM) }
43 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
44 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
46 { http://www.sourceforge.net/projects/zeoslib. }
49 { Zeos Development Group. }
50 {********************************************************@}
52 unit ZFunctionsConvert;
59 SysUtils, ZFunctions, ZExpression, ZVariant;
61 {** Conversion functions }
66 {** Implements a VAL function. }
67 TZValFunction = class (TZAbstractFunction)
69 function Execute(Stack: TZExecutionStack;
70 VariantManager: IZVariantManager): TZVariant; override;
74 {** Implements a CTOD function. }
75 TZCtodFunction = class (TZAbstractFunction)
77 function Execute(Stack: TZExecutionStack;
78 VariantManager: IZVariantManager): TZVariant; override;
81 {** Implements a DTOS function. }
82 TZDtosFunction = class (TZAbstractFunction)
84 function Execute(Stack: TZExecutionStack;
85 VariantManager: IZVariantManager): TZVariant; override;
88 {** Implements a DTOS function. }
89 TZFormatDateTimeFunction = class (TZAbstractFunction)
91 function Execute(Stack: TZExecutionStack;
92 VariantManager: IZVariantManager): TZVariant; override;
95 procedure AddConvertFunctions(Functions : TZFunctionsList);
100 InternalDefaultFormatSettings : TFormatSettings;
103 DefaultFormatSettings : TFormatSettings = (
106 ThousandSeparator: ',';
107 DecimalSeparator: '.';
113 ShortDateFormat: 'd/m/y';
114 LongDateFormat: 'dd" "mmmm" "yyyy';
117 ShortTimeFormat: 'hh:nn';
118 LongTimeFormat: 'hh:nn:ss';
119 ShortMonthNames: ('Jan','Feb','Mar','Apr','May','Jun',
120 'Jul','Aug','Sep','Oct','Nov','Dec');
121 LongMonthNames: ('January','February','March','April','May','June',
122 'July','August','September','October','November','December');
123 ShortDayNames: ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
124 LongDayNames: ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
125 TwoDigitYearCenturyWindow: 50;
131 function TZValFunction.Execute(Stack: TZExecutionStack;
132 VariantManager: IZVariantManager): TZVariant;
134 CheckParamsCount(Stack, 1);
135 VariantManager.SetAsFloat(Result, StrToFloatDef(Stack.GetParameter(1).VString, 0, InternalDefaultFormatSettings));
140 function TZCtodFunction.Execute(Stack: TZExecutionStack;
141 VariantManager: IZVariantManager): TZVariant;
145 CheckParamsCount(Stack, 1);
146 Value := Stack.GetParameter(1);
147 VariantManager.SetAsDateTime(Result, StrToDateDef(Value.VString, 0));
152 function TZDtosFunction.Execute(Stack: TZExecutionStack;
153 VariantManager: IZVariantManager): TZVariant;
157 CheckParamsCount(Stack, 1);
158 Value := Stack.GetParameter(1);
159 VariantManager.SetAsString(Result, FormatDateTime('yyyymmdd', Value.VDateTime));
162 { TZFormatDateTimeFunction }
164 function TZFormatDateTimeFunction.Execute(Stack: TZExecutionStack;
165 VariantManager: IZVariantManager): TZVariant;
167 CheckParamsCount(Stack, 2);
168 VariantManager.SetAsString(Result, FormatDateTime(Stack.GetParameter(2).VString, Stack.GetParameter(1).VDateTime));
171 procedure AddConvertFunctions(Functions : TZFunctionsList);
173 Functions.Add(TZValFunction.Create('VAL'));
174 Functions.Add(TZDtosFunction.Create('DTOS'));
175 Functions.Add(TZCtodFunction.Create('CTOD'));
176 Functions.Add(TZFormatDateTimeFunction.Create('FORMATDATETIME'));
180 // InternalDefaultFormatSettings := DefaultFormatSettings;
181 InternalDefaultFormatSettings.ThousandSeparator := ',';
182 InternalDefaultFormatSettings.DecimalSeparator := '.';