|
1 | 1 | /** |
2 | | - * Copyright (c) 2010 - 2016 Yahoo! Inc., 2016 YCSB contributors. All rights reserved. |
| 2 | + * Copyright (c) 2010 - 2016 Yahoo! Inc., 2016, 2019 YCSB contributors. All rights reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you |
5 | 5 | * may not use this file except in compliance with the License. You |
@@ -82,6 +82,7 @@ public class JdbcDBClient extends DB { |
82 | 82 | /** The field name prefix in the table. */ |
83 | 83 | public static final String COLUMN_PREFIX = "FIELD"; |
84 | 84 |
|
| 85 | + private boolean sqlserver = false; |
85 | 86 | private List<Connection> conns; |
86 | 87 | private boolean initialized = false; |
87 | 88 | private Properties props; |
@@ -183,6 +184,10 @@ public void init() throws DBException { |
183 | 184 | String passwd = props.getProperty(CONNECTION_PASSWD, DEFAULT_PROP); |
184 | 185 | String driver = props.getProperty(DRIVER_CLASS); |
185 | 186 |
|
| 187 | + if (driver.contains("sqlserver")) { |
| 188 | + sqlserver = true; |
| 189 | + } |
| 190 | + |
186 | 191 | this.jdbcFetchSize = getIntProperty(props, JDBC_FETCH_SIZE); |
187 | 192 | this.batchSize = getIntProperty(props, DB_BATCH_SIZE); |
188 | 193 |
|
@@ -299,7 +304,7 @@ private PreparedStatement createAndCacheUpdateStatement(StatementType updateType |
299 | 304 |
|
300 | 305 | private PreparedStatement createAndCacheScanStatement(StatementType scanType, String key) |
301 | 306 | throws SQLException { |
302 | | - String select = dbFlavor.createScanStatement(scanType, key); |
| 307 | + String select = dbFlavor.createScanStatement(scanType, key, sqlserver); |
303 | 308 | PreparedStatement scanStatement = getShardConnectionByKey(key).prepareStatement(select); |
304 | 309 | if (this.jdbcFetchSize > 0) { |
305 | 310 | scanStatement.setFetchSize(this.jdbcFetchSize); |
@@ -348,8 +353,13 @@ public Status scan(String tableName, String startKey, int recordcount, Set<Strin |
348 | 353 | if (scanStatement == null) { |
349 | 354 | scanStatement = createAndCacheScanStatement(type, startKey); |
350 | 355 | } |
351 | | - scanStatement.setString(1, startKey); |
352 | | - scanStatement.setInt(2, recordcount); |
| 356 | + if (sqlserver) { |
| 357 | + scanStatement.setInt(1, recordcount); |
| 358 | + scanStatement.setString(2, startKey); |
| 359 | + } else { |
| 360 | + scanStatement.setString(1, startKey); |
| 361 | + scanStatement.setInt(2, recordcount); |
| 362 | + } |
353 | 363 | ResultSet resultSet = scanStatement.executeQuery(); |
354 | 364 | for (int i = 0; i < recordcount && resultSet.next(); i++) { |
355 | 365 | if (result != null && fields != null) { |
|
0 commit comments