Reputation: 11
Using CodenameOne web database extension, I can get basic SQL fields to work for strings and numbers, but not for large binary objects BLOBs. I'm following the instructions here: https://www.codenameone.com/blog/connecting-to-a-mysql-database-part-2.html Are BLOBs supported by CodenameOne? If so how do you do it? I can't find any examples that use BLOB types.
I've tried using long strings, and with the MarianaDB, can get up to 512K string size, but I need to store images which can be larger.
MariaDB [(none)]> use tsg; desc photos; Database changed +------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | player_id | int(11) | NO | | NULL | | | tree_id | int(11) | NO | | NULL | | | photo_type | longtext | NO | | NULL | | | image | blob | YES | | NULL | | +------------+------------------+------+-----+---------+----------------+ 5 rows in set (0.001 sec)
When I add the record without the blob it works:
m.put("playerId", "1");
m.put("treeId", "2");
m.put("photoType", "front");
m.put("image", null);
client.create(m, res -> {
System.out.println(m);
System.out.println("create result = " + res);
});
outputs: {treeId=2, image=null, photoType=front, playerId=1} create result = true
But when I try to add the blob, it does not:
m.put("playerId", "1");
m.put("treeId", "2");
m.put("photoType", "front");
byte bytes[] = new byte[100];
m.put("image", bytes);
client.create(m, res -> {
System.out.println(m);
System.out.println("create result = " + res);
});
outputs:
{treeId=2, image=[B@5968c8cb, photoType=front, playerId=1} create result = false
Help! I'm using BLOBs in the wrong way, or does CN1 not support BLOBs?
The only error message is from the result of create being false.
Upvotes: 1
Views: 50
Reputation: 52770
It doesn't have builtin support for that at this time. You can use MultipartRequest to submit binary data to the server.
Upvotes: 1