I'm getting an exception when I attempt to insert a large number of rows 
into a table with SET ALLOW_LITERALS NONE applied.  This is repeatable with 
the following code snippet:

    public void analyzeLiteralFailure() throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:");
        conn.createStatement().execute("SET ALLOW_LITERALS NONE");
        
        conn.prepareStatement("CREATE TABLE test (id INT)").execute();

        for(int i = 0; i < 10000; i++) {
            PreparedStatement ps = conn.prepareStatement("INSERT INTO test 
(id) VALUES (?)");
            ps.setInt(1, i);
            ps.executeUpdate();
        }
    }

The stack trace I see is:

org.h2.jdbc.JdbcSQLException: Literals of this kind are not allowed; SQL 
statement:
SELECT SELECTIVITY(ID) FROM PUBLIC.TEST LIMIT 1 SAMPLE_SIZE 1000 [90116-173]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:331)
at org.h2.message.DbException.get(DbException.java:171)
at org.h2.message.DbException.get(DbException.java:148)
at org.h2.message.DbException.get(DbException.java:137)
at org.h2.command.Parser.checkLiterals(Parser.java:3075)
at org.h2.command.Parser.read(Parser.java:2998)
at org.h2.command.Parser.readIf(Parser.java:2863)
at org.h2.command.Parser.parseEndOfQuery(Parser.java:1658)
at org.h2.command.Parser.parseSelectUnionExtension(Parser.java:1581)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1551)
at org.h2.command.Parser.parseSelect(Parser.java:1538)
at org.h2.command.Parser.parsePrepared(Parser.java:405)
at org.h2.command.Parser.parse(Parser.java:279)
at org.h2.command.Parser.parse(Parser.java:251)
at org.h2.command.Parser.prepare(Parser.java:202)
at org.h2.engine.Session.prepare(Session.java:401)
at org.h2.engine.Session.prepare(Session.java:388)
at org.h2.command.ddl.Analyze.analyzeTable(Analyze.java:100)
at org.h2.table.RegularTable.analyzeIfRequired(RegularTable.java:423)
at org.h2.table.RegularTable.addRow(RegularTable.java:157)
at org.h2.command.dml.Insert.insertRows(Insert.java:127)
at org.h2.command.dml.Insert.update(Insert.java:86)
at org.h2.command.CommandContainer.update(CommandContainer.java:79)
at org.h2.command.Command.executeUpdate(Command.java:235)
at 
org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:154)
at 
org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:140)
at db.H2UsageFunct.analyzeLiteralFailure(H2UsageFunct.java:128)

It appears RegularTable executes an ANALYZE command if enough rows are 
inserted, but uses hard coded values (LIMIT, SAMPLE_SIZE) rather than 
populating them with a prepared statement, causing this exception when 
literals are disabled.  I noticed a similar bug report here: 
https://groups.google.com/forum/#!msg/h2-database/xwB2jXxMqGE/t44itMbqiXgJ

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to