Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    GROUP_CONCAT in sql returns byte[] in DMI method instead of String

    Hello,

    Using: (v8.3p_2012-11-23/PowerEdition Deployment 2012-11-23)

    I have a DMI method, that fetches some rows, with the following MySQL select clause:

    Code:
    <selectClause>Order__orderedProducts_Product.orderedProducts_id, GROUP_CONCAT(ProductOptionValue.ProductOptionValue_id) as selectedOptions</selectClause>
    The query works. But when I parse results like this, it thinks that the 'r.get("selectedOptions")' is of type byte[]:
    Code:
    DSRequest req2 = new DSRequest("Order__orderedProducts_Product","fetch");
    Map<String,Object> crit = new HashMap<String,Object>();
    //set criteria
    crit.put("Order__id", req.getFieldValue("Order__id"));
    crit.put("Product_id", req.getFieldValue("Product_id")); 
    req2.setCriteria(crit);
    DSResponse resp = req2.execute();
    List data = resp.getDataList();
    		
    if(data == null || data.size() == 0)
    	return null;
    		
    for(Object o : data){
    	Map r = (Map) o;
             //why is this a byte[]? A (String) cast instead of byte[] cast gave class cast exception
    	byte[] j =  (byte[]) r.get("selectedOptions");
    }
    Now I have to work-around this by doing:
    Code:
    byte[] j =  (byte[]) r.get("selectedOptions");
    String s = new String(j);
    Which works, but still I thought maybe it is not what you guys intended (ie. it should be String?)

    #2
    This probably just reflects what MySQL is returning to us from the JDBC driver - most likely, for whatever reason they've chosen to provide a byte[] when you use GROUP_CONCAT.

    However, what's the declared type of the field? If you've declared it as type "text", you should have seen the byte[] converted for you.

    Comment


      #3
      Yeah it was text, i checked that. Sorry, forgot to mention that.

      Comment


        #4
        OK, we'd recommend keeping your workaround in place. We probably won't try to address this at a framework level, as it's quite obscure, arguably a JDBC driver bug, and any attempt to get around it might have unexpected side effects.

        Comment

        Working...
        X