📄 compiledstatement.java
字号:
types[i] = parameters[i].getDataType(); } this.paramTypes = types; } private void setSubqueries(SubQuery[] subqueries) { this.subqueries = subqueries; } void materializeSubQueries(Session session) throws HsqlException { for (int i = 0; i < subqueries.length; i++) { SubQuery sq = subqueries[i]; // VIEW working table contents are filled only once per query and reused if (sq.isMaterialised) { continue; } if (sq.isResolved) { sq.populateTable(session); sq.isMaterialised = true; } } } void dematerializeSubQueries(Session session) { if (subqueries == null) { return; } for (int i = 0; i < subqueries.length; i++) { subqueries[i].table.clearAllRows(session); subqueries[i].isMaterialised = false; } } void clearVariables() { isValid = false; targetTable = null; targetFilter = null; condition = null; columnMap = null; columnValues = null; checkColumns = null; expression = null; select = null; parameters = null; paramTypes = null; subqueries = null; } boolean canExecute(Session session) throws HsqlException { switch (type) { case CALL : {} case SELECT : for (int i = 0; i < select.tFilter.length; i++) { HsqlName name = select.tFilter[i].filterTable.getName(); session.check(name, UserManager.SELECT); } break; case INSERT_SELECT : break; case DELETE : session.check(targetTable.getName(), UserManager.DELETE); break; case INSERT_VALUES : session.check(targetTable.getName(), UserManager.INSERT); break; case UPDATE : session.check(targetTable.getName(), UserManager.UPDATE); break; case DDL : } return true; } void checkTableWriteAccess(Session session, Table table) throws HsqlException { // session level user rights session.checkReadWrite(); // object type if (table.isView()) { throw Trace.error(Trace.NOT_A_TABLE, table.getName().name); } // object readonly table.checkDataReadOnly(); } private static final Result updateCountResult = new Result(ResultConstants.UPDATECOUNT); Result describeResult() { switch (type) { case CALL : { // TODO: // // 1.) standard to register metadata for columns of // the primary result set, if any, generated by call // // 2.) Represent the return value, if any (which is // not, in truth, a result set), as an OUT parameter // // For now, I've reverted a bunch of code I had in place // and instead simply reflect things as the are, describing // a single column result set that communicates // the return value. If the expression generating the // return value has a void return type, a result set // is described whose single column is of type NULL Expression e; Result r; e = expression; r = Result.newSingleColumnResult( CompiledStatement.RETURN_COLUMN_NAME, e.getDataType()); r.metaData.classNames[0] = e.getValueClassName(); // no more setup for r; all the defaults apply return r; } case SELECT : return select.sIntoTable == null ? select.describeResult() : updateCountResult; case DELETE : case INSERT_SELECT : case INSERT_VALUES : case UPDATE : case DDL : // will result in return updateCountResult; default : return new Result( Trace.runtimeError( Trace.UNSUPPORTED_INTERNAL_OPERATION, "CompiledStatement.describeResult()"), null); } } Result describeParameters() { Result out; Expression e; int outlen; int offset; int idx; boolean hasReturnValue; outlen = parameters.length; offset = 0;// NO: Not yet// hasReturnValue = (type == CALL && !expression.isProcedureCall());//// if (hasReturnValue) {// outlen++;// offset = 1;// } out = Result.newParameterDescriptionResult(outlen);// NO: Not yet// if (hasReturnValue) {// e = expression;// out.sName[0] = DIProcedureInfo.RETURN_COLUMN_NAME;// out.sClassName[0] = e.getValueClassName();// out.colType[0] = e.getDataType();// out.colSize[0] = e.getColumnSize();// out.colScale[0] = e.getColumnScale();// out.nullability[0] = e.nullability;// out.isIdentity[0] = false;// out.paramMode[0] = expression.PARAM_OUT;// } for (int i = 0; i < parameters.length; i++) { e = parameters[i]; idx = i + offset; // always i + 1. We currently use the convention of @p0 to name the // return value OUT parameter out.metaData.colNames[idx] = CompiledStatement.PCOL_PREFIX + (i + 1); // sLabel is meaningless in this context. out.metaData.classNames[idx] = e.getValueClassName(); out.metaData.colTypes[idx] = e.getDataType(); out.metaData.colSizes[idx] = e.getColumnSize(); out.metaData.colScales[idx] = e.getColumnScale(); out.metaData.colNullable[idx] = e.nullability; out.metaData.isIdentity[idx] = e.isIdentity; // currently will always be Expression.PARAM_IN out.metaData.paramMode[idx] = e.paramMode; } return out; } /** * Retrieves a String representation of this object. * * @return the String representation of this object */ public String describe(Session session) { try { return describeImpl(session); } catch (Exception e) { return e.toString(); } } /** * Provides the toString() implementation. * * @throws Exception if a database access or io error occurs * @return the String representation of this object */ private String describeImpl(Session session) throws Exception { StringBuffer sb; sb = new StringBuffer(); switch (type) { case SELECT : { sb.append(select.describe(session)); appendParms(sb).append('\n'); appendSubqueries(sb); return sb.toString(); } case INSERT_VALUES : { sb.append("INSERT VALUES"); sb.append('[').append('\n'); appendColumns(sb).append('\n'); appendTable(sb).append('\n'); appendParms(sb).append('\n'); appendSubqueries(sb).append(']'); return sb.toString(); } case INSERT_SELECT : { sb.append("INSERT SELECT"); sb.append('[').append('\n'); appendColumns(sb).append('\n'); appendTable(sb).append('\n'); sb.append(select.describe(session)).append('\n'); appendParms(sb).append('\n'); appendSubqueries(sb).append(']'); return sb.toString(); } case UPDATE : { sb.append("UPDATE"); sb.append('[').append('\n'); appendColumns(sb).append('\n'); appendTable(sb).append('\n'); appendCondition(session, sb); sb.append(targetFilter.describe(session)).append('\n'); appendParms(sb).append('\n'); appendSubqueries(sb).append(']'); return sb.toString(); } case DELETE : { sb.append("DELETE"); sb.append('[').append('\n'); appendTable(sb).append('\n'); appendCondition(session, sb); sb.append(targetFilter.describe(session)).append('\n'); appendParms(sb).append('\n'); appendSubqueries(sb).append(']'); return sb.toString(); } case CALL : { sb.append("CALL"); sb.append('['); sb.append(expression.describe(session)).append('\n'); appendParms(sb).append('\n'); appendSubqueries(sb).append(']'); return sb.toString(); } default : { return "UNKNOWN"; } } } private StringBuffer appendSubqueries(StringBuffer sb) { sb.append("SUBQUERIES["); for (int i = 0; i < subqueries.length; i++) { sb.append("\n[level=").append(subqueries[i].level).append( '\n').append("hasParams=").append( subqueries[i].hasParams).append('\n'); if (subqueries[i].select != null) { sb.append("org.hsqldb.Select@").append( Integer.toHexString(subqueries[i].select.hashCode())); } sb.append("]"); } sb.append(']'); return sb; } private StringBuffer appendTable(StringBuffer sb) { sb.append("TABLE[").append(targetTable.getName().name).append(']'); return sb; } private StringBuffer appendColumns(StringBuffer sb) { sb.append("COLUMNS=["); for (int i = 0; i < columnMap.length; i++) { sb.append('\n').append(columnMap[i]).append(':').append( ' ').append( targetTable.getColumn(columnMap[i]).columnName.name).append( '[').append(columnValues[i]).append(']'); } sb.append(']'); return sb; } private StringBuffer appendParms(StringBuffer sb) { sb.append("PARAMETERS=["); for (int i = 0; i < parameters.length; i++) { sb.append('\n').append('@').append(i).append('[').append( parameters[i]).append(']'); } sb.append(']'); return sb; } private StringBuffer appendCondition(Session session, StringBuffer sb) { return condition == null ? sb.append("CONDITION[]\n") : sb.append("CONDITION[").append( condition.describe(session)).append( "]\n"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -