arcengine 执行sql获得返回值

 //执行sql返回值 by yanleigis [email protected]

function ExecSQLResult(FWorkspace: IWorkspace; Sqlstr: string): olevariant;

var
    TableName                           : string;
    SubFields                           : string;
    WhereClause                         : string;
    P                                   : Integer;
    pFeatureWorkspace                   : IFeatureWorkspace;
    pQueryDef                           : IQueryDef;
    PCursor                             : ICursor;
    pRow                                : Irow;

begin
    P := upperpos('select ', Sqlstr);
    result := NULL;
    if P = 0 then Exit;
    Delete(Sqlstr, P, 7);
    P := upperpos(' from ', Sqlstr);
    if P = 0 then Exit;

    SubFields := Copy(Sqlstr, 1, P - 1);
    Delete(Sqlstr, 1, P + 5);
    P := upperpos(' where ', Sqlstr);
    if P = 0 then
    begin
        TableName := Sqlstr;
        WhereClause := '';
    end
    else
    begin

        TableName := Copy(Sqlstr, 1, P - 1);
        Delete(Sqlstr, 1, P + 6);
        WhereClause := Sqlstr;

    end;
    pFeatureWorkspace := FWorkspace as IFeatureWorkspace;
    pFeatureWorkspace.CreateQueryDef(pQueryDef);
    pQueryDef.Set_Tables(TableName);
    pQueryDef.Set_SubFields(SubFields);
    pQueryDef.Set_WhereClause(WhereClause);
    pQueryDef.Evaluate(PCursor);
    if PCursor = nil then Exit;
    PCursor.NextRow(pRow);
    if pRow = nil then Exit;
    pRow.Get_Value(0, result);

end;

你可能感兴趣的:(sql,String,null,Integer,delete)