You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "yogneder (JIRA)" <ib...@incubator.apache.org> on 2005/04/11 15:26:20 UTC

[jira] Created: (IBATIS-106) Retrieving bit value from data base

Retrieving bit value from data base
-----------------------------------

         Key: IBATIS-106
         URL: http://issues.apache.org/jira/browse/IBATIS-106
     Project: iBatis for Java
        Type: Task
  Components: SQL Maps  
 Environment: SQL server
    Reporter: yogneder


I’m having a problem while retrieving the data from a column of the table whose data type is ‘bit’. The values stored are 0 or 1. However when I try retrieve the values it returns true or false based on the value. 
How can I retrieve the values in the form of 1 or 0.
Pls help. This is urgent…
Thanks in Advance.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Closed: (IBATIS-106) Retrieving bit value from data base

Posted by "Clinton Begin (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-106?page=all ]
     
Clinton Begin closed IBATIS-106:
--------------------------------

    Resolution: Invalid

There are a number of ways to deal with this...map it to a numeric type, use a custom type handler etc.

> Retrieving bit value from data base
> -----------------------------------
>
>          Key: IBATIS-106
>          URL: http://issues.apache.org/jira/browse/IBATIS-106
>      Project: iBatis for Java
>         Type: Task
>   Components: SQL Maps
>  Environment: SQL server
>     Reporter: yogneder

>
> I’m having a problem while retrieving the data from a column of the table whose data type is ‘bit’. The values stored are 0 or 1. However when I try retrieve the values it returns true or false based on the value. 
> How can I retrieve the values in the form of 1 or 0.
> Pls help. This is urgent…
> Thanks in Advance.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-106) Retrieving bit value from data base

Posted by "Alexandru Barbat (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-106?page=comments#action_62811 ]
     
Alexandru Barbat commented on IBATIS-106:
-----------------------------------------

My opinion is that you have to implement an special handler.

and in resultMap you have to specify it something like this:

...
  <typeAlias alias="booleanHandler" type="org.fmk.ibatis.handler.BooleanTypeHandlerCallback"/>
...


  <resultMap id="example-map-result" class="java.util.HashMap">
    <result property="action" column="ACTION"/>
    <result property="mode" column="MODE_ACCESS"  typeHandler="booleanHandler"/>
  </resultMap>

Example (Special handler):

import java.sql.SQLException;

...
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;


public class BooleanTypeHandlerCallback
    implements TypeHandlerCallback {

  private static int refDbTrue = Integer.parseInt(IConstantes.TRUE_INT);

  public Object getResult(ResultGetter getter) throws SQLException {
    int i = getter.getInt();

    if (i == refDbTrue) {
      return new Boolean(true);
    }
    else {
      return new Boolean(false);
    }
  }

  public void setParameter(ParameterSetter setter, Object parameter) throws
      SQLException {

    boolean b = ( (Boolean) parameter).booleanValue();
    if (b) {
      setter.setInt(1);
    }
    else {
      setter.setInt(0);
    }
  }

  public Object valueOf(String s) {
    if ( (IConstantes.TRUE_INT).equalsIgnoreCase(s)) {
      return new Boolean(true);
    }
    else {
      return new Boolean(false);
    }
  }
}



> Retrieving bit value from data base
> -----------------------------------
>
>          Key: IBATIS-106
>          URL: http://issues.apache.org/jira/browse/IBATIS-106
>      Project: iBatis for Java
>         Type: Task
>   Components: SQL Maps
>  Environment: SQL server
>     Reporter: yogneder

>
> I’m having a problem while retrieving the data from a column of the table whose data type is ‘bit’. The values stored are 0 or 1. However when I try retrieve the values it returns true or false based on the value. 
> How can I retrieve the values in the form of 1 or 0.
> Pls help. This is urgent…
> Thanks in Advance.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira