Skip to content

Commit

Permalink
Boolean columns conversion fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuttari committed Jan 5, 2021
1 parent 64fce24 commit c322db8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ It is sufficient to add the two following Gradle dependencies to the application

```gradle
dependencies {
implementation 'it.mscuttari.kaoldb:core:1.0.5'
annotationProcessor 'it.mscuttari.kaoldb:annotation-processor:1.0.5'
implementation 'it.mscuttari.kaoldb:core:1.0.6'
annotationProcessor 'it.mscuttari.kaoldb:annotation-processor:1.0.6'
}
```

Expand Down
4 changes: 3 additions & 1 deletion api/src/main/java/it/mscuttari/kaoldb/schema/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private static String escape(String str) {
* @return column type
*/
public static String classToDbType(Class<?> clazz) {
if (clazz.equals(int.class) || clazz.equals(Integer.class)) {
if (clazz.equals(boolean.class) || clazz.equals(Boolean.class)) {
return "INTEGER";
} else if (clazz.equals(int.class) || clazz.equals(Integer.class)) {
return "INTEGER";
} else if (clazz.equals(long.class) || clazz.equals(Long.class)) {
return "INTEGER";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,17 @@ public final void waitUntilMapped() {
*/
@SuppressWarnings("unchecked")
public final Object parseCursor(Cursor c, String alias) {
int columnIndex = c.getColumnIndexOrThrow(alias + "." + name);
String columnName = alias + "." + name;
int columnIndex = c.getColumnIndexOrThrow(columnName);
int columnType = c.getType(columnIndex);

Object value = null;

if (columnType == Cursor.FIELD_TYPE_INTEGER) {
if (type.equals(Integer.class) || type.equals(int.class)) {
if (type.equals(Boolean.class) || type.equals(boolean.class)) {
value = c.getInt(columnIndex) != 0;

} else if (type.equals(Integer.class) || type.equals(int.class)) {
value = c.getInt(columnIndex);

} else if (type.equals(Long.class) || type.equals(long.class)) {
Expand All @@ -203,7 +207,7 @@ public final Object parseCursor(Cursor c, String alias) {
((Calendar) value).setTimeInMillis(c.getLong(columnIndex));

} else {
throw new PojoException("Incompatible data type: expected " + type.getSimpleName() + ", found Integer");
throw new PojoException("Incompatible data type for column '" + columnName + "': expected " + type.getSimpleName() + ", found Integer");
}

} else if (columnType == Cursor.FIELD_TYPE_FLOAT) {
Expand All @@ -214,7 +218,7 @@ public final Object parseCursor(Cursor c, String alias) {
value = c.getDouble(columnIndex);

} else {
throw new PojoException("Incompatible data type: expected " + type.getSimpleName() + ", found Float");
throw new PojoException("Incompatible data type for column '" + columnName + "': expected " + type.getSimpleName() + ", found Float");
}

} else if (columnType == Cursor.FIELD_TYPE_STRING) {
Expand All @@ -225,7 +229,7 @@ public final Object parseCursor(Cursor c, String alias) {
value = c.getString(columnIndex);

} else {
throw new PojoException("Incompatible data type: expected " + type.getSimpleName() + ", found String");
throw new PojoException("Incompatible data type for column '" + columnName + "': expected " + type.getSimpleName() + ", found String");
}
}

Expand Down
2 changes: 1 addition & 1 deletion release-bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
**/
ext {
bintrayRepo = 'KaolDB'
libraryVersion = '1.0.5'
libraryVersion = '1.0.6'

publishedGroupId = 'it.mscuttari.kaoldb'
libraryName = 'KaolDB'
Expand Down

0 comments on commit c322db8

Please sign in to comment.