~ubuntu-branches/ubuntu/trusty/mysql-connector-java/trusty

« back to all changes in this revision

Viewing changes to src/testsuite/regression/StatementRegressionTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg, Miguel Landaeta
  • Date: 2013-07-02 17:07:51 UTC
  • mfrom: (1.1.8) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130702170751-f4rszjabxg0391fr
Tags: 5.1.25-1
* New upstream release
* Refreshed the patches
* Added a patch to build with one JDK and removed the build
  dependency on java-gcj-compat-dev
* Updated Standards-Version to 3.9.4 (no changes)
* Use canonical URLs for the Vcs-* fields
* debian/rules: Improved the clean target to allow rebuilds
* Updated the watch file
* Renamed debian/README.Debian-source to README.source

[ Miguel Landaeta ] 
* Fix FTBFS with OpenJDK 7 (Closes: #706668)
* Remove Michael Koch from Uploaders list.
  Thanks for your work on this package. (Closes: #654122).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
 
2
 Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3
3
 
4
4
 
5
5
 
73
73
import testsuite.UnreliableSocketFactory;
74
74
 
75
75
import com.mysql.jdbc.CachedResultSetMetaData;
 
76
import com.mysql.jdbc.CharsetMapping;
76
77
import com.mysql.jdbc.Field;
 
78
import com.mysql.jdbc.MySQLConnection;
77
79
import com.mysql.jdbc.NonRegisteringDriver;
78
80
import com.mysql.jdbc.ParameterBindings;
79
81
import com.mysql.jdbc.ResultSetInternalMethods;
82
84
import com.mysql.jdbc.StatementImpl;
83
85
import com.mysql.jdbc.StatementInterceptor;
84
86
import com.mysql.jdbc.StatementInterceptorV2;
85
 
import com.mysql.jdbc.exceptions.MySQLStatementCancelledException;
86
87
import com.mysql.jdbc.exceptions.MySQLTimeoutException;
87
88
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
88
89
 
141
142
                junit.textui.TestRunner.run(StatementRegressionTest.class);
142
143
        }
143
144
 
144
 
        private int testServerPrepStmtDeadlockCounter = 0;
 
145
        protected int testServerPrepStmtDeadlockCounter = 0;
145
146
 
146
147
        /**
147
148
         * Constructor for StatementRegressionTest.
859
860
                        } catch (DataTruncation truncEx) {
860
861
                                // we expect this
861
862
                        } finally {
862
 
                                if (this.stmt != null) {
863
 
                                        this.stmt.close();
864
 
                                }
865
 
 
866
863
                                if (truncConn != null) {
867
864
                                        truncConn.close();
868
865
                                }
1041
1038
 
1042
1039
                                assertTrue(!this.rs.next());
1043
1040
                        } finally {
1044
 
                                maxRowsConn.close();
 
1041
                                if (maxRowsConn != null) {
 
1042
                                        maxRowsConn.close();
 
1043
                                }
1045
1044
                        }
1046
1045
                }
1047
1046
        }
1192
1191
        public void testBug3103() throws Exception {
1193
1192
                try {
1194
1193
                        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3103");
1195
 
                        this.stmt
1196
 
                                        .executeUpdate("CREATE TABLE testBug3103 (field1 DATETIME)");
 
1194
 
 
1195
                        if (versionMeetsMinimum(5, 6, 4)) {
 
1196
                                this.stmt.executeUpdate("CREATE TABLE testBug3103 (field1 DATETIME(3))");
 
1197
                        } else {
 
1198
                                this.stmt.executeUpdate("CREATE TABLE testBug3103 (field1 DATETIME)");
 
1199
                        }
1197
1200
 
1198
1201
                        PreparedStatement pStmt = this.conn
1199
1202
                                        .prepareStatement("INSERT INTO testBug3103 VALUES (?)");
1541
1544
                        batchStmt.setString(1, "ghi");
1542
1545
                        batchStmt.addBatch();
1543
1546
 
 
1547
                        @SuppressWarnings("unused")
1544
1548
                        int[] updateCounts = batchStmt.executeBatch();
1545
1549
 
1546
1550
                        this.rs = batchStmt.getGeneratedKeys();
1665
1669
 
1666
1670
                        p.executeUpdate();
1667
1671
 
1668
 
                        ResultSet rs = p.getGeneratedKeys();
1669
 
                        rs.next();
1670
 
                        System.out.println("Id: " + rs.getInt(1));
1671
 
                        rs.close();
 
1672
                        ResultSet genKeysRs = p.getGeneratedKeys();
 
1673
                        genKeysRs.next();
 
1674
                        System.out.println("Id: " + genKeysRs.getInt(1));
 
1675
                        genKeysRs.close();
1672
1676
                } finally {
1673
1677
                        this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4510");
1674
1678
                }
2476
2480
         */
2477
2481
        public void testLoadData() throws Exception {
2478
2482
                try {
2479
 
                        int maxAllowedPacket = 1048576;
 
2483
                        //int maxAllowedPacket = 1048576;
2480
2484
 
2481
2485
                        this.stmt.executeUpdate("DROP TABLE IF EXISTS loadDataRegress");
2482
2486
                        this.stmt
2522
2526
                        int updateCount = this.stmt
2523
2527
                                        .executeUpdate("LOAD DATA LOCAL INFILE '"
2524
2528
                                                        + fileNameBuf.toString()
2525
 
                                                        + "' INTO TABLE loadDataRegress");
 
2529
                                                        + "' INTO TABLE loadDataRegress" +
 
2530
                                                        " CHARACTER SET " + CharsetMapping.getMysqlEncodingForJavaEncoding(((MySQLConnection)this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
2526
2531
                        assertTrue(updateCount == rowCount);
2527
2532
                } finally {
2528
2533
                        this.stmt.executeUpdate("DROP TABLE IF EXISTS loadDataRegress");
2537
2542
                try {
2538
2543
                        pStmt = this.conn
2539
2544
                                        .prepareStatement("INSERT INTO testNullClob VALUES (?)");
2540
 
                        pStmt.setClob(1, null);
 
2545
                        pStmt.setClob(1, (Clob) null);
2541
2546
                        pStmt.executeUpdate();
2542
2547
                } finally {
2543
2548
                        if (pStmt != null) {
2559
2564
                        this.stmt
2560
2565
                                        .executeUpdate("CREATE TABLE testParameterBoundsCheck(f1 int, f2 int, f3 int, f4 int, f5 int)");
2561
2566
 
2562
 
                        PreparedStatement pstmt = this.conn
 
2567
                        PreparedStatement _pstmt = this.conn
2563
2568
                                        .prepareStatement("UPDATE testParameterBoundsCheck SET f1=?, f2=?,f3=?,f4=? WHERE f5=?");
2564
2569
 
2565
 
                        pstmt.setString(1, "");
2566
 
                        pstmt.setString(2, "");
 
2570
                        _pstmt.setString(1, "");
 
2571
                        _pstmt.setString(2, "");
2567
2572
 
2568
2573
                        try {
2569
 
                                pstmt.setString(25, "");
 
2574
                                _pstmt.setString(25, "");
2570
2575
                        } catch (SQLException sqlEx) {
2571
2576
                                assertTrue(SQLError.SQL_STATE_ILLEGAL_ARGUMENT.equals(sqlEx
2572
2577
                                                .getSQLState()));
2981
2986
                        assertTrue("Retrieved date of " + rTs.getDate()
2982
2987
                                        + " does not match " + ts.getDate(),
2983
2988
                                        rTs.getDate() == ts.getDate());
 
2989
 
 
2990
                        this.stmt.executeUpdate("DROP TABLE IF EXISTS testTimestampNPE");
 
2991
 
2984
2992
                } finally {
2985
2993
                }
2986
2994
        }
3261
3269
                                                try {
3262
3270
                                                        sleep(timeout);
3263
3271
                                                        toBeKilledConn.close();
3264
 
                                                } catch (Throwable t) {
 
3272
                                                } catch (Throwable thr) {
3265
3273
 
3266
3274
                                                }
3267
3275
                                        }
4345
4353
 
4346
4354
                        this.rs.next();
4347
4355
 
4348
 
                        java.util.Date date1 = new Date(this.rs.getTimestamp(2).getTime());
 
4356
                        //java.util.Date date1 = new Date(this.rs.getTimestamp(2).getTime());
4349
4357
                        Timestamp ts1 = this.rs.getTimestamp(3);
4350
4358
                        long datetimeSeconds1 = rs.getLong(4) * 1000;
4351
4359
                        long timestampSeconds1 = rs.getLong(5) * 1000;
4352
4360
 
4353
4361
                        this.rs.next();
4354
4362
 
4355
 
                        java.util.Date date2 = new Date(this.rs.getTimestamp(2).getTime());
 
4363
                        //java.util.Date date2 = new Date(this.rs.getTimestamp(2).getTime());
4356
4364
                        Timestamp ts2 = this.rs.getTimestamp(3);
4357
4365
                        long datetimeSeconds2 = rs.getLong(4) * 1000;
4358
4366
                        long timestampSeconds2 = rs.getLong(5) * 1000;
4440
4448
 
4441
4449
                Boolean minBooleanVal;
4442
4450
                Boolean oRetVal;
4443
 
                ResultSet rs;
4444
4451
                String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
4445
 
                String sMaxBooleanVal = "1";
4446
 
                // sMaxBooleanVal = "true";
4447
 
                Boolean bool = Boolean.valueOf("true");
4448
4452
                String Min_Insert = "insert into Bit_Tab values(1,0,null)";
4449
4453
                // System.out.println("Value to insert=" + extractVal(Min_Insert,1));
4450
4454
                CallableStatement cstmt;
4451
4455
 
4452
 
                stmt.executeUpdate("delete from Bit_Tab");
4453
 
                stmt.executeUpdate(Min_Insert);
4454
 
                cstmt = conn.prepareCall("{call Bit_Proc(?,?,?)}");
 
4456
                this.stmt.executeUpdate("delete from Bit_Tab");
 
4457
                this.stmt.executeUpdate(Min_Insert);
 
4458
                cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");
4455
4459
 
4456
4460
                cstmt.registerOutParameter(1, java.sql.Types.BIT);
4457
4461
                cstmt.registerOutParameter(2, java.sql.Types.BIT);
4462
4466
                boolean bRetVal = cstmt.getBoolean(2);
4463
4467
                oRetVal = new Boolean(bRetVal);
4464
4468
                minBooleanVal = new Boolean("false");
4465
 
                rs = stmt.executeQuery(Min_Val_Query);
 
4469
                this.rs = this.stmt.executeQuery(Min_Val_Query);
4466
4470
                assertEquals(minBooleanVal, oRetVal);
4467
4471
        }
4468
4472
 
4498
4502
                                return null;
4499
4503
                        }
4500
4504
 
4501
 
                        public Object getObjectStoredProc(int i, Map map, int desiredSqlType)
 
4505
                        public Object getObjectStoredProc(int i, Map<Object, Object> map, int desiredSqlType)
4502
4506
                                        throws SQLException {
4503
4507
 
4504
4508
                                return null;
4510
4514
                                return null;
4511
4515
                        }
4512
4516
 
4513
 
                        public Object getObjectStoredProc(String colName, Map map,
 
4517
                        public Object getObjectStoredProc(String colName, Map<Object, Object> map,
4514
4518
                                        int desiredSqlType) throws SQLException {
4515
4519
 
4516
4520
                                return null;
4832
4836
                                return null;
4833
4837
                        }
4834
4838
 
4835
 
                        public Object getObject(int arg0, Map arg1) throws SQLException {
 
4839
                        public Object getObject(int arg0, Map<String,Class<?>> arg1) throws SQLException {
4836
4840
 
4837
4841
                                return null;
4838
4842
                        }
4839
4843
 
4840
 
                        public Object getObject(String arg0, Map arg1) throws SQLException {
 
4844
                        public Object getObject(String arg0, Map<String,Class<?>> arg1) throws SQLException {
4841
4845
 
4842
4846
                                return null;
4843
4847
                        }
5268
5272
                        public int getBytesSize() throws SQLException {
5269
5273
                                return 0;
5270
5274
                        }
5271
 
                };
 
5275
 
 
5276
            public java.sql.RowId getRowId(int columnIndex) throws SQLException {
 
5277
                return null;
 
5278
            }
 
5279
 
 
5280
            public java.sql.RowId getRowId(String columnLabel) throws SQLException {
 
5281
                return null;
 
5282
            }
 
5283
 
 
5284
            public void updateRowId(int columnIndex, java.sql.RowId x) throws SQLException {
 
5285
            }
 
5286
 
 
5287
            public void updateRowId(String columnLabel, java.sql.RowId x) throws SQLException {
 
5288
            }
 
5289
 
 
5290
            public int getHoldability() throws SQLException {
 
5291
                return 0;
 
5292
            }
 
5293
 
 
5294
            public boolean isClosed() throws SQLException {
 
5295
                return false;
 
5296
            }
 
5297
 
 
5298
            public void updateNString(int columnIndex, String nString) throws SQLException {
 
5299
            }
 
5300
 
 
5301
            public void updateNString(String columnLabel, String nString) throws SQLException {
 
5302
            }
 
5303
 
 
5304
            public void updateNClob(int columnIndex, java.sql.NClob nClob) throws SQLException {
 
5305
            }
 
5306
 
 
5307
            public void updateNClob(String columnLabel, java.sql.NClob nClob) throws SQLException {
 
5308
            }
 
5309
 
 
5310
            public java.sql.NClob getNClob(int columnIndex) throws SQLException {
 
5311
                return null;
 
5312
            }
 
5313
 
 
5314
            public java.sql.NClob getNClob(String columnLabel) throws SQLException {
 
5315
                return null;
 
5316
            }
 
5317
 
 
5318
            public java.sql.SQLXML getSQLXML(int columnIndex) throws SQLException {
 
5319
                return null;
 
5320
            }
 
5321
 
 
5322
            public java.sql.SQLXML getSQLXML(String columnLabel) throws SQLException {
 
5323
                return null;
 
5324
            }
 
5325
 
 
5326
            public void updateSQLXML(int columnIndex, java.sql.SQLXML xmlObject) throws SQLException {
 
5327
            }
 
5328
 
 
5329
            public void updateSQLXML(String columnLabel, java.sql.SQLXML xmlObject) throws SQLException {
 
5330
            }
 
5331
 
 
5332
            public String getNString(int columnIndex) throws SQLException {
 
5333
                return null;
 
5334
            }
 
5335
 
 
5336
            public String getNString(String columnLabel) throws SQLException {
 
5337
                return null;
 
5338
            }
 
5339
 
 
5340
            public Reader getNCharacterStream(int columnIndex) throws SQLException {
 
5341
                return null;
 
5342
            }
 
5343
 
 
5344
            public Reader getNCharacterStream(String columnLabel) throws SQLException {
 
5345
                return null;
 
5346
            }
 
5347
 
 
5348
            public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
 
5349
            }
 
5350
 
 
5351
            public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
 
5352
            }
 
5353
 
 
5354
            public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
 
5355
            }
 
5356
 
 
5357
            public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
 
5358
            }
 
5359
 
 
5360
            public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
 
5361
            }
 
