You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Anders Heintz <he...@include-datorkonsulter.se> on 2000/03/06 12:49:26 UTC

Problems with Cocoon 1.7 sql processing

Hello

This might not be sent to the correct mailing list,
but here it is anyway.

I upgraded from Cocoon 1.6 to 1.7 and I'm having
troubles with sql processing. I use mysql 3.22 and
the org.gjt.mm.mysql jdbc driver. 
When I am trying to extract data from the database,
VARCHAR and INT fields are correct, but TEXT and BLOB
fields are not. Seems like the values returned are 
references, they are definitely not strings.

I've been looking through the sql processing source,
but I couldn't find anything doing this.

I'd appreciate any help!

Regards
......../Anders Heintz

Re: Problems with Cocoon 1.7 sql processing

Posted by Donald Ball <ba...@webslingerZ.com>.
On Mon, 6 Mar 2000, Anders Heintz wrote:

> Hello again...
> 
> > When I am trying to extract data from the database,
> > VARCHAR and INT fields are correct, but TEXT and BLOB
> > fields are not. Seems like the values returned are
> > references, they are definitely not strings.
> 
> Solved this by changing from a ResultSet.getObject() call
> to a  ResultSet.getString() in SQLProcessor.processQuery.
> I would appreciate comments, will anything malfunction due
> to this change?

It will certainly break things on some other databases. Jeez, JDBC sucks
in terms of cross-driver compatibility. I think the proper thing to do in
this instance would be to check to see if the Object is a 'reference' (I
think you mean a Reader or InputStream?) and if so, to serialize that to a
String. That should ensure maximum cross-driver compatibility. Do you
think that'd work? If so, can I beg for a patch?

- donald


Re: Problems with Cocoon 1.7 sql processing

Posted by Anders Heintz <he...@include-datorkonsulter.se>.
Hello again...

> When I am trying to extract data from the database,
> VARCHAR and INT fields are correct, but TEXT and BLOB
> fields are not. Seems like the values returned are
> references, they are definitely not strings.

Solved this by changing from a ResultSet.getObject() call
to a  ResultSet.getString() in SQLProcessor.processQuery.
I would appreciate comments, will anything malfunction due
to this change?

I'm enclosing the modified code section with my change
marked (line 271 in SQLProcessor.java).

Regards

......./Anders Heintz



/* ********** LINE: 260 END OF CODE SECTION ************* */

ColumnFormatter formatter = new ColumnFormatter(query_element);
while (rs.next()) {
  if (create_row_elements) {
    row_element = Utils.createElement(document,namespace,
                                      row_element_name);
    row_node = row_element;
    if (create_id_attribute && id_attribute_column_index == -1) {
      row_element.setAttribute(id_attribute,"" + count);
    }
  }

  for (int i=0; i<columns.length; i++) {

/* **************** START OF CHANGES ****************** */

    Object value = rs.getString(i+1);

/* ***************** END OF CHANGES ******************* */

    if (create_row_elements && create_id_attribute
        && id_attribute_column_index == i) {
      row_element.setAttribute(id_attribute, value.toString());
      continue;
    }
    if (value == null && null_mode == OMIT_NULLS) continue;
    column_element = Utils.createElement(document,namespace,
                                         columns[i].name);
    if (value == null && null_mode == ATTRIBUTE_NULLS) {
      column_element.setAttribute("NULL","YES");
      column_element.appendChild(document.createTextNode(""));
    } else {
   formatter.addColumnNode(document,column_element,
                              columns[i],value,i+1);
    }
    row_node.appendChild(column_element);
  }
  if (create_row_elements) results_node.appendChild(row_node);
  if (count-skip_rows == max_rows-1) break;
  count++;
}
rs.close();

/* ********** LINE: 291 END OF CODE SECTION ************* */