1 |
+ |
(* |
2 |
+ |
* Firebird Interface (fbintf) Test suite. This program is used to |
3 |
+ |
* test the Firebird Pascal Interface and provide a semi-automated |
4 |
+ |
* pass/fail check for each test. |
5 |
+ |
* |
6 |
+ |
* The contents of this file are subject to the Initial Developer's |
7 |
+ |
* Public License Version 1.0 (the "License"); you may not use this |
8 |
+ |
* file except in compliance with the License. You may obtain a copy |
9 |
+ |
* of the License here: |
10 |
+ |
* |
11 |
+ |
* http://www.firebirdsql.org/index.php?op=doc&id=idpl |
12 |
+ |
* |
13 |
+ |
* Software distributed under the License is distributed on an "AS |
14 |
+ |
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
15 |
+ |
* implied. See the License for the specific language governing rights |
16 |
+ |
* and limitations under the License. |
17 |
+ |
* |
18 |
+ |
* The Initial Developer of the Original Code is Tony Whyman. |
19 |
+ |
* |
20 |
+ |
* The Original Code is (C) 2016 Tony Whyman, MWA Software |
21 |
+ |
* (http://www.mwasoftware.co.uk). |
22 |
+ |
* |
23 |
+ |
* All Rights Reserved. |
24 |
+ |
* |
25 |
+ |
* Contributor(s): ______________________________________. |
26 |
+ |
* |
27 |
+ |
*) |
28 |
+ |
|
29 |
|
unit Test7; |
30 |
+ |
{$IFDEF MSWINDOWS} |
31 |
+ |
{$DEFINE WINDOWS} |
32 |
+ |
{$ENDIF} |
33 |
|
|
34 |
< |
{$mode objfpc}{$H+} |
34 |
> |
{$IFDEF FPC} |
35 |
> |
{$mode delphi} |
36 |
|
{$codepage utf8} |
37 |
+ |
{$ENDIF} |
38 |
|
|
39 |
|
{Test 7: Create and read back an Array} |
40 |
|
|
58 |
|
interface |
59 |
|
|
60 |
|
uses |
61 |
< |
Classes, SysUtils, TestManager, IB; |
61 |
> |
Classes, SysUtils, TestApplication, FBTestApp, IB; |
62 |
|
|
63 |
|
type |
64 |
|
|
65 |
|
{ TTest7 } |
66 |
|
|
67 |
< |
TTest7 = class(TTestBase) |
67 |
> |
TTest7 = class(TFBTestBase) |
68 |
|
private |
69 |
|
procedure UpdateDatabase(Attachment: IAttachment); |
70 |
|
public |
71 |
< |
function TestTitle: string; override; |
72 |
< |
procedure RunTest(CharSet: string; SQLDialect: integer); override; |
71 |
> |
function TestTitle: AnsiString; override; |
72 |
> |
procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; |
73 |
|
end; |
74 |
|
|
75 |
|
implementation |
82 |
|
'Dated TIMESTAMP, '+ |
83 |
|
'Notes VarChar(64) Character Set ISO8859_1,'+ |
84 |
|
'MyArray Integer [0:16],'+ |
85 |
+ |
'MyArray2 Timestamp [0:16],'+ |
86 |
+ |
'MyArray3 Numeric(10,2) [0:16],'+ |
87 |
|
'Primary Key(RowID)'+ |
88 |
|
')'; |
89 |
|
|
90 |
|
sqlInsert = 'Insert into TestData(RowID,Title,Dated,Notes) Values(:RowID,:Title,:Dated,:Notes)'; |
91 |
|
|
92 |
|
sqlUpdate = 'Update TestData Set MyArray = :MyArray Where RowID = 1'; |
93 |
+ |
sqlUpdate2 = 'Update TestData Set MyArray2 = :MyArray2 Where RowID = 1'; |
94 |
+ |
sqlUpdate3 = 'Update TestData Set MyArray3 = :MyArray3 Where RowID = 1'; |
95 |
|
|
96 |
|
{ TTest7 } |
97 |
|
|
101 |
|
ResultSet: IResultSet; |
102 |
|
i,j: integer; |
103 |
|
ar: IArray; |
104 |
+ |
aDateTime: TDateTime; |
105 |
+ |
f: double; |
106 |
|
begin |
107 |
|
Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit); |
108 |
|
Statement := Attachment.Prepare(Transaction,'Select * from TestData'); |
114 |
|
for i := 0 to GetCount - 1 do |
115 |
|
writeln(OutFile,'Param Name = ',Params[i].getName); |
116 |
|
ByName('rowid').AsInteger := 1; |
117 |
+ |
{$IFDEF DCC} |
118 |
+ |
ByName('title').AsString := UTF8Encode('Blob Test ©€'); |
119 |
+ |
{$ELSE} |
120 |
|
ByName('title').AsString := 'Blob Test ©€'; |
121 |
+ |
{$ENDIF} |
122 |
|
ByName('Notes').AsString := 'Écoute moi'; |
123 |
|
ByName('Dated').AsDateTime := EncodeDate(2016,4,1) + EncodeTime(9,30,0,100); |
124 |
|
end; |
138 |
|
end; |
139 |
|
Statement.SQLParams[0].AsArray := ar; |
140 |
|
Statement.Execute; |
141 |
+ |
|
142 |
+ |
Statement := Attachment.PrepareWithNamedParameters(Transaction,sqlUpdate2); |
143 |
+ |
ParamInfo(Statement.GetSQLParams); |
144 |
+ |
ar := Attachment.CreateArray(Transaction,'TestData','MyArray2'); |
145 |
+ |
for i := 0 to 16 do |
146 |
+ |
begin |
147 |
+ |
aDateTime := EncodeDate(2020,5,1) + EncodeTime(12,i,0,0); |
148 |
+ |
ar.SetAsDateTime(i,aDateTime); |
149 |
+ |
end; |
150 |
+ |
Statement.SQLParams[0].AsArray := ar; |
151 |
+ |
Statement.Execute; |
152 |
+ |
|
153 |
+ |
Statement := Attachment.PrepareWithNamedParameters(Transaction,sqlUpdate3); |
154 |
+ |
ParamInfo(Statement.GetSQLParams); |
155 |
+ |
ar := Attachment.CreateArray(Transaction,'TestData','MyArray3'); |
156 |
+ |
f := 0; |
157 |
+ |
for i := 0 to 13 do |
158 |
+ |
begin |
159 |
+ |
ar.SetAsFloat(i,f); |
160 |
+ |
f := f + 1.05 |
161 |
+ |
end; |
162 |
+ |
ar.SetAsString([14],'0.424567'); |
163 |
+ |
ar.SetAsString([15],'42.4567'); |
164 |
+ |
ar.SetAsString([16],'4269'); |
165 |
+ |
Statement.SQLParams[0].AsArray := ar; |
166 |
+ |
Statement.Execute; |
167 |
+ |
|
168 |
|
Statement := Attachment.Prepare(Transaction,'Select * from TestData'); |
169 |
+ |
PrintMetaData(Statement.GetMetaData); |
170 |
|
ReportResults(Statement); |
171 |
|
|
172 |
|
ResultSet := Statement.OpenCursor; |
193 |
|
Transaction.Commit; |
194 |
|
end; |
195 |
|
|
196 |
< |
function TTest7.TestTitle: string; |
196 |
> |
function TTest7.TestTitle: AnsiString; |
197 |
|
begin |
198 |
|
Result := 'Test 7: Create and read back an Array'; |
199 |
|
end; |
200 |
|
|
201 |
< |
procedure TTest7.RunTest(CharSet: string; SQLDialect: integer); |
201 |
> |
procedure TTest7.RunTest(CharSet: AnsiString; SQLDialect: integer); |
202 |
|
var DPB: IDPB; |
203 |
|
Attachment: IAttachment; |
204 |
|
begin |