In shiro.ini I declare the following SQL-queries:
jdbcRealm.authenticationQuery = SELECT password FROM Person WHERE email = ?
jdbcRealm.userRolesQuery = SELECT id FROM SecurityRole WHERE id = (SELECT securityRole_id FROM Person WHERE email = ?)
jdbcRealm.permissionsQuery = SELECT action FROM SecurityPermission WHERE id = (SELECT permissions_id FROM securityrole_securitypermission WHERE securityrole_id = ?)
When I replace the ? in the last query with 1 an run it on the db it returns the expected result: rest:*
But SecurityUtils.getSubject().isPermitted(new WildcardPermission("rest")); will return false although the logged in user has an assigned role with id = 1, securityrole_securitypermission has an entry with ids 1 and 1, and securitypermission with id 1 has action = "rest:*".
jdbcRealm.permissionsLookupEnabled = true did the job. ;)
Related
Hi I am having two tables Country and city , country(id,Name) ,city(id,Country_id,City_name) When I am having Index action method as below , If I have 4 rows in country and there are two associated rows in cities then it only shows two rows on Country index table I mean only matched records
below is controller code I need to show all Country list even though there is any assocaited city in city table or now
var test1 = (from c in db.Cities
join cc in db.Countries
on c.Country_Id equals cc.Id into u
from cc1 in u.DefaultIfEmpty()
select new
{
Id = c.Id,
Name = c.Name,
Country_Id = c.Country.CountryName,
Code = c.Code,
IsActive = c.IsActive,
// IsActive = g.IsActive,
Date_Created = c.Date_Created,
Date_Modified = c.Date_Modified,
Latitude = c.Latitude,
Longitude = c.Longitude,
}).ToList();
return Json(new { data = test1 }, JsonRequestBehavior.AllowGet);
SQL table:
SELECT id,
account_name,
parent_id
FROM
(SELECT id,
account_name,
parent_id,
CASE
WHEN id = 1 THEN #idlist := CONCAT(id)
WHEN FIND_IN_SET(parent_id, #idlist) THEN #idlist := CONCAT(#idlist, ',', id)
END AS checkId
FROM chart_of_account
ORDER BY id ASC) AS T
WHERE checkId IS NOT NULL
When I run this query in MySQL it works fine and the result is fetched perfectly, but when I run it in Laravel like this:
$accountId = DB::select('SELECT id,account_name,parent_id FROM
(SELECT id,account_name,parent_id,
CASE WHEN id = '.$account_id.' THEN #idlist := CONCAT(id)
WHEN FIND_IN_SET(parent_id,#idlist) THEN #idlist := CONCAT(#idlist,', ',id)
END as checkId
FROM chart_of_account
ORDER BY id ASC) as T
WHERE checkId IS NOT NULL');
it gives an error.
Argument 1 passed to Illuminate\\Database\\Connection::prepareBindings() must be of the type array, string given,
Try this:
$query = 'YOUR_QUERY_THE_BIG_ONE:)';
$result = DB::select($query,[]);
dd($result);
Optionally, you can use ? sign in your query wherever you are using user inputs to prevent mySQL injection issue and then provide their value in second parameter array of select function. One example would be:
$inputUserEmail = $request->input('email');
$query = 'SELECT * FROM users WHERE email=?';
$result = DB::select($query,[$inputUserEmail]);
dd($result);
I hope it gives you an idea
I'm trying to merge three update statements into one.
"UPDATE DOT_WORKS SET START_DATE = :StartDate WHERE ID = :WorksId and END_DATE IS NULL;"
"UPDATE DOT_WORKS SET WORKS_TYPE = :WorksType WHERE ID = WorksId and WORKS_GROUP = :WorksGroup;"
"UPDATE DOT_WORKS SET WORKS_CONNECTION = :WorksConn WHERE ID = WorksId and WORKS_PLACE = :WorksPlace;"
I'm wondering whether there is a way to do that.
The reason why I'm trying to do so is to save the calls to database. It's more efficient to call db once instead of three.
Thanks!
UPDATE DOT_WORKS
SET START_DATE = case when END_DATE IS NULL then :StartDate else START_DATE end,
WORKS_TYPE = case when WORKS_GROUP = :WorksGroup then :WorksType else WORKS_TYPE end,
WORKS_CONNECTION = case when WORKS_PLACE = :WorksPlace then :WorksConn else WORKS_CONNECTION end
WHERE ID = :WorksId
and
(
END_DATE IS NULL OR
WORKS_GROUP = :WorksGroup OR
WORKS_PLACE = :WorksPlace
)
I have a list x with anonymous types in which i want to use a value which pre-calculated
int count1 =
(from users in dc.BeadSets
where users.UserId == i
select users
).Count();
var x =
(from users in dc.Users
where users.Id == i
select new { username = users.UserName
, fullname = users.FirstName + " " + users.LastName
, userid = users.Id
}
).ToList();
Now this is working fine as usual
Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>'
to 'System.Collections.Generic.List<AnonymousType#2>'
but while i am trying to use like this its throwing above error
int count1 =
(from users in dc.BeadSets
where users.UserId == i
select users
).Count();
x =
(from users in dc.Users
where users.Id == i
select new { beadsets= count1
, username = users.UserName
, fullname = users.FirstName + " " + users.LastName
, userid = users.Id }
).ToList();
I am trying to select from multiple tables in an entity model. But there are two columns I would like to select and it's just not working out. The LINQ statement I have is:
var searchResult = from i in _imEntities.Issues
join dept in _imEntities.Departments
on i.Issued_to_dept equals dept.Dept_ID
where i.State == 1
select new {
i.ID_No,
i.Issue_Date,
Raised_By = dept.Dept_Name
.Where(i.Raised_by_Dept == dept.Dept_ID),
Issued_To = dept.Dept_Name
.Where(i.Issued_to_dept == dept.Dept_ID),
Details = i.Details
};
The column names are all correct, but I just can't get the dept_Names into the Raised_By and Issued_To fields. Is there another way to execute this?
Try this:
var query = from i in _imEntities.Issues
join dept_r in _imEntities.Departments
on i.Issued_to_dept equals dept_r.Dept_ID
join dept_i in _imEntities.Departments
on i.Issued_to_dept equals dept_i.Dept_ID
where i.State == 1
select new {
i.ID_No,
i.Issue_Date,
Raised_By = dept_r.Dept_Name,
Issued_To = dept_i.Dept_Name,
Details = i.Details
};
It's not clear what you are trying to achieve. But you definitely trying to apply where filter on single name string (also predicate syntax is not correct). Here is query which conditionally returns Dept_Name in Raised_By and Issued_To properties:
var query = from i in _imEntities.Issues
join dept in _imEntities.Departments
on i.Issued_to_dept equals dept.Dept_ID
where i.State == 1
select new {
i.ID_No,
i.Issue_Date,
Raised_By = (i.Raised_by_Dept == dept.Dept_ID) ? dept.Dept_Name : null,
Issued_To = (i.Issued_to_dept == dept.Dept_ID) ? dept.Dept_Name : null,
Details = i.Details
};