Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Expression evaluation will be supported?

2 posts in DataWindow .NET Last posting was on 2004-09-21 01:20:17.0Z
Lu Posted on 2004-09-21 00:57:37.0Z
Reply-To: "Lu" <luzhongren@newspace.jp>
From: "Lu" <luzhongren@newspace.jp>
Newsgroups: sybase.public.datawindow.net
Subject: Expression evaluation will be supported?
Lines: 6
Organization: NewSpace
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-2022-jp"; reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-Original-NNTP-Posting-Host: usen-221x115x175x218.ap-us01.usen.ad.jp
Message-ID: <414f7e51$1@forums-2-dub>
X-Original-Trace: 20 Sep 2004 18:05:21 -0700, usen-221x115x175x218.ap-us01.usen.ad.jp
X-Original-NNTP-Posting-Host: forums-2-dub.sybase.com
X-Original-Trace: 20 Sep 2004 17:45:00 -0700, forums-2-dub.sybase.com
NNTP-Posting-Host: forums-master.sybase.com
X-Original-NNTP-Posting-Host: forums-master.sybase.com
Date: 20 Sep 2004 17:57:37 -0700
X-Trace: forums-1-dub 1095728257 10.22.108.75 (20 Sep 2004 17:57:37 -0700)
X-Original-Trace: 20 Sep 2004 17:57:37 -0700, forums-master.sybase.com
X-Authenticated-User: ngsysop
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.datawindow.net:409
Article PK: 124838

In Pb, there is an evaluate function or to get expression value like ls_ret
= dw_1.Describe( "Evaluate('If(salary > 100000, 255,0)', 3)").
In dw .net, has such kind of functions?

Thanks


MDesai Posted on 2004-09-21 01:20:17.0Z
Sender: 477.414f809e.1804289383@sybase.com
From: Mdesai
Newsgroups: sybase.public.datawindow.net
Subject: Re: Expression evaluation will be supported?
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <414f81d1.487.1681692777@sybase.com>
References: <414f7e51$1@forums-2-dub>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="-=_forums-1-dub414f81d1"
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 20 Sep 2004 18:20:17 -0700
X-Trace: forums-1-dub 1095729617 10.22.241.41 (20 Sep 2004 18:20:17 -0700)
X-Original-Trace: 20 Sep 2004 18:20:17 -0700, 10.22.241.41
Lines: 210
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.datawindow.net:410
Article PK: 124840

Attached C# class might help you...

> In Pb, there is an evaluate function or to get expression
> value like ls_ret = dw_1.Describe( "Evaluate('If(salary >
> 100000, 255,0)', 3)"). In dw .net, has such kind of
> functions?
>
> Thanks
>

using System;
namespace test
{
/// <summary>
/// Summary description for exprChecker.
/// </summary>
public class exprChecker
{
Sybase.DataWindow.DataStore idsAssnt;
Sybase.DataWindow.DataStore idsResponse;
Sybase.DataWindow.DataStore idsRule;
Sybase.DataWindow.Transaction SQLCA;
string isAssn,isMainQnr,isAddQnr;
string isLastError;
public exprChecker()
{
idsAssnt = new Sybase.DataWindow.DataStore("C:\\dwdotnet\\test\\dwobject.pbl","d_assnt");
idsResponse= new Sybase.DataWindow.DataStore("C:\\dwdotnet\\test\\dwobject.pbl","d_response");
idsRule = new Sybase.DataWindow.DataStore("C:\\dwdotnet\\test\\dwobject.pbl","d_qtn_rule");
SQLCA = new Sybase.DataWindow.Transaction();
//
// TODO: Add constructor logic here
//
}
public bool connectDb()
{

SQLCA.AutoCommit=true;
SQLCA.Dbms=Sybase.DataWindow.DbmsType.OleDb;
SQLCA.UserId="sa";
SQLCA.Password="sa";
SQLCA.DbParameter="PROVIDER='SQLOLEDB',DATASOURCE='mel-itd-clone11\\ins',PROVIDERSTRING='database=sncaus'";
try
{
SQLCA.Connect();
}
catch (Sybase.DataWindow.TransactionException ex)
{
isLastError=ex.SqlDbCode + ": "+ex.SqlErrorText;
}
catch (System.Exception ex)
{
isLastError=ex.Message;
}
return SQLCA.IsConnected;
}
public int retrieveAssnt()
{
int liRow=-1;
//retrieve assignment info
try
{
this.idsAssnt.SetTransaction(SQLCA);
liRow=this.idsAssnt.Retrieve(this.isAssn);
}
catch (Sybase.DataWindow.DbErrorException ex )
{
liRow=-1;
isLastError="Database Code: "+ex.SqlDbCode+", Error Text: "+ex.SqlErrorText;
}
catch (System.Exception ex)
{
liRow=-1;
isLastError=ex.Message;
}
return liRow;
}
public int retrieveResponse()
{
int liRow;
//retrieve response info
try
{
this.idsResponse.SetTransaction(SQLCA);
liRow=this.idsResponse.Retrieve(this.isAssn,this.isMainQnr,this.isAddQnr);
}
catch (Sybase.DataWindow.DbErrorException ex )
{
liRow=-1;
isLastError="Database Code: "+ex.SqlDbCode+", Error Text: "+ex.SqlErrorText;
}
catch (System.Exception ex)
{
liRow=-1;
isLastError=ex.Message;
}
return liRow;
}
public int retrieveRule()
{
int liRow;
//retrieve response info
try
{
this.idsRule.SetTransaction(SQLCA);
liRow=this.idsRule.Retrieve(this.isMainQnr,this.isAddQnr);
}
catch (Sybase.DataWindow.DbErrorException ex )
{
liRow=-1;
isLastError="Database Code: "+ex.SqlDbCode+", Error Text: "+ex.SqlErrorText;
}
catch (System.Exception ex)
{
liRow=-1;
isLastError=ex.Message;
}
return liRow;
}
public bool setUp()
{
const string COMMENT_DELIMITER="~t>";
const string DISP_DURATION="SEC";
const string DISP_NUM="NUM";
bool lbRet=true;
int liY=0,liCount,liPos;
string lsField,lsStr,lsResp,lsAllControls,lsDisplayType;

//ls_ret = idsAssnt.Describe("evaluate(\"not (1=1 and 4>3 and 1>0 and 'Yes'='yes')\",1)");
//Get no of questions
//return false;
liCount = idsResponse.RowCount;

//Get all controls in a string
lsAllControls = "\t"+idsAssnt.Describe("Datawindow.Objects")+"\t";

//setup qtn_name with default value in dw_assn for evaluating expression
for (int i=1; i<=liCount; i=i+1)
{
lsDisplayType=idsResponse.GetItemString(i,"display_type");
lsField=idsResponse.GetItemString(i, "qtn_name");
lsField=lsField.ToLower().Trim();
idsResponse.SetItemString(i,"qtn_name",lsField);
if (lsField.Length<=0) continue;
if (lsDisplayType=="PICK"||lsDisplayType=="MPICK")
{
lsResp = idsResponse.GetItemString( i,"qtn_comment");
if(lsResp==null)
lsResp="X";
else
{
liPos=lsResp.IndexOf(COMMENT_DELIMITER);
if(liPos>0) lsResp = lsResp.Substring(liPos+COMMENT_DELIMITER.Length);
}
lsResp = "\"'+ls_resp +'\"";
}
else
{
lsResp = idsResponse.GetItemString( i, "resp_raw");
if (lsDisplayType==DISP_DURATION || lsDisplayType==DISP_NUM)
{
if (lsResp==null || lsResp=="")
{
lsResp = "\"-99\"";
}
else
{
if (lsDisplayType==DISP_DURATION)
{
lsResp = idsResponse.GetItemDecimal( i, "resp_raw_num").ToString();
if (lsResp==null || lsResp=="")
{
lsResp = "\"-99\"";
}
else
{
lsResp = "\"" + lsResp + "\"";
}
}
else
{
lsResp = "\"" + lsResp + "\"";
}
}
}
else
{
if (lsResp==null || lsResp=="")
lsResp = "\"'n/a'\"";
else
lsResp = "\"' + ls_resp + '\"";
}
if (lsAllControls.IndexOf("\t" + lsField + "\t")<=0)
{
//ls_resp = "123456789" // must be double quote
// new field
lsStr = "create compute(band=detail alignment=\"0\" ";
lsStr+="expression="+lsResp+" ";
//ls_str+="expression='0' ";
lsStr+="border=\"5\" ";
lsStr+="color=\"0\" ";
lsStr+="x=\"686\" ";
lsStr+="y=\""+liY+"\" ";
lsStr+="height=\"76\" ";
lsStr+="width=\"1371\" ";
lsStr+="format=\"[GENERAL]\" ";
lsStr+="html.valueishtml=\"0\" ";
lsStr+="name="+lsField +" ";
lsStr+="visible=\"1\" ";
lsStr+="font.face=\"Arial\" ";
lsStr+="font.height=\"-10\" ";
lsStr+="font.weight=\"700\" ";
lsStr+="font.family=\"2\" ";
lsStr+="font.pitch=\"2\" ";
lsStr+="font.charset=\"0\" ";
lsStr+="background.mode=\"2\" ";
lsStr+="background.color=\"12632256\" )";

try
{
idsAssnt.Modify( lsStr );
liY+=100;
}
catch (Sybase.DataWindow.MethodFailureException ex)
{
lbRet=false;
this.isLastError=ex.Message;
}
}
else
{
try
{
// existing field
lsStr = lsField + ".expression=" + lsResp;
idsAssnt.Modify( lsStr );
}
catch (Sybase.DataWindow.MethodFailureException ex)
{
lbRet=false;
this.isLastError=ex.Message;
}
}
}
}
lsAllControls = "\t"+idsAssnt.Describe("Datawindow.Objects")+"\t";
return lbRet;
}
public int checkRule(int aiRow)
{
string lsStr,lsExpr;
string lsResult;
//Get rule parameter
lsExpr = idsRule.GetItemString( aiRow, "eval_expr" );

// skip inactive rule
lsStr = idsRule.GetItemString( aiRow, "rule_status" );
if (lsStr=="C")
{
this.isLastError="Rule cancelled...";
return -1;
}
// skip SCoring rule
lsStr = idsRule.GetItemString( aiRow, "rule_type" );
if(lsStr!="EXPRS")
{
this.isLastError="Score Rule...";
return -1;
}


if (lsExpr.IndexOf("count_opt")>0)
{
this.isLastError="Return count_opt used in this rule";
return -1;
}
if (lsExpr.IndexOf("find_opt")>0)
{
this.isLastError="Return find_opt used in this rule";
return -1;
}
if (lsExpr.IndexOf("sum")>0)
{
this.isLastError="Return Sum used in this rule";
return -1;
}

// add the single quotes
//lsExpr= insertQuote(lsExpr);

lsExpr=lsExpr.ToLower();
lsExpr=lsExpr.Replace("yes","'yes'");
lsExpr=lsExpr.Replace("no","'no'");
lsExpr=lsExpr.Replace("na","'N/A'");
lsExpr=lsExpr.Replace("n/a","'N/A'");

try
{
lsExpr="evaluate(\"" + lsExpr + "\", 1)";
lsResult = idsAssnt.Describe(lsExpr);
}
catch (Sybase.DataWindow.MethodFailureException ex)
{
this.isLastError=ex.Message;
return -1;
}
if (lsResult=="true")
{
this.isLastError="Rule express return true";
return 1;
}
else
{
this.isLastError ="Rule express return false";
return 1;
}
}
public string insertQuote(string asExpr)
{
return asExpr;
}

public void checkExpr(string asAssn,string asMainQnr,string asAddQnr)
{

isAssn=asAssn;
isMainQnr=asMainQnr;
isAddQnr=asAddQnr;
}
public string getLastError()
{
return this.isLastError;
}
}
}