/*
;/doc/ ****************************************************************************************
;
; The method RefactorCode_FindAssign is used to find an assignment to a variable that is being
; used later in the code to supply a value. It is this value that needs to be modified.
;
;/doc/ ****************************************************************************************
*/
int RefactorCode_FindAssign(int varRoot,int iEnd)
{
tCodeBlock codptr;
int lastLev0;
int icode;
int addr;
int opcd;
int subcd;
codptr = Opcode.GetCode();
lastLev0 = 0;
for(icode = 0; icode >= 0; icode = Opcode.GetNext(codptr,icode,iEnd))
{
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd == OPC.LEV && subcd == 0) lastLev0 = icode;
else if(opcd == OPC.LDA && subcd == varRoot)
{
opcd = Opcode.GetOperation(codptr,icode+sizeof(OPC.LDA),subcd);
if(opcd == OPC.STR) return lastLev0;
}
}
return 0;
}
/*
;/doc/ ****************************************************************************************
;
; The method RefactorCode_RelaceAssign replaces a string argument with an constant relacement
; string.
;
;/doc/ ****************************************************************************************
*/
int RefactorCode_ReplaceAssign(int iAssign, string replacement)
{
tCodeBlock codptr
int RefactorCode_FindAssign(int varRoot,int iEnd)
{
tCodeBlock codptr;
int lastLev0;
int icode;
int addr;
int opcd;
int subcd;
codptr = Opcode.GetCode();
lastLev0 = 0;
for(icode = 0; icode >= 0; icode = Opcode.GetNext(codptr,icode,iEnd))
{
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd == OPC.LEV && subcd == 0) lastLev0 = icode;
else if(opcd == OPC.LDA && subcd == varRoot)
{
opcd = Opcode.GetOperation(codptr,icode+sizeof(OPC.LDA),subcd);
if(opcd == OPC.STR) return lastLev0;
}
}
return 0;
}
int RefactorCode_ReplaceAssign(int iAssign, string replacement)
{
tCodeBlock codptr;
int nCode;
int iEnd;
int nDelete;
int addr;
codptr = Opcode.GetCode();
nCode = Opcode.GetLength();
iEnd = Opcode.FindArgumentEnd(codptr,iAssign,nCode);
iAssign = iAssign + sizeof(OPC.LEV);
nDelete = iEnd - iAssign - sizeof(OPC.LSC) - sizeof(OPC.ARG);
if(nDelete > 0)
{
nCode = Opcode.DeleteCode(iAssign,nCode,nDelete);
Opcode.SetLength(nCode);
}
addr = Store.String(replacement);
Opcode.SetOperation(codptr,iAssign,OPC.LSC,addr);
return nDelete;
}
int __rdoConnection_Connect(int subRoot,int iStart,int iRefer)
{
tCodeBlock codptr;
int nCode;
int opcd;
int subcd;
int icode;
int iEnd;
int nCodelocalVar;
int iEndiAssign;
intstring nDeleteconnect;
int addriPos;
codptrint = Opcode.GetCode(); nCode = Opcode.GetLength()semi;
iEndint = Opcode.FindArgumentEnd(codptr,iAssign,nCode); iAssign = iAssignnDelete;
+ sizeof(OPC.LEV); int nDelete = iEnd - iAssign - sizeof(OPC.LSC) - sizeof(OPC.ARG); addr;
/*
Step if(nDelete > 0)
{
nCode = Opcode.DeleteCode(iAssign,nCode,nDelete1: Verify that this is a local variable assignment to a property.
*/
codptr = Opcode.GetCode();
nCode = Opcode.GetLength();
opcd = Opcode.SetLength(nCodeGetOperation(codptr,iStart,localVar);
if(opcd != }OPC.LDA) return 0;
addricode = Store.String(replacement);
iRefer + sizeof(OPC.LLP);
opcd = Opcode.SetOperationGetOperation(codptr,iAssign,OPC.LSC,addricode,subcd);
if(opcd != OPC.MEM) return nDelete;
}
/*
;/doc/ ****************************************************************************************
;
; transform the connection string (difficult to generalize; easily done with authorfix or
; runtime method)
; OLD: dbs = "UID=stocks_login;PWD=password;Database=stocks;" + "Server=GMI-CS-01.gmi.local;
; Driver={SQL Server};" + "DSN='';";
; NEW: dbs = "UID=stocks_login;PWD=password;Database=stocks;" + "Server=GMI-CS-01.gmi.local;";
;
;/doc/ ****************************************************************************************
*/
int __rdoConnection_Connect(int subRoot,int iStart,int iRefer)
{
tCodeBlock codptr;
int nCode;
int opcd;
int subcd;
int icode;
int0;
icode = icode + sizeof(OPC.MEM);
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.STR) return 0;
/*
Step 2: Look for a preceeding string assignent to this local variable.
*/
iAssign = RefactorCode_FindAssign(localVar,iStart);
if(iAssign == 0) return 0;
/*
Step 3: Obtain the actual string value being assigned to the local variable.
*/
iEnd = Opcode.FindArgumentEnd(codptr,iAssign,nCode);
connect = Opcode.GetString(iAssign,iEnd);
if(!connect) return 0;
/*
Step 4: Remove the atrribute-values pairs that are not to be used.
*/
iPos = Character.FindFirst(connect,0,"Driver=");
if(iPos)
{
iPos = iPos - 1;
semi = Character.FindFirst(connect,iPos,";");
if(semi)
{
iEnd;connect int localVar;
int iAssign;
string connect;
int iPos;
int semi;
int nDelete;
int addr;
/*
Step 1: Verify that this is a local variable assignment to a property.
*/
codptr = Opcode.GetCode();
nCode = Opcode.GetLength();
opcd = Opcode.GetOperation(codptr,iStart,localVar);
if(opcd != OPC.LDA) return 0;
icode = iRefer + sizeof(OPC.LLP);
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.MEM) return 0;
icode = icode + sizeof(OPC.MEM);
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.STR) return 0;
/*
Step 2: Look for a preceeding string assignent to this local variable.
*/
iAssign = RefactorCode_FindAssign(localVar,iStart);
if(iAssign == 0) return 0;
/*
Step 3: Obtain the actual string value being assigned to the local variable.
*/
iEnd = Opcode.FindArgumentEnd(codptr,iAssign,nCode);
connect = Opcode.GetString(iAssign,iEnd);
if(!connect) return 0;
/*
Step 4: Remove the atrribute-values pairs that are not to be used.
*/
iPos = Character.FindFirst(connect,0,"Driver=");
if(iPos)
{
iPos = iPos - 1;
semi = Character.FindFirst(connect,iPos,";");
if(semi)
{
connect = Character.Remove(connect,iPos,semi);
}
}
iPos = Character.FindFirst(connect,0,"DSN=");
if(iPos)
{
iPos = iPos - 1;
semi = Character.FindFirst(connect,iPos,";");
if(semi)
{
connect = Character.Remove(connect,iPos,semi);
}
}
/*
Step 5: Replace the old string expression with the revised string.
*/
nDelete = RefactorCode_ReplaceAssign(iAssign,connect);
iRefer = iRefer - nDelete;
return iRefer;
}
/*
;/doc/ ****************************************************************************************
;
; The tool needs to replace ? with incremented generic @# type parameters OR
; the tool could insert a runtime parser that replaces ? with @# typed parameters which need
; compensated for when adding the parameters Some consideration needs to be taken when considering
; that SQL strings can be built using various concat statements and variables.
; Our current sample and the issue provided by client did not include that scenerio.
; OLD: SQL = "select * from accounts where accountID < ? and FirstName like ?";
; NEW: SQL = "select * from accounts where accountID < @0 and FirstName like @1";
;
;/doc/ ****************************************************************************************
*/= Character.Remove(connect,iPos,semi);
}
}
iPos = Character.FindFirst(connect,0,"DSN=");
if(iPos)
{
iPos = iPos - 1;
semi = Character.FindFirst(connect,iPos,";");
if(semi)
{
connect = Character.Remove(connect,iPos,semi);
}
}
/*
Step 5: Replace the old string expression with the revised string.
*/
nDelete = RefactorCode_ReplaceAssign(iAssign,connect);
iRefer = iRefer - nDelete;
return iRefer;
}
int __rdoConnection_CreateQuery(int subRoot,int iStart,int iRefer)
{
tCodeBlock codptr;
int nCode;
int opcd;
int subcd;
int icode;
int sqlString;
int sqlVar;
string query;
int iAssign;
int index;
int iPos;
int lPos;
int nDelete;
int createCommand;
int iEnd;
/*
Step 1: Make certain that this is a valid CreateQuery call and obtain the variable that contains the
SQL Query
*/
codptr = Opcode.GetCode();
nCode = Opcode.GetLength();
icode = iRefer;
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.LLP) return 0;
icode = icode + sizeof(OPC.LLP);
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.MEM) return 0;
icode = icode + sizeof(OPC.MEM);
opcd = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.LEV) return 0;
sqlString = Opcode.FindArgumentEnd(codptr,icode,nCode);
opcd = Opcode.GetOperation(codptr,sqlString,subcd);
if(opcd != OPC.LEV) return 0;
sqlString = sqlString + sizeof(OPC.LEV);
opcd = Opcode.GetOperation(codptr,sqlString,sqlVar);
if(opcd != OPC.LDA) return 0;
sqlString = sqlString+sizeof(OPC.LDA);
opcd = Opcode.GetOperation(codptr,sqlString,subcd);
if(opcd != OPC.ARG) return 0;
sqlString = sqlString+sizeof(OPC.ARG);
/*
Step 2: Look for a preceeding string assignent to this local variable.
*/
iAssign = RefactorCode_FindAssign(sqlVar,iRefer);
if(iAssign == 0) return 0;
/*
Step 3: Obtain the actual string value being assigned to the local variable.
*/
iEnd = Opcode.FindArgumentEnd(codptr,iAssign,nCode);
query = Opcode.GetString(iAssign,iEnd);
if(!query) return 0;
/*
Step 4: If there is a constant query string replace the ?'s with @index and
if necessary relace it in the code.
*/
if(iAssign)
{
iPos = 0;
for(index = 0; index < 10; index = index + 1)
{
lPos = Character.FindFirst(query,iPos,"?");
if(!lPos) break;
iPos = iPos + lPos - 1;
query = Character.Remove(query,iPos,1);
query = Character.Insert(query,iPos,"@" + index);
}
if(iPos != 0)
{
nDelete = RefactorCode_ReplaceAssign(iAssign,query);
iRefer = iRefer - nDelete;
sqlString = sqlString - nDelete;
}
}
/*
Step 5: Replace the CreateQuery call with a CreateCommannd call.
*/
iEnd = sqlString;
opcd = Opcode.GetOperation(codptr,iEnd,subcd);
if(opcd != OPC.CUF) return 0;
iEnd = iEnd + sizeof(OPC.CUF);
opcd = Opcode.GetOperation(codptr,iEnd,subcd);
if(opcd != OPC.REF) return 0;
iEnd = iEnd + sizeof(OPC.REF);
opcd = Opcode.GetOperation(codptr,iEnd,subcd);
if(opcd != OPC.ARG) return 0;
iEnd = iEnd + sizeof(OPC.ARG);
opcd = Opcode.GetOperation(codptr,iEnd,subcd);
if(opcd != OPC.CMD) return 0;
iEnd = iEnd + sizeof(OPC.CMD);
nDelete = iEnd - sqlString - sizeof(OPC.PAT);
createCommand = Symbol.FindIdentifier("RDO.DotNet.CreateCommand");
nCode = Opcode.DeleteCode(sqlString,nCode,6);
Opcode.SetLength(nCode);
Opcode.SetOperation(codptr,sqlString,OPC.PAT,createCommand);
return iRefer;
}
int rdoPreparedStatement_OpenResultsetrdoParameters(int subRoot,int iStarticode,int iRefer)
{
tCodeBlockint codptr; int nCode;
inttCodeBlock opcdcodptr;
int subcdiEnd;
int icodeopcd;
int varRoot; tVariable varInfosubc;
/* int Step 1: Make certain the reference is present and obtainparameters; the root
of the results nCode = variable.
*/Opcode.GetLength();
codptr = Opcode.GetCode();
iEnd = Opcode.FindArgumentEnd(codptr,iRefer+7,nCode);
opcd = Opcode.GetLength()GetOperation(codptr,iEnd,subc);
if(opcd != OPC.COL || subc != OPC.COL.Item) return 0;
icodeparameters = iReferSymbol.FindIdentifier("RDO.DotNet.Parameters");
opcdnCode = Opcode.GetOperationExpandCode(codptriEnd,icode,subcd);
if(opcd != OPC.REF) return 0nCode,sizeof(OPC.PAT) - sizeof(OPC.COL));
icode = icode + sizeof(OPC.REFOpcode.SetLength(nCode);
opcd = Opcode.GetOperationSetOperation(codptr,iEnd,icodeOPC.PAT,subcdparameters);
return iRefer;
}
int if(opcd != OPC.ARG) return 0;
icode = icode + sizeof(OPC.ARG);rdoPreparedStatement_OpenResultset(int subRoot,int iStart,int iRefer)
{
tCodeBlock codptr;
int opcd = Opcode.GetOperation(codptr,icode,subcd) nCode;
if(opcdint != OPC.CMD) return 0; opcd;
= Opcode.GetOperation(codptr,iStart,varRoot); int if(opcd != OPC.LDA) return 0; /* subcd;
Step 2:int Set the DEADCODE property of the results variableicode;
to True to blockint its declaration.
*/ varInfo = Store.DeltaVector(varRoot);
varInfo.DeadCodetVariable = TruevarInfo;
/*
Step 31: Make Changecertain the SETreference command to an using commandis present and insertobtain the typeroot declarationof code in it
the results
for the results variable.
*/
codptr = Opcode.SetOperation(codptr,icode,OPC.IFS,OPC.IFS.UsingGetCode();
nCode = Opcode.ExpandCode(icode,nCode,sizeof(OPC.TYV)GetLength();
Opcode.SetLength(nCode);icode = iRefer;
opcd = Opcode.SetOperationGetOperation(codptr,icode,OPC.TYV,varRootsubcd);
if(opcd != OPC.REF) return iRefer0;
} int rdoPreparedStatement_rdoParameters(int subRoot,int icode,int iRefer)
{icode = icode + sizeof(OPC.REF);
opcd int = Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.ARG) return nCode0;
tCodeBlockicode = codptr;icode int + sizeof(OPC.ARG);
opcd iEnd= Opcode.GetOperation(codptr,icode,subcd);
int if(opcd != OPC.CMD) return 0;
opcd opcd= Opcode.GetOperation(codptr,iStart,varRoot);
intif(opcd != OPC.LDA) return 0;
/*
subc;Step 2: Set the intDEADCODE property of the results variable to True to parameters; block its declaration.
*/
nCodevarInfo = OpcodeStore.GetLengthDeltaVector();
codptr = Opcode.GetCode();
iEnd = Opcode.FindArgumentEnd(codptr,iRefer+7,nCode);
opcd = Opcode.GetOperation(codptr,iEnd,subc);
if(opcd != OPC.COL || subc != OPC.COL.Item) return 0;
parameters = Symbol.FindIdentifier("RDO.DotNet.Parameters"varRoot);
varInfo.DeadCode = True;
/*
Step 3: Change the SET command to an using command and insert the type declaration code in it
for the results variable.
*/
Opcode.SetOperation(codptr,icode,OPC.IFS,OPC.IFS.Using);
nCode = Opcode.ExpandCode(iEndicode,nCode,3sizeof(OPC.TYV));
Opcode.SetLength(nCode);
Opcode.SetOperation(codptr,iEndicode,OPC.PATTYV,parametersvarRoot);
return iRefer;
}
int rdoPreparedStatement_Close(int subRoot,int icode,int iRefer)
{
int nCode;
tCodeBlock codptr;
iRefer = Opcode.CommentOut(iRefer,OPC.CMT.Delete);
iRefer = iRefer + sizeof(OPC.CMT);
nCode = Opcode.GetLength();
codptr = Opcode.GetCode();
nCode = Opcode.ExpandCode(iRefer,nCode,sizeof(OPC.IFS));
Opcode.SetLength(nCode);
Opcode.SetOperation(codptr,iRefer,OPC.IFS,OPC.IFS.EndUsing);
return iRefer;
}
int __rdoColumn_Value(int subRoot,int icode,int iRefer)
{
int nCode;
tCodeBlock codptr;
}
int __rdoResultset_EOF(int subRoot,int iStart,int iRefer)
{
int nCode;
tCodeBlock codptr;
int opcd;
int subcd;
int icode;
nCode = Opcode.GetLength();
codptr = Opcode.GetCode();
nCodeicode = Opcode.DeleteCode(iRefer,nCode,7); Opcode.SetLength(nCode+ sizeof(OPC.LLP);
returnopcd iRefer;
}
int __rdoResultset_rdoColumns(int subRoot,int icode,int iRefer)
{
int nCode;
tCodeBlock codptr= Opcode.GetOperation(codptr,icode,subcd);
if(opcd != OPC.MEM) return 0;
icode = icode + sizeof(OPC.MEM);
nCodeopcd = Opcode.GetLengthGetOperation(codptr,icode,subcd);
codptrif(opcd != OpcodeOPC.GetCode()NOT) return 0;
nCode = Opcode.DeleteCode(iRefericode,nCode,7sizeof(OPC.NOT));
Opcode.SetLength(nCode);
return iRefer;
}
int __rdoResultsetrdoColumn_EOFValue(int subRoot,int icode,int iRefer)
{
int nCode;
tCodeBlock codptr;
nCode = Opcode.GetLength();
codptr = Opcode.GetCode();
nCode = Opcode.DeleteCode(iRefer+7,nCode,2sizeof(OPC.LLP) + sizeof(OPC.MEM));
Opcode.SetLength(nCode);
return iRefer;
}
int __rdoResultset_MoveNextrdoColumns(int subRoot,int icode,int iRefer)
{
int nCode;
tCodeBlock codptr;
nCode = Opcode.GetLength();
codptr = Opcode.GetCode();
iRefer
= iRefer - 5;
nCode = Opcode.DeleteCode(iRefer,nCode,14sizeof(OPC.LLP); Opcode.SetLength(nCode+ sizeof(OPC.MEM));
return iRefer;
} |