When developing the idea plug-in, how to execute the query sql and get the query result?

Answered

0
2 comments
Official comment

Hi zion,

To execute a query you need to:
1. Create or get existing session (it's our wrapper for connection) by using com.intellij.database.console.session.DatabaseSessionManager#getSessions(com.intellij.openapi.project.Project, com.intellij.database.dataSource.LocalDataSource).
2. Create request com.intellij.database.datagrid.DataRequest.RawRequest and override processRaw method. Here you can get the connection from the second argument - com.intellij.database.dataSource.DatabaseConnectionCore#getRemoteConnection.
3. Send the request for execution session.getMessageBus().getDataProducer().processRequest(request).

To get the query result you need to implement com.intellij.database.datagrid.DataConsumer and do the following before the query execution:

session.getMessageBus().subscribe(DatabaseTopics.RESPONSE_TOPIC, <your data consumer>);

@Anna Rodionova Thanks!

 
 
 
 
0

Please sign in to leave a comment.