Skip to content
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

SQLiteStatement.columnValue returns a Long when an Integer is expected #15

Closed
GoogleCodeExporter opened this issue Mar 25, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

When you use columnValue method to retrieve an Integer, you obtain a Long. Here 
is a small test case:

SQLiteStatement st = cnx.prepare("select 1;");
st.step();
Assert.assertEquals(Integer.class, st.columnValue(0).getClass());

The problem comes from SQLiteStatement.java, line 1044:

return value == ((long) ((int) value)) ? Integer.valueOf((int) value) : 
Long.valueOf(value);

This instruction works fine unless you mix Integer, Byte, Short, Long, Float or 
Double value as the result of the inline condition. For example, the following 
inline condition:

<cond> ? new Integer(1) : new String()

has a type of Object: the common base class of Integer and String. But the 
following condition:

<cond> ? new Integer(1) : new Long(1)

has a type of Long. This is because a promotion occurs on Integer and it 
becomes a Long.

you must use standard condition like:

if (value == (int)value) {
  return Integer.valueOf(value);
}
return Long.valueOf(value);

It works fine for me.

Original issue reported on code.google.com by olivier....@free.fr on 19 Aug 2010 at 12:18

@GoogleCodeExporter
Copy link
Author

Thx!

Original comment by ser...@gmail.com on 19 Aug 2010 at 12:25

  • Changed state: Accepted
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

fixed in revision 193

Original comment by ser...@gmail.com on 21 Aug 2010 at 10:55

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Original comment by ser...@gmail.com on 23 Aug 2010 at 8:10

  • Changed state: Delivered
  • Added labels: FixVersion-201
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant