(* * Firebird Interface (fbintf) Test suite. This program is used to * test the Firebird Pascal Interface and provide a semi-automated * pass/fail check for each test. * * The contents of this file are subject to the Initial Developer's * Public License Version 1.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy * of the License here: * * http://www.firebirdsql.org/index.php?op=doc&id=idpl * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing rights * and limitations under the License. * * The Initial Developer of the Original Code is Tony Whyman. * * The Original Code is (C) 2016 Tony Whyman, MWA Software * (http://www.mwasoftware.co.uk). * * All Rights Reserved. * * Contributor(s): ______________________________________. * *) unit Test8; {$IFDEF MSWINDOWS} {$DEFINE WINDOWS} {$ENDIF} {$IFDEF FPC} {$mode delphi} {$codepage utf8} {$ENDIF} {Test 8: Create and read back an Array with 2 dimensions} { 1. Create an empty database and populate with a single table including a two dimensional array of varchar(16) column. 2. Select all and show metadata including array metadata. 3. Insert a row but leave array null 4. Show result. 5. Update row with a populated array and show results. } interface uses Classes, SysUtils, TestApplication, FBTestApp, IB; type { TTest8 } TTest8 = class(TFBTestBase) private procedure UpdateDatabase(Attachment: IAttachment); public function TestTitle: AnsiString; override; procedure RunTest(CharSet: AnsiString; SQLDialect: integer); override; end; implementation const sqlCreateTable = 'Create Table TestData ('+ 'RowID Integer not null,'+ 'Title VarChar(32) Character Set UTF8,'+ 'MyArray VarChar(16) [0:16, -1:7] Character Set ISO8859_2,'+ 'Primary Key(RowID)'+ ')'; sqlInsert = 'Insert into TestData(RowID,Title) Values(:RowID,:Title)'; sqlUpdate = 'Update TestData Set MyArray = ? Where RowID = 1'; { TTest8 } procedure TTest8.UpdateDatabase(Attachment: IAttachment); var Transaction: ITransaction; Statement: IStatement; i,j,k : integer; ar: IArray; begin Transaction := Attachment.StartTransaction([isc_tpb_write,isc_tpb_nowait,isc_tpb_concurrency],taCommit); Statement := Attachment.Prepare(Transaction,'Select * from TestData'); PrintMetaData(Statement.GetMetaData); Statement := Attachment.PrepareWithNamedParameters(Transaction,sqlInsert); ParamInfo(Statement.GetSQLParams); with Statement.GetSQLParams do begin ByName('rowid').AsInteger := 1; ByName('title').AsString := '2D Array'; end; Statement.Execute; Statement := Attachment.Prepare(Transaction,'Select * from TestData'); ReportResults(Statement); Statement := Attachment.Prepare(Transaction,sqlUpdate); ar := Attachment.CreateArray(Transaction,'TestData','MyArray'); if ar <> nil then begin k := 50; for i := 0 to 16 do for j := -1 to 7 do begin ar.SetAsString([i,j],'A' + IntToStr(k)); Inc(k); end; Statement.SQLParams[0].AsArray := ar; Statement.Execute; end; Statement := Attachment.Prepare(Transaction,'Select * from TestData'); ReportResults(Statement); end; function TTest8.TestTitle: AnsiString; begin Result := 'Test 8: Create and read back an Array with 2 dimensions'; end; procedure TTest8.RunTest(CharSet: AnsiString; SQLDialect: integer); var DPB: IDPB; Attachment: IAttachment; begin DPB := FirebirdAPI.AllocateDPB; DPB.Add(isc_dpb_user_name).setAsString(Owner.GetUserName); DPB.Add(isc_dpb_password).setAsString(Owner.GetPassword); DPB.Add(isc_dpb_lc_ctype).setAsString(CharSet); DPB.Add(isc_dpb_set_db_SQL_dialect).setAsByte(SQLDialect); Attachment := FirebirdAPI.CreateDatabase(Owner.GetNewDatabaseName,DPB); Attachment.ExecImmediate([isc_tpb_write,isc_tpb_wait,isc_tpb_consistency],sqlCreateTable); UpdateDatabase(Attachment); Attachment.DropDatabase; end; initialization RegisterTest(TTest8); end.