Hi,

FYI Shannah, 

I modified DAO.java in your framework like : 
/**
* Fills a map with the data of the current row of database Cursor
*
* @param c
*            The database cursor from a query.
* @param m
*            The map to fill.
* @throws IOException
*/
protected void fillMap(Cursor c, Map m) throws IOException {
Row row = c.getRow();
int len = c.getColumnCount();
for (int i = 0; i < len; i++) {

String colName = c.getColumnName(i);
ColType colType = colTypes.get(colName);

if (colType == null) {
continue;
}
switch (colType) {
case FLOAT:
if (isNotNullValue(row, i))
m.put(colName, row.getFloat(i));
break;
case DOUBLE:
if (isNotNullValue(row, i))
m.put(colName, row.getDouble(i));
break;
case BLOB:
m.put(colName, row.getBlob(i));
break;
case STRING:
case VARCHAR:
m.put(colName, row.getString(i));
break;
case INTEGER:
if ("id".equals(colName) || colName.startsWith("id")) { // if it's the 
object's id or foreign key id
m.put(colName, row.getLong(i));
} else {
if (isNotNullValue(row, i))
m.put(colName, row.getInteger(i));
}
break;
case LONG:
if (isNotNullValue(row, i))
m.put(colName, row.getLong(i));
break;
case SHORT:
if (isNotNullValue(row, i))
m.put(colName, row.getShort(i));
break;
default:
}

}
}

private boolean isNotNullValue(Row row, int ind) throws IOException {
return !"null".equals(row.getString(ind));

}

If it's null in database, it doesn't fill map with the value so when your 
try to retrieve your value like :

map.get("my_value_key");

it will return null (as it is in database.

Won't hesitate if I am wrong !

On Tuesday, May 24, 2016 at 10:32:33 AM UTC+2, Jérémy MARQUER wrote:
>
> Hi,
>
> I'm facing to a problem with load/read data in database. In case of 
> integer or long column type, we can't find/update/save object with null 
> values since these methods return primitive types : 
>   /**
>      * Gets column value by index.
>      * 
>      * @param index starts with zero
>      * @return a int data from the database
>      * @throws IOException 
>      */
>     public int getInteger(int index)throws IOException;
>
>
>     /**
>      * Gets column value by index.
>      * 
>      * @param index starts with zero
>      * @return a long data from the database
>      * @throws IOException 
>      */
>     public long getLong(int index)throws IOException;
>
>
> I absolutely need to save null value in my database. 
>
> FYI, I use cn1-data-lib-access shannah's library.
>
> Thanks.
>
> If you are experiencing an issue please mention the full platform your 
> issue applies to:
> IDE: NetBeans/Eclipse/IDEA
> Desktop OS
> Simulator 
> Device
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/e1e2e408-164a-43f5-b3d7-42510231bd83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to