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