5362
 
 
5363
            public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
 
5364
            }
 
5365
 
 
5366
            public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
 
5367
            }
 
5368
 
 
5369
            public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
 
5370
            }
 
5371
 
 
5372
            public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
 
5373
            }
 
5374
 
 
5375
            public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
 
5376
            }
 
5377
 
 
5378
            public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
 
5379
            }
 
5380
 
 
5381
            public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
 
5382
            }
 
5383
 
 
5384
            public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
 
5385
              
 
5386
            }
 
5387
 
 
5388
            public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
 
5389
            }
 
5390
 
 
5391
            public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
 
5392
            }
 
5393
 
 
5394
            public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
 
5395
            }
 
5396
 
 
5397
            public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
 
5398
            }
 
5399
 
 
5400
            public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
 
5401
            }
 
5402
 
 
5403
            public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
 
5404
            }
 
5405
 
 
5406
            public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
 
5407
            }
 
5408
 
 
5409
            public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
 
5410
            }
 
5411
 
 
5412
            public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
 
5413
            }
 
5414
 
 
5415
            public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
 
5416
            }
 
5417
 
 
5418
            public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
 
5419
            }
 
5420
 
 
5421
            public void updateClob(int columnIndex, Reader reader) throws SQLException {
 
5422
            }
 
