Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » SqlBind error(Error)
SqlBind error [message #1795499] Mon, 24 September 2018 11:39 Go to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello
I am facin this error with my application, can any one help me please

no SqlBind mapping for class org.eclipse.scout.rt.platform.resource.BinaryResource

I am trying to save a Doc file to the data base ( LONGBLOB ) and the field in the Table is a BinaryResource Column.

Kind Regards
Re: SqlBind error [message #1795506 is a reply to message #1795499] Mon, 24 September 2018 13:53 Go to previous messageGo to next message
Patrick Baenziger is currently offline Patrick BaenzigerFriend
Messages: 96
Registered: September 2011
Member
Hi there

This message indicates that you're probably trying to pass an object to the SQL service - but the service can't convert it into something the database will understand.

BinaryResource is a wrapper for byte[].
Have you made sure that you are unwrapping (calling the getContent() method on) the BinaryResource when trying to store the content and pass the byte array to the SQL Service instead of the Binary Resource itself?
And in the other direction, that you're wrapping the Byte Array in a BinaryResource using the constructor?

Please otherwise provide us with the following to effectively help you:

  • Which version of Scout are you using?
  • An extract of the code where your error happens


Regards,
Patrick
Re: SqlBind error [message #1795511 is a reply to message #1795506] Mon, 24 September 2018 14:41 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello,
Actually in the Table I use the FileBinaryColum defined by the Framework and then I am using

getTable().getFileBinaryColumn().setValue(row, file);

to popolate it
if I use
getTable().getFileBinaryColumn().setValue(row, file.getContent());

This will generate an error because the setValue will only accept BinaryResource Entry.

then is I use parseValue(row, file.getContent())

This will generate the follwing error

converting [50,4b,03,04,14,00,08,08,08,00,2b,59,38,4d,00,00,00,00,00,00,00,00,00,00,00,00,1a,00,00,00,78,6c,2f,5f,72,65,6c,73,2f,77,6f,72,6b,62,6f,6f,6b,2e,78,6d,6c,2e,72,65,6c,73,bd,94,4d,4e,c3,30,10,46,f7,3d,85,35,7b,e2,24,fd,01,a1,38,dd,54,48,dd,42,39,80,e5,4c,e2,a8,89,6d,79,5c,a0,b7,c7,08,04,a9,54,59,2c,aa,...] from byte[] to BinaryResource failed with code 2 (no from-mapping)


So I understand that I have to use an other TabColumn but I do not see any other Type that can support Binary file;

Kind Regards
Anis
Re: SqlBind error [message #1795515 is a reply to message #1795511] Mon, 24 September 2018 15:37 Go to previous messageGo to next message
Patrick Baenziger is currently offline Patrick BaenzigerFriend
Messages: 96
Registered: September 2011
Member
Hi Anis

You seem to have two different problems, I'll address them separately:


  1. In the client: Storing the binary resource into your table
  2. In the server: Getting the binary resource in and out of the database


1. Getting the data into the table and to the backend
This one is simple: There is no dedicated column for BinaryResources like AbstractStringColumn. Simply use the generic AbstractColumn and use the generic parameter: AbstractColumn<BinaryResource>
You can get the BinaryResource into and out of the column by calling the usual get/setValue methods - no "parse" needed! This will also generate you a suitable rowdata entry in the FormData.

2. Getting the data into and out of the database
This one is more tricky and depends on how you're doing it. Please show more of your backend code if my assumptions here are wrong.

Getting the data out: ("select")
I'm assuming here that you're using the SqlService method "selectInto" like this: "SELECT ..., content, ... INTO ..., :binaryResourceColumn, ..." (where "binaryResourceColumn" is the name of your rowData entry for the binary resource column)?
This won't work because there is no automatic mapping to do the conversion between BLOBS and BinaryResources.
So that will require a bit of manual work: Use the "select" Method instead that returns a Object[][] (basically: a table, first dimension being the rows, second dimension the columns you selected).
Iterate over the rows and colums and fill them into your rows of the formData. When you get to the byte[], you can simply use the BinaryResource(String filename, byte[] content) constructor to create it and fill it into your row.

Storing the data: (insert/update)
Make sure to use the NVPair class to bind the content of the BinaryResource - the NVPair constructor must get the content (byte[]) and not the BinaryResource itself!

Re: SqlBind error [message #1795521 is a reply to message #1795515] Mon, 24 September 2018 16:16 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello,
I am using this service

@Override
public void storeMedDoc(MedDocTable formData, Integer patientID,
byte[] fileByte) {

SQL.insert(SQLs.MEDDOC_INSERT + fileByte + " ," + id + ")",
new NVPair("page", formData));

}


and then in the SQL I am doing this

String MEDDOC_INSERT = " " + "INSERT INTO MEDDOC (doc_title,doc_date,doc_type,doc_file_type,doc_file,id) VALUES ( :{page.nameDocument},:{page.dateAdd},:{page.typeDocument},'doc',";

but his is generating an other error :

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[B@5ccecbb7 ,1)' at line 1 [translator=org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator, user=anis, statement=SQL with binds:
INSERT INTO MEDDOC(MEDDOC_TITLE, MEDDOC_DATE, MEDDOC_TYPE, MEDDOC_FILE_TYPE, MEDDOC_FILE, PATIENT_ID)
VALUES (:{page.nomDocument}, :{page.dateAjout}, :{page.typeDocuement}, 'doc', /*XXX unexpected token: [*/B@5CCECBB7, 1)
IN :{page.nomDocument} => ? [VARCHAR KPI DGE.xlsx]
IN :{page.dateAjout} => ? [TIMESTAMP 2018-09-24 17:01:53.354]
IN :{page.typeDocuement} => ? [VARCHAR application/vnd.openxmlformats-officedocument.spreadsheetml.sheet]

more precisely you see the server version for the right syntax to use near '[B@5ccecbb7

is is not recognising the bytes or not accepting them , I use file.getContent().

If you have an example of using the NVPair because I did not understood what do you mean by using the the constructor with byte[].
Kind Regards

Re: SqlBind error [message #1795534 is a reply to message #1795521] Mon, 24 September 2018 19:18 Go to previous messageGo to next message
Patrick Baenziger is currently offline Patrick BaenzigerFriend
Messages: 96
Registered: September 2011
Member
What I meant: You can pass additional binds (NVPairs) to the insert or select statement, like you did with the formdata.
Pass the document content (byte[]) as the value to the NVPair constructor, that is how you can bind the content of the document.

To rewrite your code:


  • Note that I used "patientId" to fill the "id" such that it should compile.
  • Bind additional NVPairs instead of using string concatenation
  • Pass the fileByte byte array to the NVPair



@Override
public void storeMedDoc(MedDocTable formData, Integer patientID,
byte[] fileByte) {

  String MEDDOC_INSERT = "INSERT INTO MEDDOC (doc_title,doc_date,doc_type,doc_file_type,doc_file,id) VALUES ( :{page.nameDocument}, :{page.dateAdd}, :{page.typeDocument}, 'doc', :{docData}, :{id})";

  SQL.insert(SQLs.MEDDOC_INSERT, new NVPair("page", formData), new NVPair("docData", fileByte), new NVPair("id", patientId);

}


Side note: The "[B@..." string you saw was the result of the string concatenation of the Insert string and the byte array.

BIG security note: String concatenation in SQL statements makes you very vulnerable to SQL injection. Please use the binds - which you already started to use - for all dynamic parts of your query to prevent this!
Re: SqlBind error [message #1795563 is a reply to message #1795534] Tue, 25 September 2018 10:12 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello,
Thanks for the answer, it is working for the insert and now for the select I am doing this

SQL.select(SQLs.MEDDOC_SELECT + SQLs.MEDDOC_SELECT_INTO, new NVPair("patient_ID", formData.getPatientID()),new NVPair(new BinaryResource("fileBinary")),formData.getMedDocTable());

I dont know how to bind the byte[] and pass it to new BinaryResource constructor !

Kind Regards
Anis
Re: SqlBind error [message #1795574 is a reply to message #1795563] Tue, 25 September 2018 12:18 Go to previous messageGo to next message
Stephan Merkli is currently offline Stephan MerkliFriend
Messages: 40
Registered: April 2012
Member
Patrick already mentioned a possible solution in his post

Kind regards
Stephan
Re: SqlBind error [message #1795720 is a reply to message #1795574] Thu, 27 September 2018 09:30 Go to previous message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Thanks I applyied Patrick's solution and it is working, :)
Previous Topic:EclipseCon Europe - Userconf
Next Topic:Witch Field supports Camera Capture
Goto Forum:
  


Current Time: Thu Mar 28 19:45:28 GMT 2024

Powered by FUDForum. Page generated in 0.03204 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top