Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'm trying to find the best way to represent an SQL query using SQL::Abstract (actually SQL::Abstract::More via DBIx::DataModel; SQL::Abstract is also used by DBIx::Class). Unfortunately there is not a great deal of information on constructing SQL queries that fall outside the bounds of the usual 'SELECT * FROM x WHERE ...' using SQL::Abstract.
My ideal query:
SELECT CASE WHEN record.is_public = 'Yes' THEN 'public' WHEN EXISTS ( SELECT 1 FROM permissions WHERE permissions.rec_id = record.id AND user_id = $user_id ) THEN 'accessible' ELSE 'private' END AS viewable, record.id, record.display_name FROM record WHERE record.id = $rec_id; # or other criteria
...where $user_id and $rec_id (or other WHERE criteria) are supplied by the Perl code.
Has anyone used SQL::Abstract for this kind of query?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL::Abstract-ing subqueries
by poj (Abbot) on Feb 03, 2017 at 22:08 UTC | |
by Anonymous Monk on Feb 04, 2017 at 01:18 UTC | |
|
Re: SQL::Abstract-ing subqueries
by flowdy (Scribe) on Feb 07, 2017 at 09:15 UTC | |
|
Re: SQL::Abstract-ing subqueries
by Anonymous Monk on Feb 03, 2017 at 19:29 UTC | |
by Anonymous Monk on Feb 03, 2017 at 20:48 UTC | |
by Anonymous Monk on Feb 03, 2017 at 21:01 UTC |