Is there a way to get results from Uniconnection without creating Uniquery ?
I mean uniconnection.execsql( select afield from mytable where bfield = 22)
I want to get value of afield.
Uniconnection Result
Re: Uniconnection Result
Hello,
No, you can't get ResultSet when using the uniconnection.execsql method
No, you can't get ResultSet when using the uniconnection.execsql method
Re: Uniconnection Result
I made a function for this which gives first result and sql.text must have a result field
It is not perfect.
Maybe people may need this or you may add such a thing to your product.
Function ConnecExec(conn: TUniConnection; Sqltext: String): Variant;
Var
Query: TUniQuery;
Begin
Result := null;
If Not AnsiContainsText(Sqltext, 'result') Then
Exit;
Query := TUniQuery.Create(Nil);
Try
With Query Do
Begin
Connection := conn;
ReadOnly := true;
SQL.text := Sqltext;
Execute;
Result := FieldByName('result').Value;
End;
Finally
Query.Free;
End;
End;
It is not perfect.
Maybe people may need this or you may add such a thing to your product.
Function ConnecExec(conn: TUniConnection; Sqltext: String): Variant;
Var
Query: TUniQuery;
Begin
Result := null;
If Not AnsiContainsText(Sqltext, 'result') Then
Exit;
Query := TUniQuery.Create(Nil);
Try
With Query Do
Begin
Connection := conn;
ReadOnly := true;
SQL.text := Sqltext;
Execute;
Result := FieldByName('result').Value;
End;
Finally
Query.Free;
End;
End;
Re: Uniconnection Result
Please specify the database you are working with, as to retrieve the only value from the table (not the whole RecordSet), some databases have more simple ways
Re: Uniconnection Result
MSSQL Server and MS Access
Re: Uniconnection Result
You can use stored procedures/functions for implementation of this functionality in MS SQL Server.