D
djh_djh
Unregistered / Unconfirmed
GUEST, unregistred user!
//此段代码为由字段别名取其表达式但不稳定 有时经常取出一奇怪的字符
哪位高手有时间改写改写
function GetFieldExp(ASQL:string;AAliasName:string;out OExp:string):boolean;
type TIncStatus=(isUnknown,isInc,isDec);
var pSQLChar;
pExpChar;
ALIndex:integer;
J,Count:integer;
IncStatus:TIncStatus;
begin
Result:=False;
pSQL:=PChar(ASQL);
ALIndex:=Pos(AALiasName,ASQL);
if ALIndex=0 then exit;
inc(pSQL,ALIndex-2);
if pSQL^=',' then begin
OExp:=AAliasName;
result:=true;
exit;
end;
J:=0;
Count:=0;
IncStaTus:=isUnknown;
repeat begin
if PSQL^ in ['(',')'] then
if PSQL^='(' then Begin
Dec(J);
IncStaTus:=isDec;
end
else begin
IncStaTus:=isInc;
Inc(J);
end;
if (PSQL^ in LeadBytes) then begin
Dec(PSQL,2);
inc(count,2);
end
else begin
Dec(pSql);
inc(count);
end;
end;
until (J=0) and (IncStatus=isDec) and (PSQL^=',') or (PSQL^='') or (IncStatus=isUnknown) and (PSQL^=',');
try
pEXP:=AllocMem(count);
pEXP:=StrMove(pEXP,PSQL+1,count);//PChar(ASQL)+ALIndex-PSQL-1);
OEXP:=Trim(StrPas(pEXP));
if copy(OEXP,length(OEXP),1)=#39 then
Delete(OEXP,length(OEXP),1);
if LowCase(copy(OEXP,length(OEXP)-1,2)='as' then
Delete(OEXP,length(OEXP)-1,2);
if copy(OEXP,1,6)='select' then
Delete(OEXP,1,6);
if (OExp='') then
OExp:=AAliasName;
if (OExp[Length(OExp)]='.') then
OExp:=OExp+AAliasName;
result:=true;
finally
FreeMem(pEXP);
end;
end;
哪位高手有时间改写改写
function GetFieldExp(ASQL:string;AAliasName:string;out OExp:string):boolean;
type TIncStatus=(isUnknown,isInc,isDec);
var pSQLChar;
pExpChar;
ALIndex:integer;
J,Count:integer;
IncStatus:TIncStatus;
begin
Result:=False;
pSQL:=PChar(ASQL);
ALIndex:=Pos(AALiasName,ASQL);
if ALIndex=0 then exit;
inc(pSQL,ALIndex-2);
if pSQL^=',' then begin
OExp:=AAliasName;
result:=true;
exit;
end;
J:=0;
Count:=0;
IncStaTus:=isUnknown;
repeat begin
if PSQL^ in ['(',')'] then
if PSQL^='(' then Begin
Dec(J);
IncStaTus:=isDec;
end
else begin
IncStaTus:=isInc;
Inc(J);
end;
if (PSQL^ in LeadBytes) then begin
Dec(PSQL,2);
inc(count,2);
end
else begin
Dec(pSql);
inc(count);
end;
end;
until (J=0) and (IncStatus=isDec) and (PSQL^=',') or (PSQL^='') or (IncStatus=isUnknown) and (PSQL^=',');
try
pEXP:=AllocMem(count);
pEXP:=StrMove(pEXP,PSQL+1,count);//PChar(ASQL)+ALIndex-PSQL-1);
OEXP:=Trim(StrPas(pEXP));
if copy(OEXP,length(OEXP),1)=#39 then
Delete(OEXP,length(OEXP),1);
if LowCase(copy(OEXP,length(OEXP)-1,2)='as' then
Delete(OEXP,length(OEXP)-1,2);
if copy(OEXP,1,6)='select' then
Delete(OEXP,1,6);
if (OExp='') then
OExp:=AAliasName;
if (OExp[Length(OExp)]='.') then
OExp:=OExp+AAliasName;
result:=true;
finally
FreeMem(pEXP);
end;
end;