未验证 提交 2eb4390c 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #13412 from dbeaver/#11268

#11268 always enquote session role & change session role field name and tooltip
......@@ -135,7 +135,8 @@ public class PostgreMessages extends NLS {
public static String dialog_setting_group_performance;
public static String dialog_setting_connection_use_prepared_statements;
public static String dialog_setting_connection_use_prepared_statements_tip;
public static String dialog_setting_user_role;
public static String dialog_setting_session_role;
public static String dialog_setting_session_role_tip;
/* PostgreCreateRoleDialog */
public static String dialog_create_role_title;
......
......@@ -111,7 +111,8 @@ dialog_setting_sql_dd_tag_label = Show $tagName$ quote as
dialog_setting_sql_dd_tag_tip = Show $tagName$ quotes as string quote or as code block quote
dialog_setting_sql_dd_string = String
dialog_setting_sql_dd_code_block = Code block
dialog_setting_user_role = User role
dialog_setting_session_role = Session role
dialog_setting_session_role_tip = Sets the current user identifier of the current session
dialog_setting_group_performance = Performance
dialog_setting_connection_use_prepared_statements = Use prepared statements
......
......@@ -119,11 +119,12 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements IDi
createAuthPanel(mainGroup, 1);
if (isUserRoleSupported() || serverType.supportsClient()) {
if (isSessionRoleSupported() || serverType.supportsClient()) {
Group advancedGroup = UIUtils.createControlGroup(mainGroup, "Advanced", 4, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
if (isUserRoleSupported()) {
roleText = UIUtils.createLabelText(advancedGroup, PostgreMessages.dialog_setting_user_role, null, SWT.BORDER);
if (isSessionRoleSupported()) {
roleText = UIUtils.createLabelText(advancedGroup, PostgreMessages.dialog_setting_session_role, null, SWT.BORDER);
roleText.setToolTipText(PostgreMessages.dialog_setting_session_role_tip);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(roleText) * 15;
roleText.setLayoutData(gd);
......@@ -140,7 +141,7 @@ public class PostgreConnectionPage extends ConnectionPageWithAuth implements IDi
setControl(mainGroup);
}
protected boolean isUserRoleSupported() {
protected boolean isSessionRoleSupported() {
return true;
}
......
......@@ -267,14 +267,15 @@ public class PostgreExecutionContext extends JDBCExecutionContext implements DBC
}
}
void setSessionRole(final DBRProgressMonitor monitor) throws DBCException {
private void setSessionRole(@NotNull DBRProgressMonitor monitor) throws DBCException {
final String roleName = getDataSource().getContainer().getConnectionConfiguration().getProviderProperty(PostgreConstants.PROP_CHOSEN_ROLE);
if (CommonUtils.isEmpty(roleName)) {
return;
}
try (JDBCSession session = openSession(monitor, DBCExecutionPurpose.UTIL, "Set active role")) {
try (JDBCStatement dbStat = session.createStatement()) {
dbStat.executeUpdate("SET ROLE " + roleName);
String sql = "SET ROLE " + getDataSource().getSQLDialect().getQuotedIdentifier(roleName, false, true);
dbStat.executeUpdate(sql);
}
} catch (SQLException e) {
throw new DBCException(e, this);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册