5423
 
 
5424
            public void updateClob(String columnLabel, Reader reader) throws SQLException {
 
5425
            }
 
5426
 
 
5427
            public void updateNClob(int columnIndex, Reader reader) throws SQLException {
 
5428
            }
 
5429
 
 
5430
            public void updateNClob(String columnLabel, Reader reader) throws SQLException {
 
5431
            }
 
5432
 
 
5433
            public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
 
5434
                return null;
 
5435
            }
 
5436
 
 
5437
            public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
 
5438
                return null;
 
5439
            }
 
5440
 
 
5441
            public <T> T unwrap(Class<T> iface) throws SQLException {
 
5442
                return null;
 
5443
            }
 
5444
 
 
5445
            public boolean isWrapperFor(Class<?> iface) throws SQLException {
 
5446
                return false;
 
5447
            }
 
5448
        };
5272
5449
        }
5273
5450
 
5274
5451
        /**
5336
5513
                                createTable("testBug30493", ddl);
5337
5514
                                this.stmt.executeUpdate(tablePrimeSql);
5338
5515
                                int expectedUpdateCount = versionMeetsMinimum(5, 1, 0) ? 2 : 1;
 
5516
 
 
5517
                                // TODO: check server bug#13904273, bug#14598395 to find last affected version
 
5518
                                if (versionMeetsMinimum(5, 5, 16)) {
 
5519
                                        expectedUpdateCount = 1;
 
5520
                                }
 
5521
 
5339
5522
                                int rwUpdateCounts[] = testStmts[1].executeBatch();
5340
5523
                                ResultSet rewrittenRsKeys = testStmts[1].getGeneratedKeys();
5341
5524
                                for (int i = 0; i < 4; ++i) {
5375
5558
                        }
5376
5559
                        stmt.executeUpdate(tablePrimeSql);
5377
5560
 
5378
 
                        stmt.execute(sql, Statement.RETURN_GENERATED_KEYS);
 
5561
                        Statement stmt1 = conn.createStatement();
 
5562
                        stmt1.execute(sql, Statement.RETURN_GENERATED_KEYS);
5379
5563
                        int expectedUpdateCount = versionMeetsMinimum(5, 1, 0) ? 2 : 1;
5380
5564
 
5381
 
                        assertEquals(expectedUpdateCount, stmt.getUpdateCount());
5382
 
                        ResultSet stmtKeys = stmt.getGeneratedKeys();
 
5565
                        // TODO: check server bug#13904273, bug#14598395 to find last affected version
 
5566
                        if (versionMeetsMinimum(5, 5, 16)) {
 
5567
                                expectedUpdateCount = 1;
 
5568
                        }
 
5569
 
 
5570
                        assertEquals(expectedUpdateCount, stmt1.getUpdateCount());
 
5571
                        ResultSet stmtKeys = stmt1.getGeneratedKeys();
5383
5572
                        assertResultSetLength(stmtKeys, 1);
5384
5573
 
5385
5574
                        try {
6054
6243
 
6055
6244
                        if (this.rs.next()) {
6056
6245
 
6057
 
                                Long id = (Long) this.rs.getObject(1);// use long
 
6246
                                Object id = this.rs.getObject(1);// use long
6058
6247
 
 
6248
                                assertEquals(Long.class, id.getClass());
6059
6249
                        }
6060
6250
 
6061
6251
                        this.rs.close();
6063
6253
                        this.rs = this.stmt.executeQuery("select id from bug43196");
6064
6254
 
6065
6255
                        if (this.rs.next()) {
6066
 
                                BigInteger id = (BigInteger) this.rs.getObject(1);// use
6067
 
                                                                                                                                        // BigInteger
 
6256
                                Object id = this.rs.getObject(1);// use BigInteger
 
6257
 
 
6258
                                assertEquals(BigInteger.class, id.getClass());
6068
6259
                        }
6069
6260
 
6070
6261
                        this.rs.close();
6140
6331
        }
6141
6332
 
6142
6333
        public static class Bug39426Interceptor implements StatementInterceptor {
6143
 
                public static List vals = new ArrayList();
 
6334
                public static List<Integer> vals = new ArrayList<Integer>();
6144
6335
                String prevSql;
6145
6336
 
6146
6337
                public void destroy() {
6201
6392
                        ps.setInt(1, 3);
6202
6393
                        ps.addBatch();
6203
6394
                        ps.executeBatch();
6204
 
                        List vals = Bug39426Interceptor.vals;
 
6395
                        List<Integer> vals = Bug39426Interceptor.vals;
6205
6396
                        assertEquals(new Integer(1), vals.get(0));
6206
6397
                        assertEquals(new Integer(2), vals.get(1));
6207
6398
                        assertEquals(new Integer(3), vals.get(2));
6355
6546
                createTable("testStatementInterceptorCount", "(field1 int)");
6356
6547
                this.stmt
6357
6548
                                .executeUpdate("INSERT INTO testStatementInterceptorCount VALUES (0)");
6358
 
                ResultSet rs = testConn.createStatement().executeQuery(
 
6549
                ResultSet testRs = testConn.createStatement().executeQuery(
6359
6550
                                "SHOW SESSION STATUS LIKE 'Com_select'");
6360
 
                rs.next();
6361
 
                int s = rs.getInt(2);
 
6551
                testRs.next();
 
6552
                int s = testRs.getInt(2);
6362
6553
                testConn.createStatement().executeQuery("SELECT 1");
6363
 
                rs = testConn.createStatement().executeQuery(
 
6554
                testRs = testConn.createStatement().executeQuery(
6364
6555
                                "SHOW SESSION STATUS LIKE 'Com_select'");
6365
 
                rs.next();
6366
 
                assertEquals(s + 1, rs.getInt(2));
 
6556
                testRs.next();
 
6557
                assertEquals(s + 1, testRs.getInt(2));
6367
6558
 
6368
6559
        }
6369
6560
 
6565
6756
                        rs1.close();
6566
6757
                }
6567
6758
        }
 
6759
        
 
6760
        public void testBug61501() throws Exception {
 
6761
                createTable("testBug61501", "(id int)");
 
6762
                stmt.executeUpdate("INSERT INTO testBug61501 VALUES (1)");
 
6763
                String sql = "SELECT id FROM testBug61501 where id=1";
 
6764
                pstmt = conn.prepareStatement(sql);
 
6765
                pstmt.executeQuery();
 
6766
                pstmt.cancel();
 
6767
                pstmt.close();
 
6768
                
 
6769
                pstmt = conn.prepareStatement(sql);
 
6770
                rs = pstmt.executeQuery();
 
6771
                
 
6772
                stmt.cancel();
 
6773
                stmt.executeQuery(sql);
 
6774
                stmt.cancel();
 
6775
                stmt.execute(sql);
 
6776
                pstmt = ((com.mysql.jdbc.Connection) conn).serverPrepareStatement(sql);
 
6777
                pstmt.execute();
 
6778
                pstmt.cancel();
 
6779
                pstmt.execute();
 
6780
                
 
6781
                sql = "INSERT INTO testBug61501 VALUES (2)";
 
6782
                pstmt = conn.prepareStatement(sql);
 
6783
                pstmt.execute();
 
6784
                assertEquals(1, pstmt.getUpdateCount());
 
6785
                pstmt.cancel();
 
6786
                pstmt.close();
 
6787
                
 
6788
                pstmt = conn.prepareStatement(sql);
 
6789
                assertEquals(1, pstmt.executeUpdate());
 
6790
                
 
6791
                stmt.cancel();
 
6792
                assertEquals(1, stmt.executeUpdate(sql));
 
6793
                stmt.cancel();
 
6794
                stmt.execute(sql);
 
6795
                assertEquals(1, stmt.getUpdateCount());
 
6796
                
 
6797
                pstmt = ((com.mysql.jdbc.Connection) conn).serverPrepareStatement(sql);
 
6798
                pstmt.execute();
 
6799
                assertEquals(1, pstmt.getUpdateCount());
 
6800
                pstmt.cancel();
 
6801
                pstmt.close();
 
6802
                
 
6803
                pstmt = ((com.mysql.jdbc.Connection) conn).serverPrepareStatement(sql);
 
6804
                assertEquals(1, pstmt.executeUpdate());
 
6805
                
 
6806
                pstmt.cancel();
 
6807
                pstmt.addBatch();
 
6808
                pstmt.addBatch();
 
6809
                pstmt.addBatch();
 
6810
                int[] counts = pstmt.executeBatch();
 
6811
                
 
6812
                for (int i = 0; i < counts.length; i++) {
 
6813
                        assertEquals(1, counts[i]);
 
6814
                }
 
6815
                
 
6816
                pstmt = conn.prepareStatement(sql);
 
6817
                pstmt.cancel();
 
6818
                pstmt.addBatch();
 
6819
                pstmt.addBatch();
 
6820
                pstmt.addBatch();
 
6821
                counts = pstmt.executeBatch();
 
6822
                
 
6823
                for (int i = 0; i < counts.length; i++) {
 
6824
                        assertEquals(1, counts[i]);
 
6825
                }
 
6826
                
 
6827
                stmt.cancel();
 
6828
                stmt.addBatch(sql);
 
6829
                stmt.addBatch(sql);
 
6830
                stmt.addBatch(sql);
 
6831
 
 
6832
                counts = stmt.executeBatch();
 
6833
                
 
6834
                for (int i = 0; i < counts.length; i++) {
 
6835
                        assertEquals(1, counts[i]);
 
6836
                }
 
6837
                
 
6838
                
 
6839
        }
 
6840
        
 
6841
        public void testbug61866() throws Exception {
 
6842
                        
 
6843
                        createProcedure("WARN_PROCEDURE", "() BEGIN     DECLARE l_done INT;     SELECT 1        INTO l_done     FROM DUAL       WHERE 1=2; END");
 
6844
                        this.pstmt = this.conn.prepareCall("{CALL WARN_PROCEDURE()}");
 
6845
                        this.pstmt.execute();
 
6846
                        assertTrue("No warning when expected", this.pstmt.getWarnings().toString().contentEquals("java.sql.SQLWarning: No data - zero rows fetched, selected, or processed"));
 
6847
                        this.pstmt.clearWarnings();
 
6848
                        assertNull("Warning when not expected", this.pstmt.getWarnings());
 
6849
        }
 
6850
        
 
6851
        public void testbug12565726() throws Exception {
 
6852
                // Not putting the space between VALUES() and ON DUPLICATE KEY UPDATE
 
6853
                // causes C/J a) enter rewriting the query altrhough it has ON UPDATE 
 
6854
                // and b) to generate the wrong query with multiple ON DUPLICATE KEY
 
6855
 
 
6856
                Properties props = new Properties();
 
6857
        props.put("rewriteBatchedStatements","true");
 
6858
        props.put("useServerPrepStmts","false");
 
6859
        props.put("enablePacketDebug","true");
 
6860
                this.conn = getConnectionWithProps(props);
 
6861
                this.stmt = this.conn.createStatement();
 
6862
                
 
6863
                try {
 
6864
                        createTable("testbug12565726", "(id int primary key, txt1 varchar(32))");
 
6865
            this.stmt.executeUpdate("INSERT INTO testbug12565726 " +
 
6866
                "(id, txt1) VALUES (1, 'something')");
 
6867
                        
 
6868
 
 
6869
            this.pstmt = this.conn.prepareStatement("INSERT INTO " +
 
6870
                    "testbug12565726 (id, txt1) " +
 
6871
                    "VALUES (?, ?)ON DUPLICATE KEY UPDATE " +
 
6872
                    "id=LAST_INSERT_ID(id)+10");            
 
6873
            
 
6874
            this.pstmt.setInt(1, 1);
 
6875
            this.pstmt.setString(2, "something else");
 
6876
            this.pstmt.addBatch();
 
6877
            
 
6878
            this.pstmt.setInt(1, 2);
 
6879
            this.pstmt.setString(2, "hope it is not error again!");
 
6880
            this.pstmt.addBatch();
 
6881
 
 
6882
            this.pstmt.executeBatch();
 
6883
                        
 
6884
                } finally {
 
6885
                }
 
6886
                
 
6887
        }
 
6888
 
 
6889
        public void testBug36478() throws Exception {
 
6890
 
 
6891
                createTable("testBug36478", "(`limit` varchar(255) not null primary key, id_limit INT, limit1 INT, maxlimit2 INT)");
 
6892
                
 
6893
                this.stmt.execute("INSERT INTO testBug36478 VALUES ('bahblah',1,1,1)");
 
6894
                this.stmt.execute("INSERT INTO testBug36478 VALUES ('bahblah2',2,2,2)");
 
6895
                this.pstmt = this.conn.prepareStatement("select 1 FROM testBug36478");
 
6896
 
 
6897
                this.pstmt.setMaxRows(1);
 
6898
                this.rs = this.pstmt.executeQuery();
 
6899
                this.rs.first();
 
6900
                assertTrue(this.rs.isFirst());
 
6901
                assertTrue(this.rs.isLast());
 
6902
 
 
6903
                this.pstmt = this.conn.prepareStatement("select `limit`, id_limit, limit1, maxlimit2 FROM testBug36478");
 
6904
                this.pstmt.setMaxRows(0);
 
6905
                this.rs = this.pstmt.executeQuery();
 
6906
                this.rs.first();
 
6907
                assertTrue(this.rs.isFirst());
 
6908
                assertFalse(this.rs.isLast());          
 
6909
                
 
6910
                //SSPS
 
6911
                Connection _conn = null;
 
6912
                PreparedStatement s = null;
 
6913
                try {
 
6914
                        Properties props = new Properties();
 
6915
                        props.setProperty("useServerPrepStmts", "true");
 
6916
 
 
6917
                        _conn = getConnectionWithProps(props);
 
6918
                        s = _conn.prepareStatement("select 1 FROM testBug36478");
 
6919
 
 
6920
                        s.setMaxRows(1);
 
6921
                        ResultSet _rs = s.executeQuery();
 
6922
                        _rs.first();
 
6923
                        assertTrue(_rs.isFirst());
 
6924
                        assertTrue(_rs.isLast());
 
6925
 
 
6926
                        s = _conn.prepareStatement("select `limit`, id_limit, limit1, maxlimit2 FROM testBug36478");
 
6927
                        s.setMaxRows(0);
 
6928
                        _rs = s.executeQuery();
 
6929
                        _rs.first();
 
6930
                        assertTrue(_rs.isFirst());
 
6931
                        assertFalse(_rs.isLast());              
 
6932
                        
 
6933
                } finally {
 
6934
                        if (s != null) {
 
6935
                                s.close();
 
6936
                        }
 
6937
                        if (_conn != null) {
 
6938
                                _conn.close();
 
6939
                        }
 
6940
                }
 
6941
                
 
6942
        }
 
6943
 
 
6944
        /**
 
6945
         * Tests fix for BUG#40279 - Timestamp values get truncated when passed as prepared statement parameters
 
6946
         * (and duplicate BUG#60584 - prepared statements truncate milliseconds)
 
6947
         * 
 
6948
         *  [13 Sep 2012 21:06] Mark Matthews
 
6949
         *  This was fixed with http://bazaar.launchpad.net/~mysql/connectorj/5.1/revision/1107 in 2011,
 
6950
         *  it supports MySQL-5.6.4 or later.
 
6951
         *  
 
6952
         *  But that fix did not cover useLegacyDatetimeCode=true case.
 
6953
         * 
 
6954
         * @throws Exception
 
6955
         */
 
