Search in sources :

Example 16 with SQLQuery

use of org.jkiss.dbeaver.model.sql.SQLQuery in project dbeaver by serge-rider.

the class SQLEditor method extractScriptQueries.

private List<SQLQuery> extractScriptQueries(int startOffset, int length) {
    List<SQLQuery> queryList = new ArrayList<>();
    IDocument document = getDocument();
    if (document == null) {
        return queryList;
    }
    this.startScriptEvaluation();
    try {
        for (int queryOffset = startOffset; ; ) {
            SQLQuery query = parseQuery(document, queryOffset, startOffset + length, queryOffset, true);
            if (query == null) {
                break;
            }
            queryList.add(query);
            queryOffset = query.getOffset() + query.getLength() + 1;
        }
    } finally {
        this.endScriptEvaluation();
    }
    if (getActivePreferenceStore().getBoolean(ModelPreferences.SQL_PARAMETERS_ENABLED)) {
        // Parse parameters
        for (SQLQuery query : queryList) {
            query.setParameters(parseParameters(getDocument(), query));
        }
    }
    return queryList;
}
Also used : SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) Point(org.eclipse.swt.graphics.Point)

Example 17 with SQLQuery

use of org.jkiss.dbeaver.model.sql.SQLQuery in project dbeaver by serge-rider.

the class ExplainPlanViewer method loadQueryPlan.

public boolean loadQueryPlan(DBCQueryPlanner planner, Viewer viewer) {
    if (planner instanceof DBCQueryPlannerSerializable) {
        FileDialog fd = new FileDialog(viewer.getControl().getShell(), SWT.OPEN | SWT.SINGLE);
        fd.setText(UIMessages.save_execution_plan);
        fd.setFilterPath(curFolder);
        fd.setFilterExtensions(SQLPlanSaveProvider.EXT);
        String selected = fd.open();
        if (selected != null) {
            curFolder = fd.getFilterPath();
            try (Reader r = new FileReader(selected)) {
                lastPlan = ((DBCQueryPlannerSerializable) planner).deserialize(r);
                lastQuery = new SQLQuery(contextProvider.getExecutionContext().getDataSource(), lastPlan.getQueryString());
                lastQueryId = lastPlan.getQueryString();
                refresh();
                return true;
            } catch (IOException | InvocationTargetException e) {
                DBWorkbench.getPlatformUI().showError("Load plan", "Error loading plan ", GeneralUtils.getRootCause(e));
            }
        }
    }
    return false;
}
Also used : Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) IOException(java.io.IOException) SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) FileDialog(org.eclipse.swt.widgets.FileDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SQLQuery (org.jkiss.dbeaver.model.sql.SQLQuery)17 DBException (org.jkiss.dbeaver.DBException)5 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)4 Point (org.eclipse.swt.graphics.Point)3 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)3 DBSTable (org.jkiss.dbeaver.model.struct.rdb.DBSTable)3 DBDDataReceiver (org.jkiss.dbeaver.model.data.DBDDataReceiver)2 SQLDataSource (org.jkiss.dbeaver.model.sql.SQLDataSource)2 DBVEntityConstraint (org.jkiss.dbeaver.model.virtual.DBVEntityConstraint)2 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 JSQLParserException (net.sf.jsqlparser.JSQLParserException)1 Expression (net.sf.jsqlparser.expression.Expression)1 Function (net.sf.jsqlparser.expression.Function)1 ExpressionList (net.sf.jsqlparser.expression.operators.relational.ExpressionList)1 Column (net.sf.jsqlparser.schema.Column)1 Statement (net.sf.jsqlparser.statement.Statement)1