Access selected schema in Query Console
已回答
Hi,
I want to access the selected schema in the Query Console. I've tried many things and this is my current code:
import com.intellij.database.console.JdbcConsoleService
val consoleService = JdbcConsoleService.getInstance()
val consoles = consoleService.getActiveConsoles(project)
I tried to access the schema through console.dataSource.schemaMapping
but this solution gives me all the schemas I've enabled in the database window, but I only want to have the schema that the user specifically selected in the query console. How can I do this?
I would appreciate any help.
请先登录再写评论。
`com.intellij.database.console.JdbcConsole` has the `getTarget` method
Also I don't think you need all the consoles for project, you need it for current file, so `com.intellij.database.console.JdbcConsoleProvider#getValidConsole`
Alexander Kass Thank you!
But I'm still wondering how to access the selected schema in the query console.
val validConsole = JdbcConsoleProvider.getValidConsole(project, editor?.virtualFile)
if (validConsole != null) {
Messages.showInfoMessage("$validConsole -> ${validConsole.target}","Valid Console")
}