6956
        public void testBug40279() throws Exception {
 
6957
                if (!versionMeetsMinimum(5, 6, 4)) {
 
6958
                        return;
 
6959
                }
 
6960
                
 
6961
                createTable("testBug40279", "(f1 int, f2 timestamp(6))");
 
6962
 
 
6963
                Timestamp ts = new Timestamp(1300791248001L);
 
6964
 
 
6965
                Connection ps_conn_legacy = null;
 
6966
                Connection ps_conn_nolegacy = null;
 
6967
 
 
6968
                Connection ssps_conn_legacy = null;
 
6969
                Connection ssps_conn_nolegacy = null;
 
6970
 
 
6971
                try {
 
6972
                        Properties props = new Properties();
 
6973
                        props.setProperty("serverTimezone", "UTC");
 
6974
                        props.setProperty("useLegacyDatetimeCode", "true");
 
6975
                        props.setProperty("useServerPrepStmts", "false");
 
6976
                        ps_conn_legacy = getConnectionWithProps(props);
 
6977
                        
 
6978
                        props.setProperty("useLegacyDatetimeCode", "false");
 
6979
                        ps_conn_nolegacy = getConnectionWithProps(props);
 
6980
                        
 
6981
                        props.setProperty("useLegacyDatetimeCode", "true");
 
6982
                        props.setProperty("useServerPrepStmts", "true");
 
6983
                        ssps_conn_legacy = getConnectionWithProps(props);
 
6984
 
 
6985
                        props.setProperty("useLegacyDatetimeCode", "false");
 
6986
                        ssps_conn_nolegacy = getConnectionWithProps(props);
 
6987
 
 
6988
                        this.pstmt = ps_conn_legacy.prepareStatement("INSERT INTO testBug40279(f1, f2) VALUES (?, ?)");
 
6989
                        this.pstmt.setInt(1, 1);
 
6990
                        this.pstmt.setTimestamp(2, ts);
 
6991
                        this.pstmt.execute();
 
6992
                        this.pstmt.close();
 
6993
 
 
6994
                        this.pstmt = ps_conn_nolegacy.prepareStatement("INSERT INTO testBug40279(f1, f2) VALUES (?, ?)");
 
6995
                        this.pstmt.setInt(1, 2);
 
6996
                        this.pstmt.setTimestamp(2, ts);
 
6997
                        this.pstmt.execute();
 
6998
                        this.pstmt.close();
 
6999
 
 
7000
                        this.pstmt = ssps_conn_legacy.prepareStatement("INSERT INTO testBug40279(f1, f2) VALUES (?, ?)");
 
7001
                        this.pstmt.setInt(1, 3);
 
7002
                        this.pstmt.setTimestamp(2, ts);
 
7003
                        this.pstmt.execute();
 
7004
                        this.pstmt.close();
 
7005
 
 
7006
                        this.pstmt = ssps_conn_nolegacy.prepareStatement("INSERT INTO testBug40279(f1, f2) VALUES (?, ?)");
 
7007
                        this.pstmt.setInt(1, 4);
 
7008
                        this.pstmt.setTimestamp(2, ts);
 
7009
                        this.pstmt.execute();
 
7010
                        this.pstmt.close();
 
7011
 
 
7012
                        this.rs = this.stmt.executeQuery("SELECT f2 FROM testBug40279");
 
7013
                        while (this.rs.next()) {
 
7014
                                assertEquals(ts.getNanos(), this.rs.getTimestamp("f2").getNanos());
 
7015
                        }
 
7016
                        
 
7017
                } finally {
 
7018
                        if (ps_conn_legacy != null) {
 
7019
                                ps_conn_legacy.close();
 
7020
                        }
 
7021
                        if (ps_conn_nolegacy != null) {
 
7022
                                ps_conn_nolegacy.close();
 
7023
                        }
 
7024
                        if (ssps_conn_legacy != null) {
 
7025
                                ssps_conn_legacy.close();
 
7026
                        }
 
7027
                        if (ssps_conn_nolegacy != null) {
 
7028
                                ssps_conn_nolegacy.close();
 
7029
                        }
 
7030
                }
 
7031
        
 
7032
        }
 
7033
 
 
7034
        /**
 
7035
         * Tests fix for BUG#35653 - executeQuery() in Statement.java let "TRUNCATE" queries being executed.
 
7036
         * "RENAME" is also filtered now.
 
7037
         * 
 
7038
         * @throws Exception
 
7039
         */
 
7040
        public void testBug35653() throws Exception {
 
7041
                createTable("testBug35653", "(f1 int)");
 
7042
                try {
 
7043
                        this.stmt.executeQuery("TRUNCATE testBug35653");
 
7044
                        fail("executeQuery() shouldn't allow TRUNCATE");
 
7045
                } catch (SQLException e) {
 
7046
                        assertTrue(SQLError.SQL_STATE_ILLEGAL_ARGUMENT == e.getSQLState());
 
7047
                }
 
7048
 
 
7049
                try {
 
7050
                        this.stmt.executeQuery("RENAME TABLE testBug35653 TO testBug35653_new");
 
7051
                        fail("executeQuery() shouldn't allow RENAME");
 
7052
                } catch (SQLException e) {
 
7053
                        assertTrue(SQLError.SQL_STATE_ILLEGAL_ARGUMENT == e.getSQLState());
 
7054
                } finally {
 
7055
                        dropTable("testBug35653_new");
 
7056
                }
 
7057
        }
 
7058
 
 
7059
        /**
 
7060
         * Tests fix for BUG#64805 - StatementImpl$CancelTask occasionally throws NullPointerExceptions.
 
7061
         * 
 
7062
         * @throws Exception
 
7063
         */
 
7064
        public void testBug64805() throws Exception {
 
7065
 
 
7066
                try {
 
7067
                        this.stmt.setQueryTimeout(5);
 
7068
                        this.stmt.executeQuery("select sleep(5)");
 
7069
                } catch (NullPointerException e) {
 
7070
                        e.printStackTrace();
 
7071
                        fail();
 
7072
                } catch (Exception e) {
 
7073
                        if (e instanceof MySQLTimeoutException) {
 
7074
                                // expected behavior in slow environment
 
7075
                        } else {
 
7076
                                throw e;
 
7077
                        }
 
7078
                }
 
7079
 
 
7080
        }
 
7081
 
6568
7082
}