New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test class to insert and read multidimensional array fields [DNET332] #343
Comments
Modified by: luis olascoaga (olasur)Version: 2.5.2 [ 10370 ] Version: 2.5.1 [ 10360 ] Component: http://ADO.NET Provider [ 10041 ] |
Modified by: luis olascoaga (olasur)description: The following tables and the class are to test the solution presented in x to insert and read multidimensional array type fields: CREATE TABLE VECINT (
); CREATE TABLE VECDEC (
); CREATE TABLE VECCHAR (
); CREATE TABLE VECVARCHAR (
); CREATE TABLE MATINT (
); CREATE TABLE MATDEC (
); CREATE TABLE MATCHAR (
); CREATE TABLE MATVARCHAR (
); using System; using FirebirdSql.Data.FirebirdClient; class TestArray{ private static FbConnection Con; private static void Conectar(){ FbConnectionStringBuilder ConStr = new FbConnectionStringBuilder(); ConStr.ServerType = 0; ConStr.Database = "TestArray.fdb"; ConStr.UserID = "sysdba"; ConStr.Password = "masterkey"; ConStr.DataSource = "localhost"; Con = new FbConnection(); Con.ConnectionString = ConStr.ToString(); Con.Open(); } private static void ShowVec(string Table,Array Vec){ int i=1; Console.WriteLine("Data for table " + Table); foreach(object val in Vec){ Console.WriteLine("Element(" + i + ") = " + val); i++; } Console.WriteLine("Press any key to continue . . . "); Console.ReadKey(true); Console.Clear(); } public static void Insert(string Table,Array Val){ string sql = "INSERT INTO " + Table + " Values(@Valid,@valvec)"; FbCommand cmd = new FbCommand(sql,Con); cmd.Parameters.Add("@Valid",FbDbType.Integer).Value = 10; cmd.Parameters.Add("@valvec",FbDbType.Array).Value = Val; cmd.ExecuteNonQuery(); cmd.Dispose(); } public static void InsertVec(){ int[] VecI = {10,15,20,25,30};//Vector Integer[3:7] decimal[] VecD = {1.5m,2.5m,3.5m,4.5m,5.5m};//Vector Decimal(4,2)[1:5] string[] VecC = {"España","nuevo","campeon","del","mundo"};//Vector Char(20)[2:6] string[] VecVC = {"Spain","new","world","champion","2010"};//Vector VarChar(10)[3:7] Insert("VecInt",VecI); Insert("VecDec",VecD); Insert("VecChar",VecC); Insert("VecVarChar",VecVC); } public static Array CreateMat(Type tp,int nf,int nc){ int i,j,val; Random R = new Random(); Array Vec = Array.CreateInstance(tp,nf,nc); for(i=0;i<nf;i++) for(j=0;j<nc;j++){
} return Vec; } public static void InsertMat(){ Insert("MatInt",CreateMat(typeof(int),4,5));//MATRIX Integer[2:5,3:7] Insert("MatDec",CreateMat(typeof(decimal),3,4));//Decimal(4,2) [5:7,1:4] Insert("MatChar",CreateMat(typeof(string),5,4));//Char(20)[1:5,2:5] Insert("MatVarChar",CreateMat(typeof(string),4,3));//VarChar(10)[3:6,5:7] } public static void ShowDatas(){ int i; string sql="Select * From {0} Rows 1"; string []Tabs={"VecInt","VecDec","VecChar","VecVarChar",
FbCommand cmd = new FbCommand("",Con); FbDataReader rd; Console.Clear(); for(i=0;i<Tabs.Length;i++){ cmd.CommandText=string.Format(sql,Tabs[i]); rd = cmd.ExecuteReader(); if(rd.Read())
} cmd.Dispose(); } public static void Main(string[] args) { Conectar(); InsertVec(); InsertMat(); ShowDatas(); Con.Close(); Con.Dispose(); } } => The following tables and the class are to test the solution presented in DNET331 to insert and read multidimensional array type fields: CREATE TABLE VECINT (
); CREATE TABLE VECDEC (
); CREATE TABLE VECCHAR (
); CREATE TABLE VECVARCHAR (
); CREATE TABLE MATINT (
); CREATE TABLE MATDEC (
); CREATE TABLE MATCHAR (
); CREATE TABLE MATVARCHAR (
); using System; using FirebirdSql.Data.FirebirdClient; class TestArray{ private static FbConnection Con; private static void Conectar(){ FbConnectionStringBuilder ConStr = new FbConnectionStringBuilder(); ConStr.ServerType = 0; ConStr.Database = "TestArray.fdb"; ConStr.UserID = "sysdba"; ConStr.Password = "masterkey"; ConStr.DataSource = "localhost"; Con = new FbConnection(); Con.ConnectionString = ConStr.ToString(); Con.Open(); } private static void ShowVec(string Table,Array Vec){ int i=1; Console.WriteLine("Data for table " + Table); foreach(object val in Vec){ Console.WriteLine("Element(" + i + ") = " + val); i++; } Console.WriteLine("Press any key to continue . . . "); Console.ReadKey(true); Console.Clear(); } public static void Insert(string Table,Array Val){ string sql = "INSERT INTO " + Table + " Values(@Valid,@valvec)"; FbCommand cmd = new FbCommand(sql,Con); cmd.Parameters.Add("@Valid",FbDbType.Integer).Value = 10; cmd.Parameters.Add("@valvec",FbDbType.Array).Value = Val; cmd.ExecuteNonQuery(); cmd.Dispose(); } public static void InsertVec(){ int[] VecI = {10,15,20,25,30};//Vector Integer[3:7] decimal[] VecD = {1.5m,2.5m,3.5m,4.5m,5.5m};//Vector Decimal(4,2)[1:5] string[] VecC = {"España","nuevo","campeon","del","mundo"};//Vector Char(20)[2:6] string[] VecVC = {"Spain","new","world","champion","2010"};//Vector VarChar(10)[3:7] Insert("VecInt",VecI); Insert("VecDec",VecD); Insert("VecChar",VecC); Insert("VecVarChar",VecVC); } public static Array CreateMat(Type tp,int nf,int nc){ int i,j,val; Random R = new Random(); Array Vec = Array.CreateInstance(tp,nf,nc); for(i=0;i<nf;i++) for(j=0;j<nc;j++){
} return Vec; } public static void InsertMat(){ Insert("MatInt",CreateMat(typeof(int),4,5));//MATRIX Integer[2:5,3:7] Insert("MatDec",CreateMat(typeof(decimal),3,4));//Decimal(4,2) [5:7,1:4] Insert("MatChar",CreateMat(typeof(string),5,4));//Char(20)[1:5,2:5] Insert("MatVarChar",CreateMat(typeof(string),4,3));//VarChar(10)[3:6,5:7] } public static void ShowDatas(){ int i; string sql="Select * From {0} Rows 1"; string []Tabs={"VecInt","VecDec","VecChar","VecVarChar",
FbCommand cmd = new FbCommand("",Con); FbDataReader rd; Console.Clear(); for(i=0;i<Tabs.Length;i++){ cmd.CommandText=string.Format(sql,Tabs[i]); rd = cmd.ExecuteReader(); if(rd.Read())
} cmd.Dispose(); } public static void Main(string[] args) { Conectar(); InsertVec(); InsertMat(); ShowDatas(); Con.Close(); Con.Dispose(); } } |
Submitted by: luis olascoaga (olasur)
The following tables and the class are to test the solution presented in DNET331 to insert and read multidimensional array type fields:
CREATE TABLE VECINT (
);
CREATE TABLE VECDEC (
);
CREATE TABLE VECCHAR (
);
CREATE TABLE VECVARCHAR (
);
CREATE TABLE MATINT (
);
CREATE TABLE MATDEC (
);
CREATE TABLE MATCHAR (
);
CREATE TABLE MATVARCHAR (
);
using System;
using FirebirdSql.Data.FirebirdClient;
class TestArray{
private static FbConnection Con;
private static void Conectar(){
FbConnectionStringBuilder ConStr = new FbConnectionStringBuilder();
ConStr.ServerType = 0;
ConStr.Database = "TestArray.fdb";
ConStr.UserID = "sysdba";
ConStr.Password = "masterkey";
ConStr.DataSource = "localhost";
Con = new FbConnection();
Con.ConnectionString = ConStr.ToString();
Con.Open();
}
private static void ShowVec(string Table,Array Vec){
int i=1;
Console.WriteLine("Data for table " + Table);
foreach(object val in Vec){
Console.WriteLine("Element(" + i + ") = " + val);
i++;
}
Console.WriteLine("Press any key to continue . . . ");
Console.ReadKey(true);
Console.Clear();
}
public static void Insert(string Table,Array Val){
string sql = "INSERT INTO " + Table + " Values(@Valid,@valvec)";
FbCommand cmd = new FbCommand(sql,Con);
cmd.Parameters.Add("@Valid",FbDbType.Integer).Value = 10;
cmd.Parameters.Add("@valvec",FbDbType.Array).Value = Val;
cmd.ExecuteNonQuery();
cmd.Dispose();
}
public static void InsertVec(){
int[] VecI = {10,15,20,25,30};//Vector Integer[3:7]
decimal[] VecD = {1.5m,2.5m,3.5m,4.5m,5.5m};//Vector Decimal(4,2)[1:5]
string[] VecC = {"España","nuevo","campeon","del","mundo"};//Vector Char(20)[2:6]
string[] VecVC = {"Spain","new","world","champion","2010"};//Vector VarChar(10)[3:7]
Insert("VecInt",VecI);
Insert("VecDec",VecD);
Insert("VecChar",VecC);
Insert("VecVarChar",VecVC);
}
public static Array CreateMat(Type tp,int nf,int nc){
int i,j,val;
Random R = new Random();
Array Vec = Array.CreateInstance(tp,nf,nc);
for(i=0;i<nf;i++)
for(j=0;j<nc;j++){
}
return Vec;
}
public static void InsertMat(){
Insert("MatInt",CreateMat(typeof(int),4,5));//MATRIX Integer[2:5,3:7]
Insert("MatDec",CreateMat(typeof(decimal),3,4));//Decimal(4,2) [5:7,1:4]
Insert("MatChar",CreateMat(typeof(string),5,4));//Char(20)[1:5,2:5]
Insert("MatVarChar",CreateMat(typeof(string),4,3));//VarChar(10)[3:6,5:7]
}
public static void ShowDatas(){
int i;
string sql="Select * From {0} Rows 1";
string []Tabs={"VecInt","VecDec","VecChar","VecVarChar",
FbCommand cmd = new FbCommand("",Con);
FbDataReader rd;
Console.Clear();
for(i=0;i<Tabs.Length;i++){
cmd.CommandText=string.Format(sql,Tabs[i]);
rd = cmd.ExecuteReader();
if(rd.Read())
}
cmd.Dispose();
}
public static void Main(string[] args) {
Conectar();
InsertVec();
InsertMat();
ShowDatas();
Con.Close();
Con.Dispose();
}
}
The text was updated successfully, but these errors were encountered: