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

已回答

0
正式评论

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>);

请先登录再写评论。