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