Search in sources :

Example 1 with MysqlSQLXML

use of com.mysql.cj.jdbc.MysqlSQLXML in project aws-mysql-jdbc by awslabs.

the class ResultSetRegressionTest method tstBug24525461testBytes.

private void tstBug24525461testBytes(Properties props, boolean testJSON, Statement st) throws Exception {
    st.executeUpdate("truncate table testBug24525461");
    String fGeomFromText = versionMeetsMinimum(5, 6, 1) ? "ST_GeomFromText" : "GeomFromText";
    StringBuilder sb = new StringBuilder("INSERT INTO testBug24525461 values(0, 1, 1, 1, 1, 1, 1, 1, '2000-01-01 00:00:00', 1, 1, '2000-01-01', '12:00:00', '2000-01-01 00:00:00', 2000, 'aaa'," + " 1, 1, 'x', 'a', 1, '1', 1 , '1', 1, '1', 1, '1', '1', 1, " + fGeomFromText + "('POINT(1 1)'), " + fGeomFromText + "('POINT(2 2)')," + " _utf8 'aaa', _utf8 'aaa', 'aaa', 'aaa', 1, 1, 'aaa', 'aaa', 'aaa', _utf8 'aaa', _utf8 'aaa', '1', null");
    if (testJSON) {
        sb.append(", '{\"key1\": \"value1\"}'");
    }
    sb.append(")");
    st.executeUpdate(sb.toString());
    System.out.println(" with params = " + props);
    Connection con = getConnectionWithProps(props);
    PreparedStatement testPstmt = con.prepareStatement("SELECT * FROM testBug24525461", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
    ResultSet rs1 = testPstmt.executeQuery();
    assertTrue(rs1.next());
    // check that other fields are refreshed properly
    rs1.updateInt(2, 10);
    rs1.updateRow();
    tstBug24525461assertResults1(testJSON, st);
    // check that all fields are set as expected
    Calendar cal = Calendar.getInstance();
    cal.set(2002, 01, 02, 10, 30, 0);
    cal.set(Calendar.MILLISECOND, 0);
    rs1.updateBigDecimal(2, BigDecimal.valueOf(20));
    rs1.updateInt(3, 2);
    rs1.updateBoolean(4, false);
    rs1.updateShort(5, (short) 2);
    rs1.updateInt(6, 2);
    rs1.updateFloat(7, 2);
    rs1.updateDouble(8, 2);
    // f08 TIMESTAMP
    rs1.updateTimestamp(9, new Timestamp(cal.getTimeInMillis()));
    rs1.updateLong(10, 2L);
    rs1.updateInt(11, 2);
    // f11 DATE
    rs1.updateDate(12, new Date(cal.getTimeInMillis()));
    // f12 TIME
    rs1.updateTime(13, new Time(cal.getTimeInMillis()));
    // f13 DATETIME
    rs1.updateTimestamp(14, new Timestamp(cal.getTimeInMillis()));
    // f14 YEAR
    rs1.updateInt(15, 2002);
    rs1.updateNString(16, "bbb");
    // f16 VARBINARY(30)
    rs1.updateBytes(17, new byte[] { 50 });
    // f17 BIT
    rs1.updateByte(18, (byte) 0);
    rs1.updateString(19, "y");
    rs1.updateString(20, "b");
    rs1.updateBlob(21, new com.mysql.cj.jdbc.Blob("2".getBytes(), null));
    rs1.updateClob(22, new com.mysql.cj.jdbc.Clob("2", null));
    rs1.updateBlob(23, new ByteArrayInputStream(new byte[] { 50 }));
    rs1.updateClob(24, new StringReader("2"));
    rs1.updateBlob(25, new ByteArrayInputStream(new byte[] { 50, 51, 52 }), 1);
    rs1.updateClob(26, new StringReader("2222"), 1);
    rs1.updateObject(27, "2", MysqlType.BLOB);
    rs1.updateNClob(28, new com.mysql.cj.jdbc.NClob("2", null));
    rs1.updateString(29, "2");
    rs1.updateBytes(30, new byte[] { 50 });
    Object p1 = rs1.getObject(31);
    Object p2 = rs1.getObject(32);
    rs1.updateObject(31, p2);
    rs1.updateObject(32, p1);
    rs1.updateNClob(33, new StringReader("bbb"));
    rs1.updateNClob(34, new StringReader("bbbbbb"), 3);
    rs1.updateAsciiStream(35, new ByteArrayInputStream("bbb".getBytes()));
    rs1.updateAsciiStream(36, new ByteArrayInputStream("bbbbbb".getBytes()), 3);
    rs1.updateBinaryStream(37, new ByteArrayInputStream(new byte[] { 50 }));
    rs1.updateBinaryStream(38, new ByteArrayInputStream(new byte[] { 50, 51, 52 }), 1);
    rs1.updateCharacterStream(39, new StringReader("bbb"));
    rs1.updateCharacterStream(40, new StringReader("bbbbbb"), 3);
    rs1.updateCharacterStream(41, new StringReader("bbbbbb"), 3L);
    rs1.updateNCharacterStream(42, new StringReader("bbb"));
    rs1.updateNCharacterStream(43, new StringReader("bbbbbb"), 3);
    rs1.updateNull(44);
    SQLXML xml = new MysqlSQLXML(null, new JdbcPropertySetImpl());
    xml.setString("<doc/>");
    rs1.updateSQLXML(45, xml);
    if (testJSON) {
        // f18 JSON
        rs1.updateObject(46, "{\"key2\": \"value2\"}");
    }
    rs1.updateRow();
    tstBug24525461assertResults2(testJSON, st);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Time(java.sql.Time) ZonedDateTime(java.time.ZonedDateTime) LocalTime(java.time.LocalTime) OffsetTime(java.time.OffsetTime) OffsetDateTime(java.time.OffsetDateTime) LocalDateTime(java.time.LocalDateTime) Timestamp(java.sql.Timestamp) InternalDate(com.mysql.cj.protocol.InternalDate) LocalDate(java.time.LocalDate) Date(java.sql.Date) SQLXML(java.sql.SQLXML) MysqlSQLXML(com.mysql.cj.jdbc.MysqlSQLXML) MysqlSQLXML(com.mysql.cj.jdbc.MysqlSQLXML) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) UpdatableResultSet(com.mysql.cj.jdbc.result.UpdatableResultSet) StringReader(java.io.StringReader) JdbcPropertySetImpl(com.mysql.cj.jdbc.JdbcPropertySetImpl)

Aggregations

MysqlConnection (com.mysql.cj.MysqlConnection)1 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)1 JdbcPropertySetImpl (com.mysql.cj.jdbc.JdbcPropertySetImpl)1 MysqlSQLXML (com.mysql.cj.jdbc.MysqlSQLXML)1 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)1 UpdatableResultSet (com.mysql.cj.jdbc.result.UpdatableResultSet)1 InternalDate (com.mysql.cj.protocol.InternalDate)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 Connection (java.sql.Connection)1 Date (java.sql.Date)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLXML (java.sql.SQLXML)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1