Search in sources :

Example 11 with SqlFormattingStrategy

use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.

the class SQLGenerateUtils method getSelectSQLWithLimit.

/**
	 * Get the select sql with limit 1 to 100
	 * 
	 * @param name
	 * @param allAttrList
	 * @return
	 */
public static String getSelectSQLWithLimit(String name, List<DBAttribute> allAttrList) {
    if (name == null || name.length() == 0 || allAttrList == null) {
        return "";
    }
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ");
    StringBuilder columns = new StringBuilder();
    for (DBAttribute attr : allAttrList) {
        //			} else {
        if (columns.length() > 0) {
            columns.append(", ");
        }
        columns.append(QuerySyntax.escapeKeyword(attr.getName()));
    //			}
    }
    if (columns.length() == 0) {
        sql.append("*");
    } else {
        sql.append(columns);
    }
    sql.append(" FROM ").append(QuerySyntax.escapeKeyword(name));
    sql.append(" WHERE ROWNUM BETWEEN 1 AND 100;");
    String res = sql.toString();
    try {
        SqlFormattingStrategy formatter = new SqlFormattingStrategy();
        return formatter.format(res);
    } catch (Exception ignored) {
        return res;
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 12 with SqlFormattingStrategy

use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.

the class SQLGenerateUtils method getSelectSQLNoWhere.

/**
	 * Get the select sql no where
	 * 
	 * @param name
	 * @param allAttrList
	 * @return
	 */
public static String getSelectSQLNoWhere(String name, List<DBAttribute> allAttrList, boolean useSemicolon) {
    if (name == null || name.length() == 0 || allAttrList == null) {
        return "";
    }
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT ");
    StringBuilder columns = new StringBuilder();
    for (DBAttribute attr : allAttrList) {
        //			} else {
        if (columns.length() > 0) {
            columns.append(", ");
        }
        columns.append(QuerySyntax.escapeKeyword(attr.getName()));
    //			}
    }
    if (columns.length() == 0) {
        sql.append("*");
    } else {
        sql.append(columns);
    }
    sql.append(" FROM ").append(QuerySyntax.escapeKeyword(name));
    if (useSemicolon) {
        sql.append(";");
    }
    String res = sql.toString();
    try {
        SqlFormattingStrategy formatter = new SqlFormattingStrategy();
        return formatter.format(res);
    } catch (Exception ignored) {
        return res;
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 13 with SqlFormattingStrategy

use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.

the class SQLViewerConfiguration method getContentFormatter.

/**
	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentFormatter(org.eclipse.jface.text.source.ISourceViewer)
	 * @param sourceViewer the source viewer to be configured by this
	 *        configuration
	 * @return a content formatter or <code>null</code> if formatting should not
	 *         be supported
	 */
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
    ContentFormatter formatter = new ContentFormatter();
    formatter.setFormattingStrategy(new SqlFormattingStrategy(databaseProvider), IDocument.DEFAULT_CONTENT_TYPE);
    return formatter;
}
Also used : IContentFormatter(org.eclipse.jface.text.formatter.IContentFormatter) ContentFormatter(org.eclipse.jface.text.formatter.ContentFormatter) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 14 with SqlFormattingStrategy

use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.

the class MakeCreateQueryAction method getStmtSQL.

/**
	 * Get create table SQL
	 *
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
protected String getStmtSQL(DefaultSchemaNode schemaNode, IEditorPart editorPart) {
    // FIXME move this logic to core module
    String sql = SQLGenerateUtils.getCreateSQL(schemaNode);
    try {
        sql = wrapShardSQL(schemaNode, editorPart, sql);
        sql = new SqlFormattingStrategy().format(sql).trim();
    } catch (Exception ignored) {
    }
    return sql;
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 15 with SqlFormattingStrategy

use of com.cubrid.common.ui.query.format.SqlFormattingStrategy in project cubrid-manager by CUBRID.

the class MakeDeleteQueryAction method getStmtSQL.

/**
	 * Create select statement SQL
	 *
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
protected String getStmtSQL(DefaultSchemaNode schemaNode, IEditorPart editorPart) {
    // FIXME move this logic to core module
    String sql = SQLGenerateUtils.getDeleteSQL(schemaNode);
    try {
        sql = wrapShardSQL(schemaNode, editorPart, sql);
        sql = new SqlFormattingStrategy().format(sql).trim();
    } catch (Exception ignored) {
    }
    return sql;
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Aggregations

SqlFormattingStrategy (com.cubrid.common.ui.query.format.SqlFormattingStrategy)19 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)6 GetAllAttrTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllAttrTask)3 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 ArrayList (java.util.ArrayList)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)1 GetAllClassListTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask)1 GetViewAllColumnsTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetViewAllColumnsTask)1 PeriodGroup (com.cubrid.cubridmanager.ui.cubrid.jobauto.control.PeriodGroup)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ContentFormatter (org.eclipse.jface.text.formatter.ContentFormatter)1 IContentFormatter (org.eclipse.jface.text.formatter.IContentFormatter)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Group (org.eclipse.swt.widgets.Group)1