-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binary and Varbinary types for framework #119
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.commons.codec.binary.Hex; | ||
|
||
import com.microsoft.sqlserver.testframework.sqlType.SqlType; | ||
import com.microsoft.sqlserver.testframework.sqlType.VariableLengthType; | ||
import com.microsoft.sqlserver.testframework.util.RandomUtil; | ||
|
@@ -251,16 +253,22 @@ String populateTableSql() { | |
for (int colNum = 0; colNum < totalColumns; colNum++) { | ||
|
||
// TODO: add betterway to enclose data | ||
if (JDBCType.CHAR == getColumn(colNum).getSqlType().getJdbctype() | ||
if (JDBCType.CHAR == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.VARCHAR == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.NCHAR == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.NVARCHAR == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.TIMESTAMP == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.DATE == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.TIME == getColumn(colNum).getSqlType().getJdbctype()) | ||
|| JDBCType.TIME == getColumn(colNum).getSqlType().getJdbctype()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SUGGESTION: In order to reduce complexity it is better to create new method having all conditions and call that method in your if condition. |
||
sb.add("'" + String.valueOf(getColumn(colNum).getRowValue(i)) + "'"); | ||
else | ||
} | ||
else if (JDBCType.BINARY == getColumn(colNum).getSqlType().getJdbctype() | ||
|| JDBCType.VARBINARY == getColumn(colNum).getSqlType().getJdbctype()) { | ||
sb.add("0X" + Hex.encodeHexString((byte[]) (getColumn(colNum).getRowValue(i)))); | ||
} | ||
else { | ||
sb.add(String.valueOf(getColumn(colNum).getRowValue(i))); | ||
} | ||
|
||
if (colNum < totalColumns - 1) { | ||
sb.add(COMMA); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// --------------------------------------------------------------------------------------------------------------------------------- | ||
// File: SqlBinary.java | ||
// | ||
// | ||
// Microsoft JDBC Driver for SQL Server | ||
// Copyright(c) Microsoft Corporation | ||
// All rights reserved. | ||
// MIT License | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files(the "Software"), | ||
// to deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
// and / or sell copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following conditions : | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
// IN THE SOFTWARE. | ||
// --------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
package com.microsoft.sqlserver.testframework.sqlType; | ||
|
||
import java.sql.JDBCType; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add appropriate java docs? |
||
public class SqlBinary extends SqlType { | ||
|
||
public SqlBinary() { | ||
this("binary", JDBCType.BINARY, 2000); | ||
} | ||
|
||
SqlBinary(String name, JDBCType jdbctype, int precision) { | ||
super(name, jdbctype, precision, 0, SqlTypeValue.BINARY.minValue, SqlTypeValue.BINARY.maxValue, SqlTypeValue.BINARY.nullValue, | ||
VariableLengthType.Precision); | ||
generatePrecision(); | ||
} | ||
|
||
public Object createdata() { | ||
int dataLength = ThreadLocalRandom.current().nextInt(precision); | ||
byte[] bytes = new byte[dataLength]; | ||
ThreadLocalRandom.current().nextBytes(bytes); | ||
return bytes; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// --------------------------------------------------------------------------------------------------------------------------------- | ||
// File: SqlVarBinary.java | ||
// | ||
// | ||
// Microsoft JDBC Driver for SQL Server | ||
// Copyright(c) Microsoft Corporation | ||
// All rights reserved. | ||
// MIT License | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files(the "Software"), | ||
// to deal in the Software without restriction, including without limitation the | ||
// rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
// and / or sell copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following conditions : | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
// IN THE SOFTWARE. | ||
// --------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
package com.microsoft.sqlserver.testframework.sqlType; | ||
|
||
import java.sql.JDBCType; | ||
|
||
public class SqlVarBinary extends SqlBinary { | ||
|
||
public SqlVarBinary() { | ||
super("varbinary", JDBCType.VARBINARY, 4000); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Can we have one utility method to get JDBCType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya, that sounds good.