ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test8.pas
Revision: 45
Committed: Tue Dec 6 10:33:46 2016 UTC (8 years ago) by tony
Content type: text/x-pascal
File size: 3133 byte(s)
Log Message:
Committing updates for Release R2-0-0

File Contents

# User Rev Content
1 tony 45 unit Test8;
2    
3     {$mode objfpc}{$H+}
4     {$codepage utf8}
5    
6     {Test 8: Create and read back an Array with 2 dimensions}
7    
8     {
9     1. Create an empty database and populate with a single table including a two
10     dimensional array of varchar(16) column.
11    
12     2. Select all and show metadata including array metadata.
13    
14     3. Insert a row but leave array null
15    
16     4. Show result.
17    
18     5. Update row with a populated array and show results.
19     }
20    
21     interface
22    
23     uses
24     Classes, SysUtils, TestManager, IB;
25    
26     type
27    
28     { TTest8 }
29    
30     TTest8 = class(TTestBase)
31     private
32     procedure UpdateDatabase(Attachment: IAttachment);
33     public
34     function TestTitle: string; override;
35     procedure RunTest(CharSet: string; SQLDialect: integer); override;
36     end;
37    
38     implementation
39    
40     const
41     sqlCreateTable =
42     'Create Table TestData ('+
43     'RowID Integer not null,'+
44     'Title VarChar(32) Character Set UTF8,'+
45     'MyArray VarChar(16) [0:16, -1:7] Character Set ISO8859_2,'+
46     'Primary Key(RowID)'+
47     ')';
48    
49     sqlInsert = 'Insert into TestData(RowID,Title) Values(:RowID,:Title)';
50    
51     sqlUpdate = 'Update TestData Set MyArray = ? Where RowID = 1';
52    
53     { TTest8 }
54    
55     procedure TTest8.UpdateDatabase(Attachment: IAttachment);
56     var Transaction: ITransaction;
57     Statement: IStatement;
58     ResultSet: IResultSet;
59     i,j,k : integer;
60     ar: IArray;
61     begin
62     Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
63     Statement := Attachment.Prepare(Transaction,'Select * from TestData');
64     PrintMetaData(Statement.GetMetaData);
65     Statement := Attachment.PrepareWithNamedParameters(Transaction,sqlInsert);
66     ParamInfo(Statement.GetSQLParams);
67     with Statement.GetSQLParams do
68     begin
69     ByName('rowid').AsInteger := 1;
70     ByName('title').AsString := '2D Array';
71     end;
72     Statement.Execute;
73     Statement := Attachment.Prepare(Transaction,'Select * from TestData');
74     ReportResults(Statement);
75    
76     Statement := Attachment.Prepare(Transaction,sqlUpdate);
77     ar := Attachment.CreateArray(Transaction,'TestData','MyArray');
78     if ar <> nil then
79     begin
80     k := 50;
81     for i := 0 to 16 do
82     for j := -1 to 7 do
83     begin
84     ar.SetAsString([i,j],'A' + IntToStr(k));
85     Inc(k);
86     end;
87     Statement.SQLParams[0].AsArray := ar;
88     Statement.Execute;
89     end;
90     Statement := Attachment.Prepare(Transaction,'Select * from TestData');
91     ReportResults(Statement);
92     end;
93    
94     function TTest8.TestTitle: string;
95     begin
96     Result := 'Test 8: Create and read back an Array with 2 dimensions';
97     end;
98    
99     procedure TTest8.RunTest(CharSet: string; SQLDialect: integer);
100     var DPB: IDPB;
101     Attachment: IAttachment;
102     begin
103     DPB := FirebirdAPI.AllocateDPB;
104     DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
105     DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
106     DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet);
107     DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
108     Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
109     Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
110     UpdateDatabase(Attachment);
111    
112     Attachment.DropDatabase;
113     end;
114    
115     initialization
116     RegisterTest(TTest8);
117    
118     end.
119