zeoslib  UNKNOWN
 All Files
ZFunctionsConvert.pas
Go to the documentation of this file.
1 {*********************************************************}
2 { }
3 { Zeos Database Objects }
4 { Variables classes and interfaces }
5 { }
6 { Originally written by Sergey Seroukhov }
7 { }
8 {*********************************************************}
9 
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
12 { }
13 { License Agreement: }
14 { }
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. }
20 { }
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. }
39 { }
40 { }
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) }
45 { }
46 { http://www.sourceforge.net/projects/zeoslib. }
47 { }
48 { }
49 { Zeos Development Group. }
50 {********************************************************@}
51 
52 unit ZFunctionsConvert;
53 
54 interface
55 
56 {$I ZCore.inc}
57 
58 uses
59  SysUtils, ZFunctions, ZExpression, ZVariant;
60 
61 {** Conversion functions }
62 
63 type
64 
65 {** Str <> Float}
66  {** Implements a VAL function. }
67  TZValFunction = class (TZAbstractFunction)
68  public
69  function Execute(Stack: TZExecutionStack;
70  VariantManager: IZVariantManager): TZVariant; override;
71  end;
72 
73 {** Str <> Date}
74  {** Implements a CTOD function. }
75  TZCtodFunction = class (TZAbstractFunction)
76  public
77  function Execute(Stack: TZExecutionStack;
78  VariantManager: IZVariantManager): TZVariant; override;
79  end;
80 
81  {** Implements a DTOS function. }
82  TZDtosFunction = class (TZAbstractFunction)
83  public
84  function Execute(Stack: TZExecutionStack;
85  VariantManager: IZVariantManager): TZVariant; override;
86  end;
87 
88  {** Implements a DTOS function. }
89  TZFormatDateTimeFunction = class (TZAbstractFunction)
90  public
91  function Execute(Stack: TZExecutionStack;
92  VariantManager: IZVariantManager): TZVariant; override;
93  end;
94 
95 procedure AddConvertFunctions(Functions : TZFunctionsList);
96 
97 implementation
98 
99 var
100  InternalDefaultFormatSettings : TFormatSettings;
101 
102 {*******
103  DefaultFormatSettings : TFormatSettings = (
104  CurrencyFormat: 1;
105  NegCurrFormat: 5;
106  ThousandSeparator: ',';
107  DecimalSeparator: '.';
108  CurrencyDecimals: 2;
109  DateSeparator: '-';
110  TimeSeparator: ':';
111  ListSeparator: ',';
112  CurrencyString: '$';
113  ShortDateFormat: 'd/m/y';
114  LongDateFormat: 'dd" "mmmm" "yyyy';
115  TimeAMString: 'AM';
116  TimePMString: 'PM';
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;
126  );
127 ******}
128 
129  { TZValFunction }
130 
131 function TZValFunction.Execute(Stack: TZExecutionStack;
132  VariantManager: IZVariantManager): TZVariant;
133 begin
134  CheckParamsCount(Stack, 1);
135  VariantManager.SetAsFloat(Result, StrToFloatDef(Stack.GetParameter(1).VString, 0, InternalDefaultFormatSettings));
136 end;
137 
138 { TZCtodFunction }
139 
140 function TZCtodFunction.Execute(Stack: TZExecutionStack;
141  VariantManager: IZVariantManager): TZVariant;
142 var
143  Value: TZVariant;
144 begin
145  CheckParamsCount(Stack, 1);
146  Value := Stack.GetParameter(1);
147  VariantManager.SetAsDateTime(Result, StrToDateDef(Value.VString, 0));
148 end;
149 
150 { TZDtosFunction }
151 
152 function TZDtosFunction.Execute(Stack: TZExecutionStack;
153  VariantManager: IZVariantManager): TZVariant;
154 var
155  Value: TZVariant;
156 begin
157  CheckParamsCount(Stack, 1);
158  Value := Stack.GetParameter(1);
159  VariantManager.SetAsString(Result, FormatDateTime('yyyymmdd', Value.VDateTime));
160 end;
161 
162 { TZFormatDateTimeFunction }
163 
164 function TZFormatDateTimeFunction.Execute(Stack: TZExecutionStack;
165  VariantManager: IZVariantManager): TZVariant;
166 begin
167  CheckParamsCount(Stack, 2);
168  VariantManager.SetAsString(Result, FormatDateTime(Stack.GetParameter(2).VString, Stack.GetParameter(1).VDateTime));
169 end;
170 
171 procedure AddConvertFunctions(Functions : TZFunctionsList);
172 begin
173  Functions.Add(TZValFunction.Create('VAL'));
174  Functions.Add(TZDtosFunction.Create('DTOS'));
175  Functions.Add(TZCtodFunction.Create('CTOD'));
176  Functions.Add(TZFormatDateTimeFunction.Create('FORMATDATETIME'));
177 end;
178 
179 initialization
180 // InternalDefaultFormatSettings := DefaultFormatSettings;
181  InternalDefaultFormatSettings.ThousandSeparator := ',';
182  InternalDefaultFormatSettings.DecimalSeparator := '.';
183 end.