Search in sources :

Example 6 with SQLServerDataTable

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

the class TVPSchemaTest method testSetup.

@BeforeEach
private void testSetup() throws SQLException {
    conn = new DBConnection(connectionString);
    stmt = conn.createStatement();
    dropProcedure();
    dropTables();
    dropTVPS();
    dropAndCreateSchema();
    createTVPS();
    createTables();
    createPreocedure();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("PlainChar", java.sql.Types.CHAR);
    tvp.addColumnMetadata("PlainVarchar", java.sql.Types.VARCHAR);
    tvp.addColumnMetadata("PlainVarcharMax", java.sql.Types.VARCHAR);
    tvp.addRow(expectecValue1, expectecValue2, expectecValue3);
    tvp.addRow(expectecValue1, expectecValue2, expectecValue3);
    tvp.addRow(expectecValue1, expectecValue2, expectecValue3);
    tvp.addRow(expectecValue1, expectecValue2, expectecValue3);
    tvp.addRow(expectecValue1, expectecValue2, expectecValue3);
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with SQLServerDataTable

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

the class TVPTypesTest method testTVPLongNVarcharStoredProcedure.

/**
 * LongNVarchar with StoredProcedure
 *
 * @throws SQLException
 */
@Test
public void testTVPLongNVarcharStoredProcedure() throws SQLException {
    createTables("nvarchar(max)");
    createTVPS("nvarchar(max)");
    createPreocedure();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 8001; i++) buffer.append("سس");
    value = buffer.toString();
    tvp = new SQLServerDataTable();
    tvp.addColumnMetadata("c1", java.sql.Types.LONGNVARCHAR);
    tvp.addRow(buffer.toString());
    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 8 with SQLServerDataTable

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

the class TVPTypesTest method testTVPNTextStoredProcedure.

/**
 * Text with StoredProcedure
 *
 * @throws SQLException
 */
@Test
public void testTVPNTextStoredProcedure() throws SQLException {
    createTables("ntext");
    createTVPS("ntext");
    createPreocedure();
    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);
    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 9 with SQLServerDataTable

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

the class TVPTypesTest method testTVPLongVarcharStoredProcedure.

/**
 * LongVarchar with StoredProcedure
 *
 * @throws SQLException
 */
@Test
public void testTVPLongVarcharStoredProcedure() throws SQLException {
    createTables("varchar(max)");
    createTVPS("varchar(max)");
    createPreocedure();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 8001; 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 10 with SQLServerDataTable

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

the class TVPTypesTest method testLongNVarchar.

/**
 * Test longnvarchar
 *
 * @throws SQLException
 */
@Test
public void testLongNVarchar() throws SQLException {
    createTables("nvarchar(max)");
    createTVPS("nvarchar(max)");
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 8001; 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();
    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)

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