如何从Qt应用程序中检查当前PostgreSQL用户的角色? [英] How to check role of current PostgreSQL user from Qt application?

查看:145
本文介绍了如何从Qt应用程序中检查当前PostgreSQL用户的角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些基于Qt库的应用程序,并使用QPSQL驱动程序。

在PostreSQL中定义了一些用户角色(例如:admin,operator,user)。我的应用程序在指定的用户下创建与postgres服务器的连接。如何查看用户角色?

解决方案

每个文档:

  SELECT current_user; - 当前执行上下文的用户名
SELECT session_user; - 会话用户名

这意味着, session_user 显示您连接的角色, current_user 显示您当前正在运行的角色,例如在调用 SET角色some_other_role


I have some application based on Qt library and using QPSQL driver.
In PostreSQL defined a few user roles (e.g: admin, operator, user). My application creates a connection to postgres server under specified user. How can I check the users role?

解决方案

Per documentation:

SELECT current_user;  -- user name of current execution context
SELECT session_user;  -- session user name

That means, session_user shows the role you connected with, and current_user shows the role you are currently operating with, for instance after calling SET role some_other_role.

这篇关于如何从Qt应用程序中检查当前PostgreSQL用户的角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