Subject | How to Use Arrays |
---|---|
Author | Alan J Davies |
Post date | 2002-05-07T23:49:34Z |
Hi
I use Delphi 6 and FB 1.0, but this would apply to IB too, and previous
versions of Delphi
I have read the article in Embedded SQL about using arrays and cannot
figure out how to read/write data into arrays. The examples shown appear to
be ok but when I try to insert data I get nowhere.
I can create a table such as:-
CREATE TABLE ARRAYTEST(
DESCRIPTION CHAR(5),
INT_ARR INTEGER [3]
)
But I cannot work out how to insert data into the table
Does anyone know of a clear example of how to do the following:-
in Delphi
var MyArray: array[1..3] of Integer; // declare an array
MyDesc: String;
// populate the array - say from an edit box
MyArr[1]:=100;
MyArr[2]:=200;
MyArr[3]:=300;
MyDesc:='AJD1';
Do I then issue an UPDATE such as:-
Sql.Add('UPDATE ARRAYTEST(');
Sql.Add('SET INT_ARR[1] =:INT_ARR1, INT_ARR[2] =:INT_ARR2, INT_ARR[3]
=:INT_ARR3');
Sql.Add('WHERE DESCRIPTION =:MyDesc ');
Params.ParamValues['DESCRIPTION ']:=MyDesc;
Params.ParamValues['INT_ARR1']:=MyArr[1];
Params.ParamValues['INT_ARR2']:=MyArr[2];
Params.ParamValues['INT_ARR3']:=MyArr[3];
ExecSql;
Or preferably pass this to a Stored Procedure, if so how? Do I need to
define each element of the array as above, or as in the example on pp
219/220 chapter 9 Using Arrays by referring to :MyArr
Basically I just need a way of accessing string and numeric data in arrays.
This has become more important because of a significant change in data
structures of a customer that manufactures jewellery. Briefly, items are
made in Silver, Gold, Bronze, Stainless Steel. For each finish there are 10
possible colours ; Order quantities, Delivery quantities and Invoice
quantities, so a subset of a table would be:-
DESCRIPTION Necklace
SilverColour1....10
GoldColour 1.....10 etc..
SilverBalance1... 10
GoldBalance1 ..... 10 etc
Within Delphi all these fields are addressed through an array so it makes
sense in FB too.
Especially now the customer has changed the number of items within each
colour range to 12!
So that all this lot has to change.
As I see it this type of data is an ideal candidate for an array. Am I
wrong or is there a better way?
Any advice gratefully received.
Regards
Alan Davies
I use Delphi 6 and FB 1.0, but this would apply to IB too, and previous
versions of Delphi
I have read the article in Embedded SQL about using arrays and cannot
figure out how to read/write data into arrays. The examples shown appear to
be ok but when I try to insert data I get nowhere.
I can create a table such as:-
CREATE TABLE ARRAYTEST(
DESCRIPTION CHAR(5),
INT_ARR INTEGER [3]
)
But I cannot work out how to insert data into the table
Does anyone know of a clear example of how to do the following:-
in Delphi
var MyArray: array[1..3] of Integer; // declare an array
MyDesc: String;
// populate the array - say from an edit box
MyArr[1]:=100;
MyArr[2]:=200;
MyArr[3]:=300;
MyDesc:='AJD1';
Do I then issue an UPDATE such as:-
Sql.Add('UPDATE ARRAYTEST(');
Sql.Add('SET INT_ARR[1] =:INT_ARR1, INT_ARR[2] =:INT_ARR2, INT_ARR[3]
=:INT_ARR3');
Sql.Add('WHERE DESCRIPTION =:MyDesc ');
Params.ParamValues['DESCRIPTION ']:=MyDesc;
Params.ParamValues['INT_ARR1']:=MyArr[1];
Params.ParamValues['INT_ARR2']:=MyArr[2];
Params.ParamValues['INT_ARR3']:=MyArr[3];
ExecSql;
Or preferably pass this to a Stored Procedure, if so how? Do I need to
define each element of the array as above, or as in the example on pp
219/220 chapter 9 Using Arrays by referring to :MyArr
Basically I just need a way of accessing string and numeric data in arrays.
This has become more important because of a significant change in data
structures of a customer that manufactures jewellery. Briefly, items are
made in Silver, Gold, Bronze, Stainless Steel. For each finish there are 10
possible colours ; Order quantities, Delivery quantities and Invoice
quantities, so a subset of a table would be:-
DESCRIPTION Necklace
SilverColour1....10
GoldColour 1.....10 etc..
SilverBalance1... 10
GoldBalance1 ..... 10 etc
Within Delphi all these fields are addressed through an array so it makes
sense in FB too.
Especially now the customer has changed the number of items within each
colour range to 12!
So that all this lot has to change.
As I see it this type of data is an ideal candidate for an array. Am I
wrong or is there a better way?
Any advice gratefully received.
Regards
Alan Davies