SQL select query for returning all roles and permissions

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by thermalmusic on July 24, 2011 at 4:40pm

Hi everybody,

I want to create a select query to return a list of all roles and their related permissions directly from a MySQL database. Does anyone have a good one for that?

Thanks,
Thermal

Comments

D7 SELECT * FROM role r left

Posted by sivaji_ganesh_j... on July 24, 2011 at 4:52pm
D7

SELECT * FROM role r left join role_permission rp on rp.rid = r.rid

D6

SELECT * FROM role r left join permission rp on rp.rid = r.rid

select permissions and group by role

Posted by thermalmusic on July 24, 2011 at 5:54pm

Thats nice and I can use it. Though any suggestion for returning each permission by role, perhaps using a group by?

such as

role1, perm1
role1, perm2
role1, perm3
role2, perm1
role2, perm2
role2, perm3

etc

Thanks,
Thermal

Are you using d6 or d7 ? I'm

Posted by sivaji_ganesh_j... on July 24, 2011 at 6:22pm

Are you using d6 or d7 ? I'm not sure how this could be done in d6, as perm field is permission table is a longtext; holding permission strings as comma separated value. For d7 the following SQL could work,
SELECT name, permission FROM role r left join role_permission rp on rp.rid = r.rid order by name, permission

D6

Posted by thermalmusic on July 24, 2011 at 7:07pm

I'm using D6. Yes I see that all permissons are strings. Do you know where those separate values are coming from? Probably each module.

Thermal

Hi Thermal

Posted by veeraprasadd on July 26, 2011 at 3:50pm

Yes Thermal you are correct.
Those permissions are coming from modules only.Each module will be having its own permission.
And those are returning from hook_perm.
You can check this url hook_perm

Regards,
Veera Prasad Dagudu
www.drup-all.com

Hi

Posted by thermalmusic on July 27, 2011 at 5:08am

Thanks for your help. I got what I needed.
Thermal

Select query for Users/Profiles on single rows

Posted by thermalmusic on March 13, 2012 at 10:21pm

Hi,

I'm trying to write an Sql query on a D6 database to return users and their profile values. My problem is getting profile values to return as separate fields (columns) in the resulting rows, since profile data is saved in the profile_values table as children, identified by fid.

I've tried Group_concat but it is not a solution. Profile csv module is not sufficient either. I'd like to have an output like this:

User | Firstname | Lastname | Address | City | State | Zip | etc |

If anyone has done this as a query, please let me know.

Thanks,
Thermal

Self joins on profile_values table

Posted by hbergin on March 14, 2012 at 1:59pm

The sample sql below will return a single row for each user, where you can add a left join for each additional field you want, and check the fids match the field name you want in the SELECT clause.

SELECT a.uid as User,
a.value as FirstName,
b.value as LastName,
c.value as Address
FROM profile_values a
LEFT JOIN profile_values b
ON a.uid = b.uid AND b.fid = 5
LEFT JOIN profile_values c
ON a.uid = c.uid AND c.fid = 7
WHERE a.fid = 4

MySQL

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /