db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bryan Pendleton <bpendle...@amberpoint.com>
Subject Confusing message from constraint processing (DERBY-4248)
Date Thu, 18 Jun 2009 17:22:18 GMT
While working with Eranda on DERBY-4248, we've run across a behavior
I don't understand, and I am hoping somebody can shed some light on it.

Below is a very short program, and the result I get when I run it.

Note that the table name ("C1") and the cursor name ("C1") are the
same, and somehow this seems to confuse the constraints binding code
for the update statement into thinking that column "c2" doesn't exist
in the table, when in fact the column *does* exist.

Is this a bug? Or am I misunderstanding what the behavior should be?

thanks,

bryan


import java.sql.*;

public class cons
{
     public static void main(String []args)
         throws Exception
     {
         Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
         Connection conn =
             DriverManager.getConnection("jdbc:derby:testdb;create=true");
         Statement st = conn.createStatement();

         st.executeUpdate(
             "create table t1(c1 int, c2 int, constraint ck1 "
             + "check(c1 = c2), constraint ck2 check(c2=c1))");

         st.executeUpdate("insert into t1 values (1, 1),(2, 2),(3, 3),(4, 4)");

         Statement st1=conn.createStatement();
         st1.setCursorName("c1");
         ResultSet rs = st1.executeQuery("select * from t1 for update");
         rs.next();
         st.executeUpdate("update t1 set c1 = c1 where current of \"c1\"");
     }
}

Exception in thread "main" java.sql.SQLException: Column 'C2' is either not in a
ny table in the FROM list or appears within a join specification and is outside
the scope of the join specification or appears in a HAVING clause and is not in
the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then 'C2' is no
t a column in the target table.
         at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(SQLExc
eptionFactory.java:45)
         at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:201)

         at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException
(TransactionResourceImpl.java:391)
         at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Tr
ansactionResourceImpl.java:346)
         at org.apache.derby.impl.jdbc.EmbedConnection.handleException(EmbedConne
ction.java:2201)
         at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Connection
Child.java:81)
         at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java
:614)
         at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(EmbedStatemen
t.java:175)
         at cons.main(cons.java:25)
Caused by: ERROR 42X04: Column 'C2' is either not in any table in the FROM list
or appears within a join specification and is outside the scope of the join spec
ification or appears in a HAVING clause and is not in the GROUP BY list. If this
  is a CREATE or ALTER TABLE  statement then 'C2' is not a column in the target t
able.
         at org.apache.derby.iapi.error.StandardException.newException(StandardEx
ception.java:286)
         at org.apache.derby.impl.sql.compile.ColumnReference.bindExpression(Colu
mnReference.java:354)
         at org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression(B
inaryOperatorNode.java:298)
         at org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.bindEx
pression(BinaryComparisonOperatorNode.java:133)
         at org.apache.derby.impl.sql.compile.UnaryOperatorNode.bindOperand(Unary
OperatorNode.java:333)
         at org.apache.derby.impl.sql.compile.TestConstraintNode.bindExpression(T
estConstraintNode.java:92)
         at org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression(B
inaryOperatorNode.java:298)
         at org.apache.derby.impl.sql.compile.BinaryLogicalOperatorNode.bindExpre
ssion(BinaryLogicalOperatorNode.java:94)
         at org.apache.derby.impl.sql.compile.AndNode.bindExpression(AndNode.java
:68)
         at org.apache.derby.impl.sql.compile.DMLModStatementNode.bindRowScopedEx
pression(DMLModStatementNode.java:809)
         at org.apache.derby.impl.sql.compile.DMLModStatementNode.bindConstraints
(DMLModStatementNode.java:735)
         at org.apache.derby.impl.sql.compile.UpdateNode.bindStatement(UpdateNode
.java:618)
         at org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatemen
t.java:316)
         at org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.j
ava:88)
         at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepa
reInternalStatement(GenericLanguageConnectionContext.java:822)
         at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java
:606)
         ... 2 more


Mime
View raw message