Search in sources :

Example 16 with SQLServerDataTable

use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testLongVarchar.

/**
 * Test a longvarchar support
 *
 * @throws SQLException
 */
@Test
public void testLongVarchar() throws SQLException {
    createTables("varchar(max)");
    createTVPS("varchar(max)");
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 9000; i++) buffer.append("a");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGVARCHAR);
    tvp.addRow(value);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
    pstmt.setStructured(1, tvpName, tvp);
    pstmt.execute();
    rs = conn.createStatement().executeQuery("select * from " + table);
    while (rs.next()) {
        assertEquals(rs.getString(1), value);
    }
    if (null != pstmt) {
        pstmt.close();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 17 with SQLServerDataTable

use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testText.

/**
 * Test text support
 *
 * @throws SQLException
 */
@Test
public void testText() throws SQLException {
    createTables("text");
    createTVPS("text");
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 9000; i++) buffer.append("a");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGVARCHAR);
    tvp.addRow(value);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
    pstmt.setStructured(1, tvpName, tvp);
    pstmt.execute();
    Connection con = DriverManager.getConnection(connectionString);
    ResultSet rs = con.createStatement().executeQuery("select * from " + table);
    while (rs.next()) assertEquals(rs.getString(1), value);
    if (null != pstmt) {
        pstmt.close();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ResultSet(java.sql.ResultSet) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 18 with SQLServerDataTable

use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testSmallDateTime.

/**
 * Test a smalldatetime support
 *
 * @throws SQLException
 */
@Test
public void testSmallDateTime() throws SQLException {
    createTables("smalldatetime");
    createTVPS("smalldatetime");
    java.sql.Timestamp value = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.123");
    java.sql.Timestamp returnValue = java.sql.Timestamp.valueOf("2007-09-23 10:10:00.0");
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", microsoft.sql.Types.SMALLDATETIME);
    tvp.addRow(value);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
    pstmt.setStructured(1, tvpName, tvp);
    pstmt.execute();
    rs = conn.createStatement().executeQuery("select * from " + table);
    while (rs.next()) {
        assertEquals(((SQLServerResultSet) rs).getSmallDateTime(1), returnValue);
    }
    if (null != pstmt) {
        pstmt.close();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 19 with SQLServerDataTable

use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testTVPTextStoredProcedure.

/**
 * Text with StoredProcedure
 *
 * @throws SQLException
 */
@Test
public void testTVPTextStoredProcedure() throws SQLException {
    createTables("text");
    createTVPS("text");
    createPreocedure();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 9000; i++) buffer.append("a");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGVARCHAR);
    tvp.addRow(value);
    final String sql = "{call " + procedureName + "(?)}";
    SQLServerCallableStatement P_C_statement = (SQLServerCallableStatement) connection.prepareCall(sql);
    P_C_statement.setStructured(1, tvpName, tvp);
    P_C_statement.execute();
    rs = stmt.executeQuery("select * from " + table);
    while (rs.next()) assertEquals(rs.getString(1), value);
    if (null != P_C_statement) {
        P_C_statement.close();
    }
}
Also used : SQLServerCallableStatement(com.microsoft.sqlserver.jdbc.SQLServerCallableStatement) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 20 with SQLServerDataTable

use of com.microsoft.sqlserver.jdbc.SQLServerDataTable in project mssql-jdbc by Microsoft.

the class TVPTypesTest method testnText.

/**
 * Test ntext support
 *
 * @throws SQLException
 */
@Test
public void testnText() throws SQLException {
    createTables("ntext");
    createTVPS("ntext");
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 9000; i++) buffer.append("س");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGNVARCHAR);
    tvp.addRow(value);
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + table + " select * from ? ;");
    pstmt.setStructured(1, tvpName, tvp);
    pstmt.execute();
    Connection con = DriverManager.getConnection(connectionString);
    ResultSet rs = con.createStatement().executeQuery("select * from " + table);
    while (rs.next()) assertEquals(rs.getString(1), value);
    if (null != pstmt) {
        pstmt.close();
    }
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) Connection(java.sql.Connection) SQLServerResultSet(com.microsoft.sqlserver.jdbc.SQLServerResultSet) ResultSet(java.sql.ResultSet) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Aggregations

SQLServerDataTable (com.microsoft.sqlserver.jdbc.SQLServerDataTable)34 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)33 Test (org.junit.jupiter.api.Test)33 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)13 SQLServerCallableStatement (com.microsoft.sqlserver.jdbc.SQLServerCallableStatement)7 SQLServerResultSet (com.microsoft.sqlserver.jdbc.SQLServerResultSet)4 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)3 SQLTimeoutException (java.sql.SQLTimeoutException)2 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)1 SqlDate (com.microsoft.sqlserver.testframework.sqlType.SqlDate)1 SqlType (com.microsoft.sqlserver.testframework.sqlType.SqlType)1 BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 Random (java.util.Random)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1