ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/testsuite/Test6.pas
(Generate patch)

Comparing ibx/trunk/fbintf/testsuite/Test6.pas (file contents):
Revision 45 by tony, Tue Dec 6 10:33:46 2016 UTC vs.
Revision 110 by tony, Thu Jan 18 14:37:51 2018 UTC

# Line 1 | Line 1
1   unit Test6;
2 + {$IFDEF MSWINDOWS}
3 + {$DEFINE WINDOWS}
4 + {$ENDIF}
5  
6 < {$mode objfpc}{$H+}
6 > {$IFDEF FPC}
7 > {$mode delphi}
8   {$codepage UTF8}
9 + {$ENDIF}
10  
11   {Test 6: Blob Handling}
12  
13   {
14 <  1. Create an empty database and populate with a single table.
14 >  1. Create an empty database and populate with a single table and stored procedure
15 >     returning a blob.
16  
17    2. Show the character sets available (List RDB$CHARACTER_SETS)
18  
# Line 41 | Line 47 | type
47    TTest6 = class(TTestBase)
48    private
49      procedure UpdateDatabase(Attachment: IAttachment);
50 +    procedure ExecProc(Attachment: IAttachment);
51    public
52 <    function TestTitle: string; override;
53 <    procedure RunTest(CharSet: string; SQLDialect: integer); override;
52 >    function TestTitle: AnsiString; override;
53 >    procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override;
54    end;
55  
56   implementation
# Line 59 | Line 66 | const
66      'Primary Key(RowID)'+
67      ')';
68  
69 +  sqlCreateProc =
70 +    'Create Procedure TestProc (RowID Integer) '+
71 +    'Returns (BlobData Blob sub_type 1 Character Set UTF8) '+
72 +    'As ' +
73 +    'Begin ' +
74 +    ' Select BlobData From TestData Where RowID = :RowID Into :BlobData; '+
75 +    'End';
76 +
77 +
78    sqlGetCharSets = 'Select RDB$CHARACTER_SET_NAME,RDB$CHARACTER_SET_ID from RDB$CHARACTER_SETS order by 2';
79  
80    sqlInsert = 'Insert into TestData(RowID,Title,FixedPoint,FloatingPoint) Values(:RowID,:Title,:FP, :DP)';
81  
82    sqlUpdate = 'Update TestData Set BlobData = ? Where RowID = ?';
83  
84 +  sqlExecProc = 'Execute Procedure TestProc ?';
85 +
86  
87   { TTest6 }
88  
# Line 111 | Line 129 | begin
129    begin
130      ByName('rowid').AsInteger := 2;
131      ByName('title').AsString := 'Blob Test ©€';
132 +    ByName('Fp').Clear;
133 +    ByName('DP').Clear;
134    end;
135    Statement.Execute;
136    Statement := Attachment.Prepare(Transaction,'Select * from TestData Where rowid = 1');
# Line 126 | Line 146 | begin
146    end;
147   end;
148  
149 < function TTest6.TestTitle: string;
149 > procedure TTest6.ExecProc(Attachment: IAttachment);
150 > var Transaction: ITransaction;
151 >    Statement: IStatement;
152 >    Results: IResults;
153 > begin
154 >  writeln('Testing Blob as stored proc parameter');
155 >  Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit);
156 >
157 >  Statement := Attachment.Prepare(Transaction,sqlExecProc);
158 >  PrintMetaData(Statement.GetMetaData);
159 >  Statement.SQLParams[0].AsInteger := 1;
160 >  Results := Statement.Execute;
161 >  ReportResult(Results);
162 > end;
163 >
164 > function TTest6.TestTitle: AnsiString;
165   begin
166    Result := 'Test 6: Blob Handling';
167   end;
168  
169 < procedure TTest6.RunTest(CharSet: string; SQLDialect: integer);
169 > procedure TTest6.RunTest(CharSet: AnsiString; SQLDialect: integer);
170   var DPB: IDPB;
171      Attachment: IAttachment;
172   begin
# Line 142 | Line 177 | begin
177    DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
178    Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
179    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
180 +  Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateProc);
181 +  UpdateDatabase(Attachment);
182 +  ExecProc(Attachment);
183 +
184 +  Attachment.DropDatabase;
185 +
186 +  {Repeat with WIN1252}
187 +  DPB := FirebirdAPI.AllocateDPB;
188 +  DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName);
189 +  DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword);
190 +  DPB.Add(isc_dpb_lc_ctype).setAsString('WIN1252');
191 +  DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
192 +  Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
193 +  Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
194 +  Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateProc);
195    UpdateDatabase(Attachment);
196 +  ExecProc(Attachment);
197  
198    Attachment.DropDatabase;
199  
# Line 153 | Line 204 | begin
204    DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect);
205    Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB);
206    Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable);
207 +  Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateProc);
208    UpdateDatabase(Attachment);
209 +  ExecProc(Attachment);
210  
211    Attachment.DropDatabase;
212   end;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines