use of com.microsoft.sqlserver.jdbc.SQLServerConnection in project mssql-jdbc by Microsoft.
the class WarningTest method testWarnings.
@Test
public void testWarnings() throws SQLException {
SQLServerConnection conn = (SQLServerConnection) DriverManager.getConnection(connectionString);
Properties info = conn.getClientInfo();
conn.setClientInfo(info);
SQLWarning warn = conn.getWarnings();
assertEquals(null, warn, "Warnings found.");
Properties info2 = new Properties();
String[] infoArray = { "prp1", "prp2", "prp3", "prp4", "prp5" };
for (int i = 0; i < 5; i++) {
info2.put(infoArray[i], "");
}
conn.setClientInfo(info2);
warn = conn.getWarnings();
for (int i = 0; i < 5; i++) {
boolean found = false;
List<String> list = Arrays.asList(infoArray);
for (String word : list) {
if (warn.toString().contains(word)) {
found = true;
break;
}
}
assertTrue(found, "warning : '" + warn.toString() + "' not found!");
warn = warn.getNextWarning();
found = false;
}
conn.clearWarnings();
conn.setClientInfo("prop7", "");
warn = conn.getWarnings();
assertTrue(warn.toString().contains("prop7"), "Warnings not found!");
warn = warn.getNextWarning();
assertEquals(null, warn, "Warnings found!");
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnection in project mssql-jdbc by Microsoft.
the class RegressionTest method testSelectIntoUpdateCount.
/**
* Tests update count returned by SELECT INTO
*
* @throws SQLException
*/
@Test
public void testSelectIntoUpdateCount() throws SQLException {
SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(connectionString);
// Azure does not do SELECT INTO
if (!DBConnection.isSqlAzure(con)) {
final String tableName = "[#SourceTableForSelectInto]";
Statement stmt = con.createStatement();
stmt.executeUpdate("CREATE TABLE " + tableName + " (col1 int primary key, col2 varchar(3), col3 varchar(128))");
stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (1, 'CAN', 'Canada')");
stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (2, 'USA', 'United States of America')");
stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (3, 'JPN', 'Japan')");
// expected values
int numRowsToCopy = 2;
PreparedStatement ps = con.prepareStatement("SELECT * INTO #TMPTABLE FROM " + tableName + " WHERE col1 <= ?");
ps.setInt(1, numRowsToCopy);
int updateCount = ps.executeUpdate();
assertEquals(numRowsToCopy, updateCount, "Incorrect update count");
if (null != stmt)
stmt.close();
}
if (null != con)
con.close();
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnection in project mssql-jdbc by Microsoft.
the class RegressionTest method terminate.
@AfterAll
public static void terminate() throws SQLException {
SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(connectionString);
Statement stmt = con.createStatement();
Utils.dropTableIfExists(tableName, stmt);
Utils.dropProcedureIfExists(procName, stmt);
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnection in project sqlg by pietermartin.
the class MSSqlServerDialect method flushEdgeGlobalUniqueIndexes.
@Override
public void flushEdgeGlobalUniqueIndexes(SqlgGraph sqlgGraph, Map<MetaEdge, Pair<SortedSet<String>, Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>>>> edgeCache) {
for (MetaEdge metaEdge : edgeCache.keySet()) {
Pair<SortedSet<String>, Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>>> triples = edgeCache.get(metaEdge);
Map<SqlgEdge, Triple<SqlgVertex, SqlgVertex, Map<String, Object>>> edgeMap = triples.getRight();
Map<String, PropertyColumn> propertyColumnMap = sqlgGraph.getTopology().getPropertiesFor(metaEdge.getSchemaTable().withPrefix(EDGE_PREFIX));
for (Map.Entry<String, PropertyColumn> propertyColumnEntry : propertyColumnMap.entrySet()) {
PropertyColumn propertyColumn = propertyColumnEntry.getValue();
for (GlobalUniqueIndex globalUniqueIndex : propertyColumn.getGlobalUniqueIndices()) {
try {
Connection connection = sqlgGraph.tx().getConnection();
SQLServerConnection sqlServerConnection = connection.unwrap(SQLServerConnection.class);
try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) {
bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Schema.GLOBAL_UNIQUE_INDEX_SCHEMA) + "." + sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + globalUniqueIndex.getName()));
bulkCopy.writeToServer(new SQLServerEdgeGlobalUniqueIndexBulkRecord(bulkCopy, sqlgGraph, edgeMap, propertyColumn));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
}
use of com.microsoft.sqlserver.jdbc.SQLServerConnection in project sqlg by pietermartin.
the class MSSqlServerDialect method flushVertexCache.
@Override
public void flushVertexCache(SqlgGraph sqlgGraph, Map<SchemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>>> vertexCache) {
Connection connection = sqlgGraph.tx().getConnection();
for (Map.Entry<SchemaTable, Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>>> entry : vertexCache.entrySet()) {
SchemaTable schemaTable = entry.getKey();
Pair<SortedSet<String>, Map<SqlgVertex, Map<String, Object>>> vertices = entry.getValue();
if (vertices.getLeft().isEmpty()) {
Map<String, PropertyType> columns = new HashMap<>();
columns.put("dummy", PropertyType.from(0));
sqlgGraph.getTopology().ensureVertexLabelPropertiesExist(schemaTable.getSchema(), schemaTable.getTable(), columns);
}
try {
SQLServerConnection sqlServerConnection = connection.unwrap(SQLServerConnection.class);
try (SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(sqlServerConnection)) {
if (schemaTable.isTemporary()) {
bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(sqlgGraph.getSqlDialect().temporaryTablePrefix() + VERTEX_PREFIX + schemaTable.getTable()));
} else {
bulkCopy.setDestinationTableName(sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()) + "." + sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + schemaTable.getTable()));
}
bulkCopy.writeToServer(new SQLServerVertexCacheBulkRecord(bulkCopy, sqlgGraph, schemaTable, vertices));
}
int numberInserted = vertices.getRight().size();
if (!schemaTable.isTemporary() && numberInserted > 0) {
long endHigh;
// If multiple threads are bulk writing to the same label then the indexes might no be in sequence.
try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT IDENT_CURRENT('" + schemaTable.getSchema() + "." + VERTEX_PREFIX + schemaTable.getTable() + "')")) {
ResultSet resultSet = preparedStatement.executeQuery();
resultSet.next();
endHigh = resultSet.getLong(1);
resultSet.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
// set the id on the vertex
long id = endHigh - numberInserted + 1;
for (SqlgVertex sqlgVertex : vertices.getRight().keySet()) {
sqlgVertex.setInternalPrimaryKey(RecordId.from(schemaTable, id++));
}
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
Aggregations