yichen
2 years ago
12 changed files with 787 additions and 25 deletions
@ -0,0 +1,646 @@
|
||||
package com.fanruan; |
||||
|
||||
import com.fanruan.cache.BeanCacheImpl; |
||||
import com.fanruan.handler.DispatcherImpl; |
||||
import com.fanruan.pojo.message.RpcRequest; |
||||
import com.fanruan.service.jdbc.ServiceArray; |
||||
import com.fanruan.service.jdbc.ServiceResultSetMetaData; |
||||
import com.fanruan.service.jdbc.statement.ServiceCallableStatement; |
||||
import com.fanruan.service.jdbc.statement.ServicePreparedStatement; |
||||
import org.junit.jupiter.api.Assertions; |
||||
import org.junit.jupiter.api.BeforeAll; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.api.TestInstance; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.net.URL; |
||||
import java.sql.*; |
||||
import java.util.Arrays; |
||||
import java.util.Calendar; |
||||
|
||||
/** |
||||
* @author Yichen Dai |
||||
* @date 2022/9/6 9:17 |
||||
*/ |
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
||||
public class PrepareStatementTest extends BaseJDBCTest{ |
||||
|
||||
private Connection connection = null; |
||||
private PreparedStatement preparedStatement = null; |
||||
|
||||
|
||||
@BeforeAll |
||||
void setup() throws SQLException { |
||||
openSocket(); |
||||
this.connection = getConnection(); |
||||
Statement statement = connection.createStatement(); |
||||
statement.executeUpdate("CREATE TABLE city (id INTEGER, name varchar(20)); "); |
||||
|
||||
this.preparedStatement = connection.prepareStatement( |
||||
"INSERT INTO city VALUES (1, '成都');" |
||||
); |
||||
} |
||||
|
||||
@Test |
||||
public void testPrepareDDL() throws SQLException { |
||||
try { |
||||
try (PreparedStatement prepStatement = |
||||
connection.prepareStatement("CREATE TABLE testPrepareDDL (id INTEGER);")) { |
||||
prepStatement.execute(); |
||||
} |
||||
|
||||
// HSQLDB treats unquoted identifiers as case insensitive and stores them in upper case.
|
||||
try (ResultSet resultSet = |
||||
connection.createStatement().executeQuery("SELECT \n" + |
||||
"*\n" + |
||||
"FROM INFORMATION_SCHEMA.TABLES\n" + |
||||
"WHERE TABLE_NAME LIKE 'TESTPREPAREDDL';")) { |
||||
// result should only have one row since table is created
|
||||
Assertions.assertEquals(1, getSizeOfResultSet(resultSet)); |
||||
} |
||||
} finally { |
||||
connection.createStatement().execute("drop table if exists TESTPREPAREDDL"); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testWrap() throws SQLException { |
||||
Assertions.assertFalse(preparedStatement.isWrapperFor(null)); |
||||
Assertions.assertThrows(SQLException.class, () -> preparedStatement.unwrap(null)); |
||||
} |
||||
|
||||
@Test |
||||
public void testMethodsThrow() throws SQLException{ |
||||
ServicePreparedStatement pstm = (ServicePreparedStatement) this.preparedStatement; |
||||
String IDtoInvoke = pstm.getID(); |
||||
|
||||
DispatcherImpl dispatcher = agent.dispatcherImpl; |
||||
BeanCacheImpl beanCache = dispatcher.CACHE.getBeanCache(dbName); |
||||
|
||||
ServicePreparedStatement pstm2 = (ServicePreparedStatement) ProxyFactoryIT.getProxy(ServicePreparedStatement.class, map); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setNClob(1, new FakeNClob()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setNull(1, Types.INTEGER); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setObject(1, null); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setRef(1, null); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setRowId(1, null); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setShort(1, Short.parseShort("0")); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setSQLXML(1, new FakeSQLXML()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setArray(1, null); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setAsciiStream(1, new FakeInputStream()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setAsciiStream(1, new FakeInputStream(), 1); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setAsciiStream(1, new FakeInputStream(), 1L); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setBigDecimal(1, new BigDecimal(0)); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setBinaryStream(0, new FakeInputStream()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setBinaryStream(1, new FakeInputStream(), 1); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setBinaryStream(1, new FakeInputStream(), 1L); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setBlob(1, new FakeBlob()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setBlob(1, new FakeInputStream()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setBlob(1, new FakeInputStream(), 1L); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setBoolean(1, false); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setByte(1, Byte.parseByte("0")); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setBytes(1, new byte[]{}); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setCharacterStream(1, new FakeReader()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setCharacterStream(1, new FakeReader(), 1); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setCharacterStream(1, new FakeReader(), 1L); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setClob(1, new FakeClob()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setClob(1, new FakeReader()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(ArrayIndexOutOfBoundsException.class, () -> { |
||||
pstm2.setClob(1, new FakeReader(), 1L); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setDate(1, new Date(1)); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setDate(1, new Date(0), Calendar.getInstance()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setDouble(1, 0.0); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setFloat(1, 0.0f); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setInt(1, 0); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setLong(1, 0L); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setTimestamp(1, new Timestamp(50)); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setTimestamp(1, new Timestamp(50), Calendar.getInstance()); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setUnicodeStream(1, new FakeInputStream(), 1); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> { |
||||
pstm2.setURL(1, new URL("http://localhost:8888")); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> { |
||||
pstm2.executeLargeBatch(); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
Assertions.assertThrows(UnsupportedOperationException.class, () -> { |
||||
pstm2.getLargeUpdateCount(); |
||||
RpcRequest request = map.get(null); |
||||
request.setIDToInvoke(IDtoInvoke); |
||||
dispatcher.invokeAsRequest( |
||||
request, |
||||
beanCache); |
||||
} |
||||
); |
||||
|
||||
pstm.setEscapeProcessing(false); |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pstm.setCursorName("name"); |
||||
|
||||
pstm.setPoolable(false); |
||||
|
||||
pstm.setQueryTimeout(2000); |
||||
} |
||||
|
||||
@Test |
||||
public void testFildSize() throws SQLException{ |
||||
preparedStatement.setMaxFieldSize(1000); |
||||
|
||||
// HSQLDB always returns zero, meaning there is no limit.
|
||||
Assertions.assertEquals(0, preparedStatement.getMaxFieldSize()); |
||||
} |
||||
|
||||
@Test |
||||
public void testDirection() throws SQLException { |
||||
// Starting with 2.0, HSQLDB accepts any valid value.
|
||||
preparedStatement.setFetchDirection(ResultSet.FETCH_FORWARD); |
||||
|
||||
Assertions.assertEquals(ResultSet.FETCH_FORWARD, preparedStatement.getFetchDirection()); |
||||
} |
||||
|
||||
@Test |
||||
public void testFectchSize() throws SQLException{ |
||||
preparedStatement.setFetchSize(0); |
||||
|
||||
Assertions.assertEquals(0, preparedStatement.getFetchSize()); |
||||
} |
||||
|
||||
@Test |
||||
public void testMaxRows() throws SQLException{ |
||||
preparedStatement.setMaxRows(1000); |
||||
|
||||
Assertions.assertEquals(1000, preparedStatement.getMaxRows()); |
||||
} |
||||
|
||||
@Test |
||||
public void testGet() throws SQLException{ |
||||
/** |
||||
* Retrieves the maximum number of rows that a ResultSet object produced by this Statement object can contain. If this limit is exceeded, the excess rows are silently dropped. |
||||
* This method should be used when the returned row limit may exceed Integer.MAX_VALUE. |
||||
* |
||||
* The default implementation will return 0 |
||||
*/ |
||||
Assertions.assertEquals(0, preparedStatement.getLargeMaxRows()); |
||||
} |
||||
|
||||
@Test |
||||
public void testExecuteBatch() throws SQLException{ |
||||
|
||||
String SQL_INSERT = "INSERT INTO EMPLOYEE VALUES ?;"; |
||||
|
||||
String SQL_CREATE = "CREATE TABLE EMPLOYEE (NAME varchar(100));"; |
||||
|
||||
PreparedStatement psDDL = connection.prepareStatement(SQL_CREATE); |
||||
psDDL.execute(); |
||||
|
||||
PreparedStatement psInsert = connection.prepareStatement(SQL_INSERT); |
||||
|
||||
// Run list of insert commands
|
||||
psInsert.setString(1, "mkyong"); |
||||
psInsert.addBatch(); |
||||
|
||||
psInsert.setString(1, "kungfu"); |
||||
psInsert.addBatch(); |
||||
|
||||
psInsert.setString(1, "james"); |
||||
psInsert.addBatch(); |
||||
|
||||
int[] rows = psInsert.executeBatch(); |
||||
Assertions.assertEquals(3, rows.length); |
||||
} |
||||
|
||||
@Test |
||||
public void testResultMetaData() throws SQLException { |
||||
PreparedStatement psmt = connection.prepareStatement("SELECT * FROM city WHERE id = ?"); |
||||
ResultSetMetaData metaData = psmt.getMetaData(); |
||||
|
||||
Assertions.assertEquals(2, metaData.getColumnCount()); |
||||
|
||||
Assertions.assertEquals("PUBLIC", metaData.getCatalogName(1)); |
||||
|
||||
Assertions.assertEquals("PUBLIC", metaData.getSchemaName(1)); |
||||
|
||||
// This reports the SQL type code of the column.
|
||||
// For time and timestamp types that are WITH TIME ZONE, the values as the SQL Standard CLI codes.
|
||||
Assertions.assertEquals(Types.INTEGER, metaData.getColumnType(1)); |
||||
|
||||
Assertions.assertEquals("INTEGER", metaData.getColumnTypeName(1)); |
||||
|
||||
Assertions.assertEquals(Integer.class.getName(), metaData.getColumnClassName(1)); |
||||
|
||||
Assertions.assertFalse(metaData.isAutoIncrement(1)); |
||||
|
||||
// This method returns true for any column whose data type is a character type, with the exception of VARCHAR_IGNORECASE for which it returns false.
|
||||
// It also returns false for any column whose data type is a not a character data type.
|
||||
Assertions.assertTrue(metaData.isCaseSensitive(2)); |
||||
|
||||
// If the column in question is a database table or view column,
|
||||
// and the type of the column allows searching, then returns true, otherwise false.
|
||||
Assertions.assertTrue(metaData.isSearchable(1)); |
||||
|
||||
// HSQLDB 2.0 fully supports this feature and returns true for NUMERIC and DECIMAL columns.
|
||||
Assertions.assertFalse(metaData.isCurrency(1)); |
||||
|
||||
Assertions.assertEquals(ResultSetMetaData.columnNullable, metaData.isNullable(1)); |
||||
|
||||
Assertions.assertTrue(metaData.isSigned(1)); |
||||
|
||||
// If the result set column is a direct pass through of a table column value and column size was declared,
|
||||
// then the declared value is returned.
|
||||
Assertions.assertEquals(20, metaData.getColumnDisplaySize(2)); |
||||
|
||||
Assertions.assertEquals("NAME", metaData.getColumnLabel(2)); |
||||
|
||||
Assertions.assertEquals("ID", metaData.getColumnName(1)); |
||||
|
||||
// For character data, this is the [maximum] length in characters.
|
||||
Assertions.assertEquals(20, metaData.getPrecision(2)); |
||||
|
||||
// The reported scale for INTEGER, BIGINT and DOUBLE is 0
|
||||
Assertions.assertEquals(0, metaData.getScale(1)); |
||||
|
||||
Assertions.assertEquals("CITY", metaData.getTableName(1)); |
||||
|
||||
// From 2.0 this method returns true if the ResultSet is not updatable or the column in question is not updatable.
|
||||
Assertions.assertFalse(metaData.isReadOnly(1)); |
||||
|
||||
// From 2.0 this method returns false if the ResultSet is not updatable or the column in question is not updatable.
|
||||
Assertions.assertFalse(metaData.isWritable(2)); |
||||
|
||||
// From 2.0 this method returns false if the ResultSet is not updatable or the column in question is not updatable.
|
||||
Assertions.assertFalse(metaData.isDefinitelyWritable(1)); |
||||
|
||||
Assertions.assertFalse(metaData.isWrapperFor(null)); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> metaData.unwrap(null)); |
||||
} |
||||
|
||||
@Test |
||||
public void testParameterMetaData() throws SQLException { |
||||
PreparedStatement psmt = connection.prepareStatement("SELECT * FROM city WHERE id = ?"); |
||||
ParameterMetaData metaData = psmt.getParameterMetaData(); |
||||
|
||||
Assertions.assertEquals(1, metaData.getParameterCount()); |
||||
|
||||
Assertions.assertEquals(ParameterMetaData.parameterNullableUnknown, metaData.isNullable(1)); |
||||
|
||||
Assertions.assertTrue(metaData.isSigned(1)); |
||||
|
||||
Assertions.assertEquals(10, metaData.getPrecision(1)); |
||||
|
||||
Assertions.assertEquals(0, metaData.getScale(1)); |
||||
|
||||
Assertions.assertEquals(Types.INTEGER, metaData.getParameterType(1)); |
||||
|
||||
Assertions.assertEquals("INTEGER", metaData.getParameterTypeName(1)); |
||||
|
||||
Assertions.assertEquals(Integer.class.getName(), metaData.getParameterClassName(1)); |
||||
|
||||
Assertions.assertEquals(ParameterMetaData.parameterModeIn, metaData.getParameterMode(1)); |
||||
|
||||
Assertions.assertFalse(metaData.isWrapperFor(null)); |
||||
|
||||
Assertions.assertThrows(SQLException.class, () -> metaData.unwrap(null)); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue