|
From: <sv...@de...> - 2005-06-29 23:01:45
|
Author: pcamacho
Date: 2005-06-29 19:01:46 -0400 (Wed, 29 Jun 2005)
New Revision: 1435
Modified:
humano2/branches/viewtools/components/tests/viewTools.cs
humano2/branches/viewtools/components/viewTools/ViewColumns.cs
humano2/branches/viewtools/components/viewTools/ViewTools.cs
Log:
CHANGE: SQLVars integrated to the build of SELECT string.
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-06-29 2=
2:12:11 UTC (rev 1434)
+++ humano2/branches/viewtools/components/tests/viewTools.cs 2005-06-29 2=
3:01:46 UTC (rev 1435)
@@ -71,7 +71,7 @@
}
=20
=20
- //[Test]
+ [Test]
public void SQLSelect()
{
init(); =20
@@ -80,32 +80,41 @@
vt.Complex =3D complex;
vt.KeyFlag =3D 0;
=20
+ //Don't forget to init SQLVars!!!
+ =20
+ =20
//Simple columns
+ vt.TestInitSQLVars("10181",""); //Don't forget to init SQLVa=
rs!
string strSelect =3D vt.SQLSelect("10181");
Logger.Log("SQLSelect(\"10181\"): " + strSelect,LogLevel.Tra=
ce);
- Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT d10160cTicket0=
.\"c10162Title\"".Trim());
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Title\"".Trim());
strSelect =3D vt.SQLSelect("0,10181");
Logger.Log("SQLSelect(\"0,10181\"): " + strSelect,LogLevel.T=
race);
- Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT d10160cTicket0=
.id_entity, d10160cTicket1.\"c10162Title\"".Trim());
+ 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!
strSelect =3D vt.SQLSelect("10231");
Logger.Log("SQLSelect(\"10231\"): " + strSelect,LogLevel.Tra=
ce);
- Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT d10160cTicket0=
.\"c10162Assigned to3\"".Trim());
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Assigned to3\"".Trim());
=20
+ vt.TestInitSQLVars("10231^18",""); //Don't forget to init SQ=
LVars!
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!
strSelect =3D vt.SQLSelect("10181,10231^18");
Logger.Log("SQLSelect(\"10181,10231^18\"): " + strSelect,Log=
Level.Trace);
- Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT d10160cTicket0=
.\"c10162Title\", user0.\"email\"".Trim());
+ Assert.IsTrue(strSelect.Trim() =3D=3D "SELECT \"d10160cTicke=
t\".\"c10162Title\", user0.\"email\"".Trim());
=20
+ vt.TestInitSQLVars("10187^10179",""); //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!
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
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=
6-29 22:12:11 UTC (rev 1434)
+++ humano2/branches/viewtools/components/viewTools/ViewColumns.cs 2005-0=
6-29 23:01:46 UTC (rev 1435)
@@ -27,6 +27,7 @@
private Enums.AggregateFunctions _func;
private int _position;
private string _type;
+ private string fullAtt; //The full attribute value of column. Ex=
ample: 10179^10187 or 10167 etc...
#endregion
=20
#region "CONSTRUCTORS"
@@ -61,6 +62,18 @@
this._type =3D value;
}
}
+ =20
+ public string FullAtt
+ {
+ get
+ {
+ return this.fullAtt;
+ }
+ set
+ {
+ this.fullAtt =3D value;
+ }
+ }
=20
public Enums.AggregateFunctions Function
{
@@ -157,4 +170,4 @@
}
#endregion
}
-}
\ No newline at end of file
+}
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-06-=
29 22:12:11 UTC (rev 1434)
+++ humano2/branches/viewtools/components/viewTools/ViewTools.cs 2005-06-=
29 23:01:46 UTC (rev 1435)
@@ -36,6 +36,7 @@
private string _whereInit =3D "";
private bool _caseSensitive; //To allow doing insensitive case s=
earch
private string query; //To get the query from outside
+ private SortedList SQLVars; //The sql vars used to build the fin=
al query =20
=20
#endregion
=20
@@ -456,6 +457,7 @@
///<param name=3D"number">The number to concatenate</param>
///<param name=3D"sqlTableName">The name of table</param>
///<returns>[name of table(without quotes)] + number.ToString</r=
eturns>
+ /*
private string getSQLTableVar(string sqlTableName, int number)
{
string res =3D "";
@@ -468,7 +470,9 @@
string res =3D sqlTableName + " " + getSQLTableVar(sqlTableN=
ame,number); =20
return res;
}
+ */
=20
+ =20
public string SQLSelect(string param)
{
Logger.Log("<<SQLSelect:>>",LogLevel.Trace);
@@ -487,14 +491,25 @@
{
affectedColumns =3D table.Columns;
int index =3D 0;
- foreach(ViewColumns Cols in affectedColumns)
+ foreach(ViewColumns Col in affectedColumns)
{
aux =3D new DisplayOrder();
- string tableAffectedName =3D getSQLTableVar(table.Ta=
bleName,index++);
+ =20
+ //if the column is in the SQLVars then find the name=
in SQLVars else choose table.TableName
+ string tableAffectedName =3D "";
+ if(this.SQLVars.ContainsKey(Col.FullAtt))
+ {
+ tableAffectedName =3D Convert.ToString(this.SQLV=
ars.GetByIndex(this.SQLVars.IndexOfKey(Col.FullAtt))); //getSQLTableVar(=
table.TableName,index++);
+ }
+ else
+ {
+ tableAffectedName =3D table.TableName;
+ }
+ =20
string beginFunction =3D "";
string endFunction =3D "";
=20
- switch(Cols.Function)
+ switch(Col.Function)
{
case Enums.AggregateFunctions.nofunc:
beginFunction =3D "";
@@ -509,10 +524,10 @@
endFunction =3D ")";
break;
}
- aux.Text =3D beginFunction + tableAffectedName + end=
Function + "." + Cols.ColumnName + ", ";
- aux.Position =3D Cols.Position;
- aux.Id =3D Cols.ColumnIndex;
- aux.Type =3D Cols.Type;
+ aux.Text =3D beginFunction + tableAffectedName + end=
Function + "." + Col.ColumnName + ", ";
+ aux.Position =3D Col.Position;
+ aux.Id =3D Col.ColumnIndex;
+ aux.Type =3D Col.Type;
values.Add(aux);
i++;
}
@@ -593,7 +608,6 @@
relations =3D GetRelatedTableList((string[])cols.ToArray(typeof(strin=
g)));
if(relations.Length > 0)
{
- //ViewRelation previousRelation =3D null;=09
string relationType =3D "";
ArrayList tableDictionary =3D new ArrayList();
int counter =3D 1;
@@ -615,18 +629,12 @@
Query.Append(relationType + relation.EndTableName);
Query.Append(" ON " + relation.IniTableName + "." + relation.Primar=
yKeyName);
Query.Append(" =3D " + relation.EndTableName + "." + relation.Forei=
gnKeyName);
-// Query.Append(" relTbl"+counter+" ON tblA." + relation.PrimaryKeyN=
ame);
-// Query.Append(" =3D relTbl"+counter+"." + relation.ForeignKeyName)=
;
- //previousRelation =3D relation;
=20
if(tableDictionary.IndexOf(relation.EndTableName) =3D=3D -1)
{
tableDictionary.Add(relation.EndTableName);
Query.Append(" LEFT JOIN entity e" + counter + " ON ");
Query.Append(relation.EndTableName + ".id_entity =3D e" + counter =
+ ".id_entity ");
-// Query.Append("relTbl"+counter+ ".id_entity =3D e" + counter + ".=
id_entity ");
-
- // Query.Append("AND e" + counter + ".\"delDate\" IS NULL ");
_whereInit =3D _whereInit + "e" + counter + ".\"delDate\" IS NULL =
AND ";
counter++;
}
@@ -730,13 +738,21 @@
return Query.ToString();
}
=20
+ ///<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)
+ {
+ this.SQLVars =3D getSQLVars(strSelect,strWhere); =20
+ }
+ =20
public string ParseQuery(DataTable Params)
{
DataRow objRow;
object[] objArray;
=20
objRow =3D Params.Rows[0];
-
+ =20
string res =3D ViewCache.Instance().GetCachedStatement(objRow, PageVi=
ew) ;
if( res !=3D null )
{ // We got the cached datatable result. lets return that and not con=
struct a new one again.
@@ -759,6 +775,10 @@
dataRowColumns[j] =3D String.Empty;
}
}
+
+ //Paso 0:
+ //Here set the SortedList that contains the SQLVars
+ initSQLVars(dataRowColumns[0],dataRowColumns[1]); //column a=
nd where conditions
=09
//Paso 1:
//Determinar Tablas y Columnas afectadas en la consulta
@@ -1313,7 +1333,8 @@
//Logger.Log("getTableList. Loop",LogLevel.Trace);
//Logger.Log("getTableList. param=3D " + Indice,LogLevel=
.Trace);
string valor =3D Indice.Split("|".ToCharArray()).GetValu=
e(0).ToString();
- if(IsNumeric(valor))
+ =09
+ if(IsNumeric(valor))
{
columnIndex =3D Convert.ToInt32(valor);
}
@@ -1384,6 +1405,9 @@
Table.AddColumn(aux);
i++;
}
+ =20
+ Col.FullAtt =3D valor; //Will be used as a key with SQLV=
ars then
+ =20
Table.AddColumn(Col);
Col.Position =3D i;
i++;
@@ -1746,7 +1770,12 @@
{
return getSQLVars(strSelect,strWhere); =20
}
-
+ =20
+ public void TestInitSQLVars(string strSelect, string strWhere)
+ {
+ initSQLVars(strSelect, strWhere);
+ }
+ =20
#endregion
}
}
|