Search in sources :

Example 6 with SqlType

use of com.microsoft.sqlserver.testframework.sqlType.SqlType in project mssql-jdbc by Microsoft.

the class TVPAllTypes method testTVPDataTable.

/**
 * Test TVP with DataTable
 *
 * @throws SQLException
 */
@Test
public void testTVPDataTable() throws SQLException {
    setupVariation();
    SQLServerDataTable dt = new SQLServerDataTable();
    int numberOfColumns = tableDest.getColumns().size();
    Object[] values = new Object[numberOfColumns];
    for (int i = 0; i < numberOfColumns; i++) {
        SqlType sqlType = tableDest.getColumns().get(i).getSqlType();
        dt.addColumnMetadata(tableDest.getColumnName(i), sqlType.getJdbctype().getVendorTypeNumber());
        values[i] = sqlType.createdata();
    }
    int numberOfRows = 10;
    for (int i = 0; i < numberOfRows; i++) {
        dt.addRow(values);
    }
    SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) connection.prepareStatement("INSERT INTO " + tableDest.getEscapedTableName() + " select * from ? ;");
    pstmt.setStructured(1, tvpName, dt);
    pstmt.execute();
}
Also used : SQLServerPreparedStatement(com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement) SqlType(com.microsoft.sqlserver.testframework.sqlType.SqlType) SQLServerDataTable(com.microsoft.sqlserver.jdbc.SQLServerDataTable) Test(org.junit.jupiter.api.Test) AbstractTest(com.microsoft.sqlserver.testframework.AbstractTest)

Example 7 with SqlType

use of com.microsoft.sqlserver.testframework.sqlType.SqlType in project mssql-jdbc by Microsoft.

the class lobsTest method createTable.

private static DBTable createTable(DBTable table, String[] types, boolean populateTable) throws Exception {
    DBStatement stmt = new DBConnection(connectionString).createStatement();
    table = new DBTable(false);
    for (String type1 : types) {
        SqlType type = Utils.find(type1);
        table.addColumn(type);
    }
    stmt.createTable(table);
    if (populateTable) {
        stmt.populateTable(table);
    }
    stmt.close();
    return table;
}
Also used : DBConnection(com.microsoft.sqlserver.testframework.DBConnection) DBTable(com.microsoft.sqlserver.testframework.DBTable) DBStatement(com.microsoft.sqlserver.testframework.DBStatement) SqlType(com.microsoft.sqlserver.testframework.sqlType.SqlType)

Aggregations

SqlType (com.microsoft.sqlserver.testframework.sqlType.SqlType)7 DBTable (com.microsoft.sqlserver.testframework.DBTable)3 SQLException (java.sql.SQLException)2 Test (org.junit.jupiter.api.Test)2 SQLServerBulkCopy (com.microsoft.sqlserver.jdbc.SQLServerBulkCopy)1 SQLServerDataTable (com.microsoft.sqlserver.jdbc.SQLServerDataTable)1 SQLServerPreparedStatement (com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement)1 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)1 DBConnection (com.microsoft.sqlserver.testframework.DBConnection)1 DBInvalidUtil (com.microsoft.sqlserver.testframework.DBInvalidUtil)1 DBStatement (com.microsoft.sqlserver.testframework.DBStatement)1 DBBinaryStream (com.microsoft.sqlserver.testframework.Utils.DBBinaryStream)1 DBCharacterStream (com.microsoft.sqlserver.testframework.Utils.DBCharacterStream)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 DisplayName (org.junit.jupiter.api.DisplayName)1