Search in sources :

Example 16 with SqlFormattingStrategy

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

the class MakeSelectPstmtQueryAction method getStmtSQL.

/**
	 * Create select prepared statement SQL
	 *
	 * @param schemaNode DefaultSchemaNode
	 * @return String
	 */
protected String getStmtSQL(DefaultSchemaNode schemaNode, IEditorPart editorPart) {
    // FIXME move this logic to core module
    String sql = SQLGenerateUtils.getSelectSQL(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 17 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 assigned limit
	 * 
	 * @param name
	 * @param allAttrList
	 * @return
	 */
public static String getSelectSQLWithLimit(String name, int start, int end) {
    if (name == null || name.length() == 0) {
        return "";
    }
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT * ");
    sql.append("FROM ").append(QuerySyntax.escapeKeyword(name));
    if (start > 0 && end > 0 && start <= end) {
        sql.append(" WHERE ROWNUM BETWEEN ").append(start).append(" AND ").append(end);
    }
    sql.append(";");
    String res = sql.toString();
    try {
        SqlFormattingStrategy formatter = new SqlFormattingStrategy();
        return formatter.format(res);
    } catch (Exception ignored) {
        return res;
    }
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 18 with SqlFormattingStrategy

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

the class ObjectInfoComposite method processDeleteAction.

/**
	 * Process delete action
	 * 
	 */
private void processDeleteAction() {
    String res = SQLGenerateUtils.getDeleteSQL(schemaNode);
    appendToEditor(new SqlFormattingStrategy().format(res).trim() + NEWLINE + NEWLINE);
}
Also used : SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy)

Example 19 with SqlFormattingStrategy

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

the class ERSchemaEditor method generateSqls.

private List<StringBuffer> generateSqls(Collection<SchemaInfo> erdSchemaInfos) throws SQLException {
    List<StringBuffer> sqls = new ArrayList<StringBuffer>();
    SqlFormattingStrategy formater = new SqlFormattingStrategy();
    StringBuffer insertOrAlterSqls = null;
    StringBuffer allUpdateSqls = null;
    Connection conn = null;
    boolean isSupportOnServer = CompatibleUtil.isCommentSupports(database.getDatabaseInfo());
    if (isSupportOnServer) {
        conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
        insertOrAlterSqls = new StringBuffer();
    } else {
        insertOrAlterSqls = new StringBuffer();
        allUpdateSqls = new StringBuffer();
    }
    for (SchemaInfo newSchemaInfo : erdSchemaInfos) {
        if (StringUtil.isEmpty(newSchemaInfo.getDescription())) {
            continue;
        }
        boolean isAddLine = false;
        String tableName = newSchemaInfo.getClassname();
        if (isSupportOnServer) {
            String description = String.format("'%s'", newSchemaInfo.getDescription());
            String sql = SchemaCommentHandler.generateDescriptionSql(conn, tableName, "*", StringUtil.escapeQuotes(description));
            appendFormattingSQL(insertOrAlterSqls, sql, formater);
        } else {
            String insertSql = SchemaCommentHandler.buildInsertSQL(tableName, "", newSchemaInfo.getDescription());
            appendFormattingSQL(insertOrAlterSqls, insertSql, formater);
            String updateSql = SchemaCommentHandler.buildUpdateSQL(tableName, "", newSchemaInfo.getDescription());
            appendFormattingSQL(allUpdateSqls, updateSql, formater);
        }
        isAddLine = true;
        for (DBAttribute newAttr : newSchemaInfo.getAttributes()) {
            if (StringUtil.isEmpty(newAttr.getDescription())) {
                continue;
            }
            if (isSupportOnServer) {
                String description = String.format("'%s'", newAttr.getDescription());
                String sql = SchemaCommentHandler.generateDescriptionSql(conn, tableName, newAttr.getName(), StringUtil.escapeQuotes(description));
                appendFormattingSQL(insertOrAlterSqls, sql, formater);
            } else {
                String insertSql = SchemaCommentHandler.buildInsertSQL(tableName, newAttr.getName(), newAttr.getDescription());
                appendFormattingSQL(insertOrAlterSqls, insertSql, formater);
                String updateSql = SchemaCommentHandler.buildUpdateSQL(tableName, newAttr.getName(), newAttr.getDescription());
                appendFormattingSQL(allUpdateSqls, updateSql, formater);
            }
            isAddLine = true;
        }
        if (isAddLine) {
            insertOrAlterSqls.append("\n\r");
        }
    }
    if (insertOrAlterSqls.length() > 0) {
        sqls.add(insertOrAlterSqls);
        if (!isSupportOnServer) {
            sqls.add(allUpdateSqls);
        }
    }
    return sqls;
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) SqlFormattingStrategy(com.cubrid.common.ui.query.format.SqlFormattingStrategy) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

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