use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class Database method getScript.
/**
* Returns the schema and authorisation statements for the database.
*/
public Result getScript(boolean indexRoots) {
Result r = Result.newSingleColumnResult("COMMAND", Type.SQL_VARCHAR);
String[] list = getSettingsSQL();
addRows(r, list);
list = getGranteeManager().getSQL();
addRows(r, list);
// schemas and schema objects such as tables, sequences, etc.
list = schemaManager.getSQLArray();
addRows(r, list);
// index roots
if (indexRoots) {
list = schemaManager.getIndexRootsSQL();
addRows(r, list);
}
// user session start schema names
list = getUserManager().getInitialSchemaSQL();
addRows(r, list);
// grantee rights
list = getGranteeManager().getRightstSQL();
addRows(r, list);
list = getPropertiesSQL();
addRows(r, list);
return r;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class HSQLInterface method getXMLCompiledStatement.
/**
* Compile a SQL statement with parameters into an XML representation.<p>
* Any question-marks (?) in the statement will be considered parameters.
*
* @param sql SQL statement to be compiled against the current schema.
* @return Pseudo XML representation of the compiled statement.
* @throws HSQLParseException Throws exception if SQL parse error is
* encountered.
*/
public VoltXMLElement getXMLCompiledStatement(String sql) throws HSQLParseException {
Statement cs = null;
// clear the expression node id set for determinism
sessionProxy.resetVoltNodeIds();
try {
cs = sessionProxy.compileStatement(sql);
} catch (HsqlException caught) {
// a switch in case we want to give more error details on additional error codes
switch(caught.getErrorCode()) {
case -ErrorCode.X_42581:
throw new HSQLParseException("SQL Syntax error in \"" + sql + "\" " + caught.getMessage(), caught);
default:
throw new HSQLParseException("Error in \"" + sql + "\" " + caught.getMessage(), caught);
}
} catch (StackOverflowError caught) {
// SQL statement causing unreasonable levels of recursion.
throw caught;
} catch (Throwable caught) {
// Expectable user errors should have been thrown as HSQLException.
// So, this throwable should be an unexpected system error.
// The details of these arbitrary Throwables are not typically
// useful to an end user reading an error message.
// They should be logged.
m_logger.error("Unexpected error in the SQL parser for statement \"" + sql + "\" ", caught);
// (especially if they can provide the log traces).
throw new HSQLParseException("An unexpected system error was logged by the SQL parser for statement \"" + sql + "\" ", caught);
}
//Result result = Result.newPrepareResponse(cs.id, cs.type, rmd, pmd);
Result result = Result.newPrepareResponse(cs);
if (result.hasError()) {
throw new HSQLParseException(result.getMainString());
}
VoltXMLElement xml = null;
xml = cs.voltGetStatementXML(sessionProxy);
if (m_logger.isDebugEnabled()) {
try {
/*
* Sometimes exceptions happen.
*/
m_logger.debug(String.format("SQL: %s\n", sql));
;
m_logger.debug(String.format("HSQLDB:\n%s", (cs == null) ? "<NULL>" : cs.describe(sessionProxy)));
m_logger.debug(String.format("VOLTDB:\n%s", (xml == null) ? "<NULL>" : xml));
} catch (Exception caught) {
m_logger.warn("Unexpected error in the SQL parser", caught);
caught.printStackTrace(System.out);
}
}
// this releases some small memory hsql uses that builds up over time if not
// cleared
// if it's not called for every call of getXMLCompiledStatement, that's ok;
// it'll get called next time
sessionProxy.sessionData.persistentStoreCollection.clearAllTables();
// clean up sql-in expressions
fixupInStatementExpressions(xml);
assert (xml != null);
return xml;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class DatabaseInformationFull method SQL_SIZING.
Table SQL_SIZING() {
Table t = sysTables[SQL_SIZING];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SQL_SIZING]);
addColumn(t, "SIZING_ID", CARDINAL_NUMBER);
addColumn(t, "SIZING_NAME", CHARACTER_DATA);
addColumn(t, "SUPPORTED_VALUE", CARDINAL_NUMBER);
addColumn(t, "COMMENTS", CHARACTER_DATA);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_SIZING].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
String sql = (String) statementMap.get("/*sql_sizing*/");
Result rs = sys.executeDirectStatement(sql);
t.insertSys(store, rs);
return t;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class DatabaseInformationFull method CONSTRAINT_TABLE_USAGE.
/**
* The CONSTRAINT_TABLE_USAGE view has one row for each table identified by a
* <table name> simply contained in a <table reference>
* contained in the <search condition> of a check constraint,
* domain constraint, or assertion. It has one row for each table
* containing / referenced by each PRIMARY KEY, UNIQUE and FOREIGN KEY
* constraint<p>
*
* <b>Definition:</b> <p>
*
* <pre class="SqlCodeExample">
* CONSTRAINT_CATALOG VARCHAR
* CONSTRAINT_SCHEMA VARCHAR
* CONSTRAINT_NAME VARCHAR
* TABLE_CATALOG VARCHAR
* TABLE_SCHEMA VARCHAR
* TABLE_NAME VARCHAR
* </pre>
*
* <b>Description:</b> <p>
*
* <ol>
* <li> The values of CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, and
* CONSTRAINT_NAME are the catalog name, unqualified schema name,
* and qualified identifier, respectively, of the constraint being
* described. <p>
*
* <li> The values of TABLE_CATALOG, TABLE_SCHEMA, and TABLE_NAME are the
* catalog name, unqualified schema name, and qualified identifier,
* respectively, of a table identified by a <table name>
* simply contained in a <table reference> contained in the
* *lt;search condition> of the constraint being described, or
* its columns.
* </ol>
*
* @return Table
*/
Table CONSTRAINT_TABLE_USAGE() {
Table t = sysTables[CONSTRAINT_TABLE_USAGE];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[CONSTRAINT_TABLE_USAGE]);
addColumn(t, "CONSTRAINT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CONSTRAINT_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "CONSTRAINT_NAME", SQL_IDENTIFIER);
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
// not null
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CONSTRAINT_TABLE_USAGE].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 3, 4, 5 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
//
Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
Result rs = sys.executeDirectStatement("select DISTINCT CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, " + "CONSTRAINT_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME " + "from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE");
t.insertSys(store, rs);
sys.close();
return t;
}
use of org.hsqldb_voltpatches.result.Result in project voltdb by VoltDB.
the class DatabaseInformationFull method SQL_PARTS.
Table SQL_PARTS() {
Table t = sysTables[SQL_PARTS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[SQL_PARTS]);
addColumn(t, "PART", CHARACTER_DATA);
addColumn(t, "NAME", CHARACTER_DATA);
addColumn(t, "IS_SUPPORTED", YES_OR_NO);
addColumn(t, "IS_VERIFIED_BY", CHARACTER_DATA);
addColumn(t, "COMMENTS", CHARACTER_DATA);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SQL_PARTS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0 }, false);
return t;
}
PersistentStore store = database.persistentStoreCollection.getStore(t);
Session sys = database.sessionManager.newSysSession(SqlInvariants.INFORMATION_SCHEMA_HSQLNAME, session.getUser());
String sql = (String) statementMap.get("/*sql_parts*/");
Result rs = sys.executeDirectStatement(sql);
t.insertSys(store, rs);
return t;
}
Aggregations