|
From: <sv...@de...> - 2005-07-08 12:01:07
|
Author: marcelo
Date: 2005-07-08 08:00:48 -0400 (Fri, 08 Jul 2005)
New Revision: 1448
Modified:
humano2/branches/viewtools/components/tests/viewTools.cs
humano2/branches/viewtools/components/viewTools/ViewColumns.cs
humano2/branches/viewtools/components/viewTools/ViewTools.cs
humano2/branches/viewtools/components/webTools/Adapter.cs
Log:
* Final fixes to the branch, going to merge with trunk.
Modified: humano2/branches/viewtools/components/tests/viewTools.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/viewtools/components/tests/viewTools.cs 2005-07-07 0=
3:37:39 UTC (rev 1447)
+++ humano2/branches/viewtools/components/tests/viewTools.cs 2005-07-08 1=
2:00:48 UTC (rev 1448)
@@ -75,13 +75,16 @@
public void SQLSelect()
{
init(); =20
- =20
+ string[] drCols =3D new string[6];
Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
vt.Complex =3D complex;
vt.KeyFlag =3D 0;
=20
//Simple columns
- vt.TestInitSQLVars("10181",""); //Don't forget to init SQLVa=
rs!
+ drCols[0] =3D "10181";
+ drCols[1] =3D "";
+
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
string strSelect =3D vt.SQLSelect("10181");
Logger.Log("SQLSelect(\"10181\"): " + strSelect,LogLevel.Tra=
ce);
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Title\"".Trim());
@@ -90,28 +93,38 @@
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".id_entity, \"d10160cTicket\".\"c10162Title\"".Trim());
=20
//Pertinence columns
- vt.TestInitSQLVars("10231",""); //Don't forget to init SQLVa=
rs!
+ drCols[0] =3D "10231";
+ drCols[1] =3D "";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
strSelect =3D vt.SQLSelect("10231");
Logger.Log("SQLSelect(\"10231\"): " + strSelect,LogLevel.Tra=
ce);
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Assigned to3\"".Trim());
=20
- vt.TestInitSQLVars("10231^18",""); //Don't forget to init SQ=
LVars!
+ drCols[0] =3D "10231^18";
+ drCols[1] =3D "";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
strSelect =3D vt.SQLSelect("10231^18");
Logger.Log("SQLSelect(\"10231^18\"): " + strSelect,LogLevel.=
Trace);
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT user0.\"email\=
"".Trim());
=20
- vt.TestInitSQLVars("10181,10231^18",""); //Don't forget to i=
nit SQLVars!
+ drCols[0] =3D "10181,10231^18";
+ drCols[1] =3D "";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
strSelect =3D vt.SQLSelect("10181,10231^18");
Logger.Log("SQLSelect(\"10181,10231^18\"): " + strSelect,Log=
Level.Trace);
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Title\", user0.\"email\"".Trim());
=20
- vt.TestInitSQLVars("10187^10179",""); //Don't forget to init=
SQLVars!
+ drCols[0] =3D "10187^10179";
+ drCols[1] =3D "";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
strSelect =3D vt.SQLSelect("10187^10179");
Logger.Log("SQLSelect(\"10187^10179\"): " + strSelect,LogLev=
el.Trace);
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT d10160cTicketS=
tatus0.\"c10163Status Name\"".Trim());
=20
//Double Pertinence on the same class
- vt.TestInitSQLVars("10229^18,10231^18",""); //Don't forget t=
o init SQLVars!
+ drCols[0] =3D "10229^18,10231^18";
+ drCols[1] =3D "";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
strSelect =3D vt.SQLSelect("10229^18,10231^18");
Logger.Log("SQLSelect(\"10229^18,10231^18\"): " + strSelect,=
LogLevel.Trace);
Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT user0.\"email\=
", user1.\"email\" as \"email1\"".Trim());=20
@@ -121,12 +134,15 @@
public void SQLWhere()
{
init(); =20
+ string[] drCols =3D new string[6];
=20
Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
vt.Complex =3D complex;
vt.KeyFlag =3D 0;
=20
- vt.TestInitSQLVars("0,10187","10187^10179|7|'closed'|0|0"); =
//Don't forget to init SQLVars!
+ drCols[0] =3D "0,10187";
+ drCols[1] =3D "10187^10179|7|'closed'|0|0";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
=20
//Simple conditions
string strWhere =3D vt.SQLWhere("10187^10179|7|'closed'|0|0"=
);
@@ -155,13 +171,16 @@
[Test]
public void SQLFrom()
{
- init(); =20
+ string[] drCols =3D new string[6];
+ init(); =20
Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
vt.Complex =3D complex;
vt.KeyFlag =3D 0; =20
=20
- vt.TestInitSQLVars("0,10231^18,10229^18,10187^10179",""); //=
Don't forget to init SQLVars!
- string strFrom =3D vt.SQLFrom("0,10231^18,10229^18,10187^101=
79","");
+ drCols[0] =3D "0,10231^18,10229^18,10187^10179";
+ drCols[1] =3D "";
+ vt.TestInitSQLVars(drCols); //Don't forget to init SQLVars!
+ string strFrom =3D vt.SQLFrom("0,10231^18,10229^18,10187^101=
79","","");
Logger.Log("SQLFrom(\"0,10231^18,10229^18,10187^10179\",\"\"=
);" + strFrom, LogLevel.Trace);
=20
Assert.IsTrue(strFrom.Trim() =3D=3D=20
@@ -205,10 +224,11 @@
Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(10162);
vt.Complex =3D complex;
vt.KeyFlag =3D 0; =20
- string strSelect =3D "0,10181,10208,10213,10231^18";
- string strWhere =3D "10231^18|4|'to...@em...'|1|0;10229^18=
|7|'lulu'|0|0";
+ string[] drCols =3D new string[6];
+ drCols[0] =3D "0,10181,10208,10213,10231^18";
+ drCols[1] =3D "10231^18|4|'to...@em...'|1|0;10229^18|7|'lu=
lu'|0|0";
=20
- SortedList SQLVarsList =3D vt.TestGetSQLVars(strSelect,strWh=
ere);
+ SortedList SQLVarsList =3D vt.TestGetSQLVars(drCols);
=20
string tableName0 =3D Convert.ToString(SQLVarsList.GetByInde=
x(SQLVarsList.IndexOfKey("10231^18")));=20
string tableName1 =3D Convert.ToString(SQLVarsList.GetByInde=
x(SQLVarsList.IndexOfKey("10229^18")));
@@ -217,10 +237,10 @@
Assert.IsTrue(tableName0 =3D=3D "user0");
Assert.IsTrue(tableName1 =3D=3D "user1");
=20
- strSelect =3D "0,10181,10208,10213,10229^18,10231^18";
- strWhere =3D "10187^10179|4|'open'|0|0;";
+ drCols[0] =3D "0,10181,10208,10213,10229^18,10229^19,10231^1=
8";
+ drCols[1] =3D "10187^10179|4|'open'|0|0;";
=20
- SQLVarsList =3D vt.TestGetSQLVars(strSelect,strWhere);
+ SQLVarsList =3D vt.TestGetSQLVars(drCols);
=20
tableName0 =3D Convert.ToString(SQLVarsList.GetByIndex(SQLVa=
rsList.IndexOfKey("10229^18")));=20
tableName1 =3D Convert.ToString(SQLVarsList.GetByIndex(SQLVa=
rsList.IndexOfKey("10231^18")));
Modified: humano2/branches/viewtools/components/viewTools/ViewColumns.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/viewtools/components/viewTools/ViewColumns.cs 2005-0=
7-07 03:37:39 UTC (rev 1447)
+++ humano2/branches/viewtools/components/viewTools/ViewColumns.cs 2005-0=
7-08 12:00:48 UTC (rev 1448)
@@ -72,6 +72,10 @@
set
{
this.fullAtt =3D value;
+ if (value.IndexOf("^") > 0)
+ {
+ value =3D value;
+ }
}
}
=20
Modified: humano2/branches/viewtools/components/viewTools/ViewTools.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/viewtools/components/viewTools/ViewTools.cs 2005-07-=
07 03:37:39 UTC (rev 1447)
+++ humano2/branches/viewtools/components/viewTools/ViewTools.cs 2005-07-=
08 12:00:48 UTC (rev 1448)
@@ -291,18 +291,30 @@
=20
#region "METODOS"
=20
- private SortedList getSQLVars(string strSelect, string strWhere)
+ private SortedList getSQLVars(string[] drCols)
{
+ SortedList res =3D new SortedList();
+ int globalIndex =3D 0;
+
+ string strSelect =3D drCols[0];
+ string [] strSelectArr =3D strSelect.Split(",".ToCharArray());
+
+ string strWhere =3D drCols[1];
+ string [] strWhereArr =3D strWhere.Split(";".ToCharArray());
+
+ //Parse strSelect and fill the sortedList
+ globalIndex =3D fillSortedListWithPertAttributes(res, strSelectArr, 0=
);
+ fillSortedListWithPertAttributes(res, strWhereArr, globalIndex);
+
+ if (drCols.Length >4)
+ {
+ string strOrder =3D drCols[4];
+ string [] strOrderArr =3D strOrder.Split(",".ToCharArray());
+ fillSortedListWithPertAttributes(res, strOrderArr, globalIndex);
+ }
//Logger.Log("<<getSQLVars>>", LogLevel.Trace);
- SortedList res =3D new SortedList();
=20
- //Parse strSelect and fill the sortedList
- string [] strSelectArr =3D strSelect.Split(",".ToCharArray()=
);
- string [] strWhereArr =3D strWhere.Split(";".ToCharArray());
- int globalIndex =3D 0;
- globalIndex =3D fillSortedListWithPertAttributes(res, strSel=
ectArr, 0);
- fillSortedListWithPertAttributes(res, strWhereArr, globalInd=
ex);
- return res;
+ return res;
}
=20
///<summary>With a list of attributes fills a sorted list with (=
att,SQLVar) id the att is a pert att</summary>
@@ -317,12 +329,14 @@
string att =3D fullAtt.Split("^".ToCharArray())[0]; //Re=
move target if pertinence
Logger.Log("att: " + att,LogLevel.Trace);
bool isPert =3D fullAtt.IndexOf('^') !=3D -1;
- if(!list.ContainsKey(fullAtt) && isPert)
+ //FIXME: do a split fullAtt on ^ to remove remote attribute
+ // also fix all the calls to SQLVarsList.IndexOfKey to do the same
+ if(!list.ContainsKey(att) && isPert)
{
Logger.Log(fullAtt + " added",LogLevel.Trace);
string tableId =3D Complex.GetPertinenceClassForAttr=
ibute(att); =20
string tableName =3D (Complex.GetClassSysName(tableI=
d) + index).Replace(" ",""); //Don't forget to remove spaces... This is a=
SQL variable!!
- list.Add(fullAtt,tableName);
+ list.Add(att,tableName);
index++;
}
}
@@ -332,7 +346,7 @@
public void ChangeSelect(string strSelect, string strWhere)
{
Select =3D SQLSelect(strSelect);
- From =3D SQLFrom(strSelect,strWhere);
+ From =3D SQLFrom(strSelect,strWhere,"");
Where =3D SQLWhere(strWhere);
}
=20
@@ -554,7 +568,7 @@
return Query.ToString();
}
=20
- public string SQLFrom(string param1, string param2)
+ public string SQLFrom(string param1, string param2, string order)
{
string inheritance =3D GetInheritance(IdClass);
StringBuilder Query =3D new StringBuilder();
@@ -580,6 +594,14 @@
}
}
}
+ if(order !=3D String.Empty)
+ {
+ foreach(string p in order.Split(",".ToCharArray()))
+ {
+ string[] arrFilters =3D p.Split("|".ToCharArray());
+ cols.Add(arrFilters[0]);
+ }
+ }
=09
relations =3D GetRelatedTableList((string[])cols.ToArray(typeof(strin=
g)));
if(relations.Length > 0)
@@ -603,7 +625,7 @@
}
=09
//Here use SQLVars to build from query
- string SQLVar =3D Convert.ToString(this.SQLVars.GetB=
yIndex(this.SQLVars.IndexOfKey(relation.IdPK + "^" + relation.IdFK)));
+ string SQLVar =3D Convert.ToString(this.SQLVars.GetB=
yIndex(this.SQLVars.IndexOfKey(relation.IdPK.ToString())));
Query.Append(relationType + relation.EndTableName + " " + SQLVar);
Logger.Log("fromColumnIndex=3D " + relation.IdPK, Lo=
gLevel.Trace);
Logger.Log("toColumnIndex=3D " + relation.IdFK, LogL=
evel.Trace);
@@ -698,6 +720,14 @@
order =3D GetOrder(param.Split(",".ToCharArray()));
if(order !=3D String.Empty)
{
+ //Here use SQLVars to build from query
+ /*string SQLVar =3D Convert.ToString(this.SQLVars.GetByIndex(this.S=
QLVars.IndexOfKey(relation.IdPK.ToString())));
+ Query.Append(relationType + relation.EndTableName + " " + SQLVar);
+ Logger.Log("fromColumnIndex=3D " + relation.IdPK, LogLevel.Trace);
+ Logger.Log("toColumnIndex=3D " + relation.IdFK, LogLevel.Trace);
+ Query.Append(" ON " + relation.IniTableName + "." + relation.Primar=
yKeyName);
+ Query.Append(" =3D " + SQLVar + "." + relation.ForeignKeyName);
+*/
Query.Append("ORDER BY " + order);
return Query.ToString();
}
@@ -722,9 +752,9 @@
///<summary>Init the SQLVars with select and where strings</summ=
ary>
///<param name=3D"strSelect">The select string</param>
///<param name=3D"strWhere">The where string</param>
- private void initSQLVars(string strSelect, string strWhere)
+ private void initSQLVars(string[] drCols)
{
- this.SQLVars =3D getSQLVars(strSelect,strWhere); =20
+ this.SQLVars =3D getSQLVars(drCols); =20
}
=20
public string ParseQuery(DataTable Params)
@@ -759,7 +789,7 @@
=20
//Paso 0:
//Here set the SortedList that contains the SQLVars
- initSQLVars(dataRowColumns[0],dataRowColumns[1]); //column a=
nd where conditions
+ initSQLVars(dataRowColumns); //column and where conditions
=09
//Paso 1:
//Determinar Tablas y Columnas afectadas en la consulta
@@ -769,7 +799,8 @@
=20
//Paso 2:
//Construir FROM
- Query.Append(SQLFrom(dataRowColumns[0],dataRowColumns[1]));
+ =09
+ Query.Append(SQLFrom(dataRowColumns[0],dataRowColumns[1],dataRowColum=
ns[4]));
//Logger.Log("FromParam: " + dataRowColumns[1],LogLevel.Trac=
e );
=20
//Paso 3:
@@ -1004,17 +1035,25 @@
string parameter;
string[] cols;
int columnIndex;
- string tableName, columnName;
+ string tableName =3D "", columnName;
=20
foreach(string Filtro in strParams)
{
parameters =3D Filtro.Split("|".ToCharArray());
cols =3D parameters[0].Split("^".ToCharArray());
columnIndex =3D Convert.ToInt32(cols[cols.Length - 1]);
-
+ =09
if(columnIndex !=3D 0)
{
- tableName =3D Complex.TableName(columnIndex);
+ int index =3D this.SQLVars.IndexOfKey(cols[0]);
+ if (index !=3D -1 )
+ {
+ tableName =3D Convert.ToString(this.SQLVars.GetByIndex(this.SQLVar=
s.IndexOfKey(cols[0])));
+ }
+ else
+ {
+ tableName =3D Complex.TableName(columnIndex);
+ }
columnName =3D Complex.ColumnName(columnIndex);
}
else
@@ -1392,12 +1431,20 @@
{
ViewColumns aux =3D new ViewColumns(0,"id_entity");
aux.Position =3D i;
- aux.Type =3D "int"; =20
+ aux.Type =3D "int";
+ aux.FullAtt =3D valor.Substring(0,valor.IndexOf("^"));
Table.AddColumn(aux);
i++;
}
=20
- Col.FullAtt =3D valor; //Will be used as a key with SQLV=
ars then
+ if (valor.IndexOf("^")>0)
+ {
+ Col.FullAtt =3D valor.Substring(0,valor.IndexOf("^")); //Will be us=
ed as a key with SQLVars then
+ }
+ else
+ {
+ Col.FullAtt =3D valor; //Will be used as a key with SQLVars then
+ }
=20
Table.AddColumn(Col);
Col.Position =3D i;
@@ -1755,14 +1802,14 @@
return getTableList(strParams);
}
=20
- public SortedList TestGetSQLVars(string strSelect, string strWhe=
re)
+ public SortedList TestGetSQLVars(string[] drCols)
{
- return getSQLVars(strSelect,strWhere); =20
+ return getSQLVars(drCols); =20
}
=20
- public void TestInitSQLVars(string strSelect, string strWhere)
+ public void TestInitSQLVars(string[] drCols)
{
- initSQLVars(strSelect, strWhere);
+ initSQLVars(drCols);
}
=20
#endregion
Modified: humano2/branches/viewtools/components/webTools/Adapter.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/viewtools/components/webTools/Adapter.cs 2005-07-07 =
03:37:39 UTC (rev 1447)
+++ humano2/branches/viewtools/components/webTools/Adapter.cs 2005-07-08 =
12:00:48 UTC (rev 1448)
@@ -462,13 +462,22 @@
Humano2.Components.ViewTools.ViewTools vt =3D new Humano2.Components.=
ViewTools.ViewTools(7);
vt.Complex =3D complex;
=20
- //Estructuras necesatias para llamar a view tools
+ //Necesary structure for Viewtools:
+ //The dataTable MUST contain at lease 6 columns
DataTable tabla =3D new DataTable();
DataColumn columna;
columna =3D new DataColumn("columna",typeof(string));
tabla.Columns.Add(columna);
columna =3D new DataColumn("filtros",typeof(string));
tabla.Columns.Add(columna);
+ columna =3D new DataColumn("relleno1",typeof(string));
+ tabla.Columns.Add(columna);
+ columna =3D new DataColumn("relleno2",typeof(string));
+ tabla.Columns.Add(columna);
+ columna =3D new DataColumn("relleno3",typeof(string));
+ tabla.Columns.Add(columna);
+ columna =3D new DataColumn("relleno4",typeof(string));
+ tabla.Columns.Add(columna);
=20
//La consulta que retorna el id del usuario
string[] fila =3D {"0","18|4|'" + user + "'|1|0;19|4|'" + password + =
"'|0|0"};
|