use of lucee.runtime.exp.DatabaseException 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.exp.DatabaseException in project Lucee by lucee.
the class Transaction method doCatch.
@Override
public void doCatch(Throwable t) throws Throwable {
ExceptionUtil.rethrowIfNecessary(t);
if (innerTag || ignore)
throw t;
DataSourceManager manager = pageContext.getDataSourceManager();
try {
manager.rollback();
} catch (DatabaseException e) {
// print.printST(e);
}
throw t;
}
use of lucee.runtime.exp.DatabaseException in project Lucee by lucee.
the class QueryImpl method addColumn.
@Override
public boolean addColumn(Collection.Key columnName, Array content, int type) throws DatabaseException {
// disconnectCache();
// TODO Meta type
content = (Array) Duplicator.duplicate(content, false);
if (getIndexFromKey(columnName) != -1)
throw new DatabaseException("column name [" + columnName.getString() + "] already exist", null, sql, null);
if (content.size() != getRecordcount()) {
// throw new DatabaseException("array for the new column has not the same size like the query (arrayLen!=query.recordcount)");
if (content.size() > getRecordcount())
addRow(content.size() - getRecordcount());
else
content.setEL(getRecordcount(), "");
}
QueryColumnImpl[] newColumns = new QueryColumnImpl[columns.length + 1];
Collection.Key[] newColumnNames = new Collection.Key[columns.length + 1];
boolean logUsage = false;
for (int i = 0; i < columns.length; i++) {
newColumns[i] = columns[i];
newColumnNames[i] = columnNames[i];
if (!logUsage && columns[i] instanceof DebugQueryColumn)
logUsage = true;
}
newColumns[columns.length] = new QueryColumnImpl(this, columnName, content, type);
newColumnNames[columns.length] = columnName;
columns = newColumns;
columnNames = newColumnNames;
columncount++;
if (logUsage)
enableShowQueryUsage();
return true;
}
use of lucee.runtime.exp.DatabaseException in project Lucee by lucee.
the class DatasourceConnectionPool method loadDatasourceConnection.
private DatasourceConnectionImpl loadDatasourceConnection(Config config, DataSource ds, String user, String pass) throws PageException {
Connection conn = null;
try {
conn = ds.getConnection(config, user, pass);
conn.setAutoCommit(true);
} catch (SQLException e) {
throw new DatabaseException(e, null);
} catch (Exception e) {
throw Caster.toPageException(e);
}
return new DatasourceConnectionImpl(conn, ds, user, pass);
}
use of lucee.runtime.exp.DatabaseException in project Lucee by lucee.
the class DatasourceManagerImpl method getConnection.
@Override
public DatasourceConnection getConnection(PageContext pc, DataSource ds, String user, String pass) throws PageException {
if (autoCommit) {
return config.getDatasourceConnectionPool().getDatasourceConnection(ThreadLocalPageContext.getConfig(pc), ds, user, pass);
}
pc = ThreadLocalPageContext.get(pc);
// DatasourceConnection newDC = _getConnection(pc,ds,user,pass);
DatasourceConnectionPro existingDC = null;
try {
existingDC = (DatasourceConnectionPro) transConns.get(ds);
// first time that datasource is used within this transaction
if (existingDC == null) {
DatasourceConnection newDC = config.getDatasourceConnectionPool().getDatasourceConnection(config, ds, user, pass);
newDC.getConnection().setAutoCommit(false);
if (isolation != Connection.TRANSACTION_NONE)
newDC.getConnection().setTransactionIsolation(isolation);
transConns.put(ds, newDC);
return newDC;
}
// we have already the same datasource but with different credentials
if (!DatasourceConnectionImpl.equals(existingDC, ds, user, pass)) {
if (QOQ_DATASOURCE_NAME.equalsIgnoreCase(ds.getName()))
return existingDC;
throw new DatabaseException("can't use different connections to the same datasource inside a single transaction.", null, null, existingDC);
}
// make sure we have auto commit disabled TODO i dont think this is necessary anymore
if (existingDC.isAutoCommit()) {
existingDC.setAutoCommit(false);
}
return existingDC;
} catch (SQLException e) {
throw new DatabaseException(e, null, existingDC);
// ExceptionHandler.printStackTrace(e);
}
// return newDC;
}
Aggregations