⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statementregressiontest.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            assertTrue("Retrieved value of length " + result.length() +                " != length of inserted value " + charBuf.length,                result.length() == charBuf.length);        } finally {            ((com.mysql.jdbc.Connection) this.conn).setTraceProtocol(false);            if (this.rs != null) {                try {                	this.rs.close();                } catch (Exception ex) {                    // ignore                }                this.rs = null;            }            this.stmt.executeUpdate("DROP TABLE IF EXISTS `charStream'RegressTest`");            this.stmt.executeUpdate("DROP TABLE IF EXISTS charStreamRegressTest");        }    }    /**     * Tests a bug where Statement.setFetchSize() does not work for values     * other than 0 or Integer.MIN_VALUE     *     * @throws Exception if any errors occur     */    public void testSetFetchSize() throws Exception {        int oldFetchSize = this.stmt.getFetchSize();        try {        	this.stmt.setFetchSize(10);        } finally {        	this.stmt.setFetchSize(oldFetchSize);        }    }    /**     * Tests fix for BUG#907     *     * @throws Exception if an error occurs     */    public void testSetMaxRows() throws Exception {        Statement maxRowsStmt = null;        try {            maxRowsStmt = this.conn.createStatement();            maxRowsStmt.setMaxRows(1);            maxRowsStmt.executeQuery("SELECT 1");        } finally {            if (maxRowsStmt != null) {                maxRowsStmt.close();            }        }    }    /**     * Tests for timestamp NPEs occuring in binary-format timestamps.     *     * @throws Exception DOCUMENT ME!     *     * @deprecated yes, we know we are using deprecated methods here :)     */    public void testTimestampNPE() throws Exception {        try {            Timestamp ts = new Timestamp(System.currentTimeMillis());            this.stmt.executeUpdate("DROP TABLE IF EXISTS testTimestampNPE");            this.stmt.executeUpdate(                "CREATE TABLE testTimestampNPE (field1 TIMESTAMP)");            this.pstmt = this.conn.prepareStatement(                    "INSERT INTO testTimestampNPE VALUES (?)");            this.pstmt.setTimestamp(1, ts);            this.pstmt.executeUpdate();            this.pstmt = this.conn.prepareStatement(                    "SELECT field1 FROM testTimestampNPE");            this.rs = this.pstmt.executeQuery();            this.rs.next();            System.out.println(this.rs.getString(1));            this.rs.getDate(1);            Timestamp rTs = this.rs.getTimestamp(1);            assertTrue("Retrieved year of " + rTs.getYear() +                " does not match " + ts.getYear(), rTs.getYear() == ts.getYear());            assertTrue("Retrieved month of " + rTs.getMonth() +                " does not match " + ts.getMonth(),                rTs.getMonth() == ts.getMonth());            assertTrue("Retrieved date of " + rTs.getDate() +                " does not match " + ts.getDate(), rTs.getDate() == ts.getDate());        } finally {        }    }    /**     * Tests fix for updatable streams being supported in updatable result     * sets.     *     * @throws Exception if the test fails.     */    public void testUpdatableStream() throws Exception {        try {            this.stmt.executeUpdate("DROP TABLE IF EXISTS updateStreamTest");            this.stmt.executeUpdate(                "CREATE TABLE updateStreamTest (keyField INT NOT NULL AUTO_INCREMENT PRIMARY KEY, field1 BLOB)");            int streamLength = 16385;            byte[] streamData = new byte[streamLength];            /* create an updatable statement */            Statement updStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,                    ResultSet.CONCUR_UPDATABLE);            /* fill the resultset with some values */            ResultSet updRs = updStmt.executeQuery(                    "SELECT * FROM updateStreamTest");            /* move to insertRow */            updRs.moveToInsertRow();            /* update the table */            updRs.updateBinaryStream("field1",                new ByteArrayInputStream(streamData), streamLength);            updRs.insertRow();        } finally {            this.stmt.executeUpdate("DROP TABLE IF EXISTS updateStreamTest");        }    }    private void createGGKTables() throws Exception {        //Delete and recreate table        dropGGKTables();        this.stmt.executeUpdate("CREATE TABLE testggk (" +            "id INT AUTO_INCREMENT NOT NULL PRIMARY KEY," + "val INT NOT NULL" +            ")");    }    private void doGGKTestPreparedStatement(int[] values, boolean useUpdate)        throws Exception {        //Generate the the multiple replace command        StringBuffer cmd = new StringBuffer("REPLACE INTO testggk VALUES ");        int newKeys = 0;        for (int i = 0; i < values.length; i++) {            cmd.append("(");            if (values[i] == 0) {                cmd.append("NULL");                newKeys += 1;            } else {                cmd.append(values[i]);            }            cmd.append(", ");            cmd.append(count++);            cmd.append("), ");        }        cmd.setLength(cmd.length() - 2); //trim the final ", "        //execute and print it        System.out.println(cmd.toString());        PreparedStatement pStmt = this.conn.prepareStatement(cmd.toString(),                Statement.RETURN_GENERATED_KEYS);        if (useUpdate) {            pStmt.executeUpdate();        } else {            pStmt.execute();        }        //print out what actually happened        System.out.println("Expect " + newKeys +            " generated keys, starting from " + nextID);        this.rs = pStmt.getGeneratedKeys();        StringBuffer res = new StringBuffer("Got keys");        int[] generatedKeys = new int[newKeys];        int i = 0;        while (this.rs.next()) {            if (i < generatedKeys.length) {                generatedKeys[i] = this.rs.getInt(1);            }            i++;            res.append(" " + this.rs.getInt(1));        }        int numberOfGeneratedKeys = i;        assertTrue(            "Didn't retrieve expected number of generated keys, expected " +            newKeys + ", found " + numberOfGeneratedKeys,            numberOfGeneratedKeys == newKeys);        assertTrue("Keys didn't start with correct sequence: ",            generatedKeys[0] == nextID);        System.out.println(res.toString());        //Read and print the new state of the table        this.rs = this.stmt.executeQuery("SELECT id, val FROM testggk");        System.out.println("New table contents ");        while (this.rs.next())            System.out.println("Id " + this.rs.getString(1) + " val " +            		this.rs.getString(2));        //Tidy up        System.out.println("");        nextID += newKeys;    }    private void doGGKTestStatement(int[] values, boolean useUpdate)        throws Exception {        //Generate the the multiple replace command        StringBuffer cmd = new StringBuffer("REPLACE INTO testggk VALUES ");        int newKeys = 0;        for (int i = 0; i < values.length; i++) {            cmd.append("(");            if (values[i] == 0) {                cmd.append("NULL");                newKeys += 1;            } else {                cmd.append(values[i]);            }            cmd.append(", ");            cmd.append(count++);            cmd.append("), ");        }        cmd.setLength(cmd.length() - 2); //trim the final ", "        //execute and print it        System.out.println(cmd.toString());        if (useUpdate) {        	this.stmt.executeUpdate(cmd.toString(), Statement.RETURN_GENERATED_KEYS);        } else {        	this.stmt.execute(cmd.toString(), Statement.RETURN_GENERATED_KEYS);        }        //print out what actually happened        System.out.println("Expect " + newKeys +            " generated keys, starting from " + nextID);        this.rs = this.stmt.getGeneratedKeys();        StringBuffer res = new StringBuffer("Got keys");        int[] generatedKeys = new int[newKeys];        int i = 0;        while (this.rs.next()) {            if (i < generatedKeys.length) {                generatedKeys[i] = this.rs.getInt(1);            }            i++;            res.append(" " + this.rs.getInt(1));        }        int numberOfGeneratedKeys = i;        assertTrue(            "Didn't retrieve expected number of generated keys, expected " +            newKeys + ", found " + numberOfGeneratedKeys,            numberOfGeneratedKeys == newKeys);        assertTrue("Keys didn't start with correct sequence: ",            generatedKeys[0] == nextID);        System.out.println(res.toString());        //Read and print the new state of the table        this.rs = this.stmt.executeQuery("SELECT id, val FROM testggk");        System.out.println("New table contents ");        while (this.rs.next())            System.out.println("Id " + this.rs.getString(1) + " val " +            		this.rs.getString(2));        //Tidy up        System.out.println("");        nextID += newKeys;    }    private void dropGGKTables() throws Exception {        this.stmt.executeUpdate("DROP TABLE IF EXISTS testggk");    }    /**     * Tests fix for BUG#4311 - Error in JDBC retrieval of mediumint column      * when using prepared statements and binary result sets.     *      * @throws Exception if the test fails.     */    public void testBug4311() throws Exception {        try {            int lowValue = -8388608;            int highValue = 8388607;            this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4311");            this.stmt.executeUpdate(                "CREATE TABLE testBug4311 (low MEDIUMINT, high MEDIUMINT)");            this.stmt.executeUpdate("INSERT INTO testBug4311 VALUES (" +                lowValue + ", " + highValue + ")");            PreparedStatement pStmt = this.conn.prepareStatement(                    "SELECT low, high FROM testBug4311");            this.rs = pStmt.executeQuery();            assertTrue(this.rs.next());            assertTrue(this.rs.getInt(1) == lowValue);            assertTrue(this.rs.getInt(2) == highValue);        } finally {            this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4311");        }    }    /**     * Tests fix for BUG#4510 -- Statement.getGeneratedKeys() fails     * when key > 32767     *      * @throws Exception if the test fails     */    public void testBug4510() throws Exception {        try {            this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4510");            this.stmt.executeUpdate("CREATE TABLE testBug4510 (" +                "field1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT," +                "field2 VARCHAR(100))");            this.stmt.executeUpdate(                "INSERT INTO testBug4510 (field1, field2) VALUES (32767, 'bar')");            PreparedStatement p = this.conn.prepareStatement("insert into testBug4510 (field2) values (?)",                    Statement.RETURN_GENERATED_KEYS);            p.setString(1, "blah");            p.executeUpdate();            ResultSet rs = p.getGeneratedKeys();            rs.next();            System.out.println("Id: " + rs.getInt(1));            rs.close();        } finally {            this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4510");        }    }        /**     * Tests fix for BUG#5012 -- ServerPreparedStatements dealing with     * return of DECIMAL type don't work.     *      * @throws Exception if the test fails.     */    public void testBug5012() throws Exception {    	PreparedStatement pStmt = null;    	String valueAsString = "12345.12";    	    	try {    		this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5012");    		this.stmt.executeUpdate("CREATE TABLE testBug5012(field1 DECIMAL(6,2))");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -