SAP Business Objects Query Builder Query - SI_SESSION_USER - query-builder

I am trying to get a list of all connections where the SI_SESSION_USER='xyz'.
When I do a query like
select * from si_infoobjects where si_id='00000', I can see this field in the results with that value (xyz).
When I modify the query to look for that specific field and value, it returns zero rows.
I am using:
select * from si_infoobjects where SI_SESSION_USER='xyz'
What query will return the correct results?

Just a guess here, but si_session_user is probably in the Processing Info bag. So use this:
select *
from ci_infoobjects
where si_processinfo.SI_SESSION_USER='xyz'
Note that that's ci_infoobjects not si_infoobjects, but I assume that's just a typo in your question.

Related

count get collection and count query giving different results

So i am trying to get distinct collections like this
$data = DB::table('project_1_data')->distinct('Farmer_BankVerificationNumber_Farmer')->get();
But when i do a count($data) I get 1600 but when i run
$data = DB::table('project_1_data')->distinct('Farmer_BankVerificationNumber_Farmer')->count();
I get 1440. This is weird as i only want collection with distinct field 'Farmer_BankVerificationNumber_Farmer'. How do i write the query correctly?
It's because you're asking your query to count the distinct values in the wrong place.
You need to tell your count parameter what field you would like to count on. So you'll basically ask the query to get the database information, separate the distinct values and then count how many of a specific field are distinct.
Your finished query should look like this:
$data = DB::table('project_1_data')
->distinct()
->count('Farmer_BankVerificationNumber_Farmer');

How do I return only the value as a string and not a collection?

This eloquent collection provides this result:
$id = Model::where('s_id', $s_id)->pluck('l_id');
print_r($id)
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => 31242682774
)
)
How do I return only the "31242682774" value as a string and not a collection?
EDIT ANSWER:
All I had to do is:
$id = Model::where('s_id', $s_id)->pluck('l_id')->first();
Any better options?
If you only need a single value, not multiple values, pluck isn't what you want. There is a method called value on Query Builder that returns a single value:
Model::where('s_id', $s_id)->value('l_id');
Laravel 6.x Docs - Query Builder - Retrieving Results - Retrieving A Single Row / Column From A Table value
It compares to when it the process you wanna do it. On the query execution or after. The most common approach would probably be.
$id = Model::where('s_id', $s_id)->first()->l_id;
This will execute after, meaning the query builder will fetch all columns in the row. In general in Laravel you don't that often work with strings and or other abstractions than your model. Model::where('s_id', $s_id)->first() will return your model and select the l_id property on it.
The approach you chosen is the database way, you only select the l_id and return it as a collection and select the first item from there. This is thou a very performance efficient way of doing it since the database does all the work and is very quick at it.
$id = Model::where('s_id', $s_id)->pluck('l_id')->first();
The reason why it is a collection, it is mainly made for selecting multiple id's, so if you query returned multiple rows multiple ids would be returned. Here you can see an example of pluck in conditional queries, where it is most often used.
$teamIds = Team::where('type', 'admin')->pluck('id');
$adminUsers = User::where('team_id', $teamIds)->get();
Your solution is perfect for what you need, just trying to bring clarity on why and a example of how it is often used.

Android Room Query cannot use same variable more than once

I am trying to convert this raw query to Query.
Raw Query:
SELECT * from numbers WHERE number=$numberToSearch OR number LIKE '%$numberToSearch%' OR number LIKE '%$numberToSearch' OR number LIKE '$numberToSearch%'
I started with simple one and created this Query
#Query("SELECT * from numbers WHERE number=:numberToSearch OR number LIKE :numberToSearch")
However, room things that my query needs to variables and creates exception. I can of course provide :numberToSearch few times as variable but that doe not sound right.
Is there any way writing a Query that works?
You should enclose your like query with % before passing as a parameter.
So correct representation of what you original query is goes as follows
val numberToSearch = 123
val numberToSearchLike = `%$numberToSearch%`
// You have to call with two parameters as parameters are not same
searchNumber(numberToSearch, numberToSearchLike)
And your DAO should look like this
#Query("SELECT * from numbers WHERE number=:numberToSearch OR number LIKE :numberToSearchLike")
fun searchNumber(numberToSearch:Int, numberToSearchLike: String)
Thats actually the way your do LIKE operations in Room
P.S.
In fact you don't have to have WHERE number=:numberToSearch as your LIKE operator will return the same thing.
So your query is same as saying
#Query("SELECT * from numbers WHERE number LIKE :numberToSearchLike")

How can we fetch column values which are between two limits in MongoTemplate?

for example i want to find age between 16 and 25 from a collection in mongoDB.
my query is..
Query query = new Query(Criteria.where("visibility").is(1)
.and("type").is("guide").and("age").gte(16).and("age").lte(25));
but it is giving exception. reason is mongo template do not support lte() and gte() with same column. so how can i handle it ? is their any solution ?
Try not to include an extra and("age") part in your criteria. What you need is this:
Query query = new Query(Criteria.where("visibility").is(1)
.and("type").is("guide").and("age").gte(16).lte(25));

Linq Contains issue: cannot formulate the equivalent of 'WHERE IN' query

In the table ReservationWorkerPeriods there are records of all workers that are planned to work on a given period on any possible machine.
The additional table WorkerOnMachineOnConstructionSite contains columns workerId, MachineId and ConstructionSiteId.
From the table ReservationWorkerPeriods I would like to retrieve just workers who work on selected machine.
In order to retrieve just relevant records from WorkerOnMachineOnConstructionSite table I have written the following code:
var relevantWorkerOnMachineOnConstructionSite = (from cswm in currentConstructionSiteSchedule.ContrustionSiteWorkerOnMachine
where cswm.MachineId == machineId
select cswm).ToList();
workerOnMachineOnConstructionSite = relevantWorkerOnMachineOnConstructionSite as List<ContrustionSiteWorkerOnMachine>;
These records are also used in the application so I don't want to bypass the above code even if is possible to directly retrieve just workerPeriods for workers who work on selected machine. Anyway I haven't figured out how it is possible to retrieve the relevant workerPeriods once we know which userIDs are relevant.
I have tried the following code:
var userIDs = from w in workerOnMachineOnConstructionSite select new {w.WorkerId};
List<ReservationWorkerPeriods> workerPeriods = currentConstructionSiteSchedule.ReservationWorkerPeriods.ToList();
allocatedWorkers = workerPeriods.Where(wp => userIDs.Contains(wp.WorkerId));
but it seems to be incorrect and don't know how to fix it. Does anyone know what is the problem and how it is possible to retrieve just records which contain userIDs from the list?
Currently, you are constructing an anonymous object on the fly, with one property. You'll want to grab the id directly with (note the missing curly braces):
var userIDs = from w in workerOnMachineOnConstructionSite select w.WorkerId;
Also, in such cases, don't call ToList on it - the variable userIDs just contains the query, not the result. If you use that variable in a further query, the provider can translate it to a single sql query.

Resources