Search in sources :

Example 1 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method verifySetNullCalledOnPS.

/**
 * Verifies that {@link PreparedStatement#setNull(int, int)} is called when invoking
 * {@link AbstractSqlStyle#writeBind(PreparedStatement, int, SqlBind)}
 *
 * @param nullType
 *          {@link Types} null type for preparedStatement
 * @throws SQLException
 */
private void verifySetNullCalledOnPS(int nullType) throws SQLException {
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    SqlBind bind = new SqlBind(nullType, null);
    sql.writeBind(ps, 1, bind);
    Mockito.verify(ps).setNull(1, nullType);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) PreparedStatement(java.sql.PreparedStatement)

Example 2 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testWriteBindForNullClob.

/**
 * Test for {@link AbstractSqlStyle#writeBind} for null values with nulltype {@link Clob}
 *
 * @throws SQLException
 */
@Test
public void testWriteBindForNullClob() throws SQLException {
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    SqlBind bind = new SqlBind(Types.CLOB, null);
    sql.writeBind(ps, 1, bind);
    Mockito.verify(ps).setClob(1, (Clob) null);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 3 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testWriteBindNoScale.

/**
 * Test for {@link AbstractSqlStyle#writeBind} for {@link BigDecimal}
 *
 * @throws SQLException
 */
@Test
public void testWriteBindNoScale() throws SQLException {
    BigDecimal bd = new BigDecimal("9");
    SqlBind bind = new SqlBind(Types.NUMERIC, bd);
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    sql.writeBind(ps, 1, bind);
    Mockito.verify(ps).setObject(1, bd, Types.NUMERIC, 0);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testWriteBindForLongVarBinary.

/**
 * Test for {@link AbstractSqlStyle#writeBind} for null values with nulltype {@link Types.LONGVARBINARY}
 *
 * @throws SQLException
 */
@Test
public void testWriteBindForLongVarBinary() throws SQLException {
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    SqlBind bind = new SqlBind(Types.LONGVARBINARY, null);
    sql.writeBind(ps, 1, bind);
    Mockito.verify(ps).setBytes(1, (byte[]) null);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 5 with SqlBind

use of org.eclipse.scout.rt.server.jdbc.SqlBind in project scout.rt by eclipse.

the class AbstractSqlStyleTest method testWriteBind.

/**
 * Test for {@link AbstractSqlStyle#writeBind} for {@link BigDecimal}
 *
 * @throws SQLException
 */
@Test
public void testWriteBind() throws SQLException {
    BigDecimal bd = new BigDecimal("9.123");
    SqlBind bind = new SqlBind(Types.DECIMAL, bd);
    PreparedStatement ps = Mockito.mock(PreparedStatement.class);
    sql.writeBind(ps, 1, bind);
    Mockito.verify(ps).setObject(1, bd, Types.DECIMAL, 3);
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

SqlBind (org.eclipse.scout.rt.server.jdbc.SqlBind)15 Test (org.junit.Test)9 PreparedStatement (java.sql.PreparedStatement)7 BigDecimal (java.math.BigDecimal)3 ISqlStyle (org.eclipse.scout.rt.server.jdbc.style.ISqlStyle)3 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)1 NVPair (org.eclipse.scout.rt.platform.holders.NVPair)1 ISqlService (org.eclipse.scout.rt.server.jdbc.ISqlService)1