use of lucee.runtime.db.SQL in project Lucee by lucee.
the class Ansi92 method select.
@Override
public Query select(Config config, String cfid, String applicationName, DatasourceConnection dc, int type, Log log, boolean createTableIfNotExist) throws PageException {
String strType = VariableInterpreter.scopeInt2String(type);
Query query = null;
SQL sqlSelect = new SQLImpl("select data from " + PREFIX + "_" + strType + "_data where cfid=? and name=? and expires > ?", new SQLItem[] { new SQLItemImpl(cfid, Types.VARCHAR), new SQLItemImpl(applicationName, Types.VARCHAR), new SQLItemImpl(now(config), Types.VARCHAR) });
PageContext pc = ThreadLocalPageContext.get();
try {
query = new QueryImpl(pc, dc, sqlSelect, -1, -1, null, "query");
} catch (DatabaseException de) {
if (dc == null || !createTableIfNotExist)
throw de;
// table does not exist???
try {
SQL sql = createSQL(dc, DataSourceUtil.isMySQL(dc) ? "longtext" : "ntext", strType);
ScopeContext.info(log, sql.toString());
new QueryImpl(pc, dc, sql, -1, -1, null, "query");
} catch (DatabaseException _de) {
// don't like "ntext", try text
try {
SQL sql = createSQL(dc, "text", strType);
ScopeContext.info(log, sql.toString());
new QueryImpl(pc, dc, sql, -1, -1, null, "query");
} catch (DatabaseException __de) {
// don't like text, try "memo"
try {
SQL sql = createSQL(dc, "memo", strType);
ScopeContext.info(log, sql.toString());
new QueryImpl(pc, dc, sql, -1, -1, null, "query");
} catch (DatabaseException ___de) {
// don't like "memo", try clob
try {
SQL sql = createSQL(dc, "clob", strType);
ScopeContext.info(log, sql.toString());
new QueryImpl(pc, dc, sql, -1, -1, null, "query");
} catch (DatabaseException ____de) {
___de.initCause(__de);
__de.initCause(_de);
_de.initCause(de);
// we could not create the table, so there seem to be an other ecception we cannot solve
DatabaseException exp = new DatabaseException("Unable to select from your client storage database, and was also unable to create the tables. Here's the exceptions we encountered.", null, null, dc);
exp.initCause(de);
throw exp;
}
}
}
}
query = new QueryImpl(pc, dc, sqlSelect, -1, -1, null, "query");
}
ScopeContext.info(log, sqlSelect.toString());
return query;
}
use of lucee.runtime.db.SQL in project Lucee by lucee.
the class QueryArray method toDumpData.
@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
DumpTable dt = (DumpTable) super.toDumpData(pageContext, maxlevel, dp);
StringBuilder comment = new StringBuilder();
// table.appendRow(1, new SimpleDumpData("SQL"), new SimpleDumpData(sql.toString()));
String template = getTemplate();
if (!StringUtil.isEmpty(template))
comment.append("Template: ").append(template).append("\n");
int top = dp.getMaxlevel();
comment.append("Execution Time: ").append(Caster.toString(FormatUtil.formatNSAsMSDouble(getExecutionTime()))).append(" ms \n");
comment.append("Record Count: ").append(Caster.toString(size()));
if (size() > top)
comment.append(" (showing top ").append(Caster.toString(top)).append(")");
comment.append("\n");
comment.append("Cached: ").append(isCached() ? "Yes\n" : "No\n");
if (isCached()) {
String ct = getCacheType();
comment.append("Cache Type: ").append(ct).append("\n");
}
SQL sql = getSql();
if (sql != null)
comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
dt.setTitle("Array (from Query)");
if (dp.getMetainfo())
dt.setComment(comment.toString());
return dt;
}
use of lucee.runtime.db.SQL in project Lucee by lucee.
the class QueryStruct method toDumpData.
@Override
public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
DumpTable dt = (DumpTable) super.toDumpData(pageContext, maxlevel, dp);
StringBuilder comment = new StringBuilder();
// table.appendRow(1, new SimpleDumpData("SQL"), new SimpleDumpData(sql.toString()));
String template = getTemplate();
if (!StringUtil.isEmpty(template))
comment.append("Template: ").append(template).append("\n");
int top = dp.getMaxlevel();
comment.append("Execution Time: ").append(Caster.toString(FormatUtil.formatNSAsMSDouble(getExecutionTime()))).append(" ms \n");
comment.append("Record Count: ").append(Caster.toString(size()));
if (size() > top)
comment.append(" (showing top ").append(Caster.toString(top)).append(")");
comment.append("\n");
comment.append("Cached: ").append(isCached() ? "Yes\n" : "No\n");
if (isCached()) {
String ct = getCacheType();
comment.append("Cache Type: ").append(ct).append("\n");
}
SQL sql = getSql();
if (sql != null)
comment.append("SQL: ").append("\n").append(StringUtil.suppressWhiteSpace(sql.toString().trim())).append("\n");
dt.setTitle("Struct (from Query)");
if (dp.getMetainfo())
dt.setComment(comment.toString());
return dt;
}
Aggregations