Sorry! I forgot to include a stack trace:
java.sql.SQLException: wpfeature_universe_wpfuniv.id_wpfuniv may not
be NULL
at org.sqlite.DB.execute(DB.java:236)
at org.sqlite.PrepStmt.execute(PrepStmt.java:59)
at
com.thomson.care.utils.SqliteJdbcTest.testPreparedStatement(SqliteJdbcTest.java:
101)
at
com.thomson.care.utils.SqliteJdbcTest.doesNotWork(SqliteJdbcTest.java:
75)
$ java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
$
I am using the Windows (3.5.4) release of the SQLiteJDBC drive.
Thanks!
On Jan 25, 2:52 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Hi there, everyone!
>
> I would just like to report a problem we found. The issue is
> executing prepared statements that created -before- a schema change
> but execute -after- the schema change.
>
> Here's a JUnit test to show what I mean:
>
> /**
> *
> */
> package com.thomson.care.utils;
>
> import java.io.File;
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
>
> import org.junit.After;
> import org.junit.Assert;
> import org.junit.Before;
> import org.junit.Test;
>
> /**
> * We found some strange behavior where executing a preparedstatement
> after a
> * schema change caused a SQLException("KEY may not be null") to be
> thrown
> *
> * This test tries to reproduce it
> *
> * @author u0066990
> *
> */
> public class SqliteJdbcTest
> {
> private static Connection conn;
>
> @Before
> public void beforeClass() throws ClassNotFoundException,
> SQLException
> {
> new File( "test.db" ).delete();
> Class.forName( "org.sqlite.JDBC" );
> conn = getConnection();
> }
>
> private static Connection getConnection() throws SQLException
> {
> return DriverManager.getConnection( "jdbc:sqlite:test.db" );
> }
>
> @After
> public void afterClass() throws SQLException
> {
> if ( conn != null )
> {
> conn.close();
> }
> new File( "test.db" ).delete();
> }
>
> @Test
> public void doesWork() throws Exception
> {
> boolean changeSchema = false;
> testPreparedStatement( changeSchema );
> }
>
> private void verifyRowIsPresent() throws SQLException
> {
> final ResultSet rs =
> conn.createStatement().executeQuery(
> "SELECT * from wpfeature_universe_wpfuniv" );
> rs.next();
> Assert.assertEquals( 1000, rs.getInt( 1 ) );
> }
>
> @Test
> public void doesNotWork() throws Exception
> {
> boolean changeSchema = true;
> testPreparedStatement( changeSchema );
>
> }
>
> private void testPreparedStatement( boolean changeSchema )
> throws SQLException
> {
> Statement stat = conn.createStatement();
> // create a new table
> final String sql =
> "CREATE TABLE wpfeature_universe_wpfuniv ("
> + "id_wpfuniv INTEGER NOT NULL" + ")";
> stat.executeUpdate( sql );
>
> // create a preparedstatement
> PreparedStatement prepSt =
> conn
> .prepareStatement( "INSERT INTO
> wpfeature_universe_wpfuniv (id_wpfuniv) VALUES(?)" );
>
> // change the schema
> if ( changeSchema )
> {
> conn.createStatement().executeUpdate(
> "create table cats(name, napTime )" );
> }
> prepSt.setInt( 1, 1000 );
> prepSt.execute();
>
> // insert new row
> prepSt.executeUpdate();
> verifyRowIsPresent();
> }
>
> }
>
> Anyone have any thoughts? Thanks!
--~--~---------~--~----~------------~-------~--~----~
Mailing List: http://groups.google.com/group/sqlitejdbc?hl=en
To unsubscribe, send email to [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---