Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PgSQLXML setCharacterStream() results in null value #731

Closed
felipe-louzas opened this issue Jan 14, 2017 · 2 comments
Closed

PgSQLXML setCharacterStream() results in null value #731

felipe-louzas opened this issue Jan 14, 2017 · 2 comments

Comments

@felipe-louzas
Copy link

When using the setCharacterStream() method in the PgSQLXML class, the value sent to the database will be null.

The PgSQLXML.setCharacterStream() method needs to be altered to the following:

public synchronized Writer setCharacterStream() throws SQLException {
    checkFreed();
    initialize();
    _active = true; //this line needs to be added
    _stringWriter = new StringWriter();
    return _stringWriter;
  }

Details:

The PgSQLXML.setCharacterStream() code does not set the _active variable to true:

public synchronized Writer setCharacterStream() throws SQLException {
    checkFreed();
    initialize();
    _stringWriter = new StringWriter();
    return _stringWriter;
  }

When the PgPreparedStatement reads the SQLXML object, it calls the getString() method:

  public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
    checkClosed();
    if (xmlObject == null || xmlObject.getString() == null) {
      setNull(parameterIndex, Types.SQLXML);
    } else {
      setString(parameterIndex, xmlObject.getString(), Oid.XML);
    }
  }

This in turn will call PgSQLXML.ensureInitialized() to move the data to the _data variable.

 public synchronized String getString() throws SQLException {
    checkFreed();
    ensureInitialized();
    return _data;
  }

However the PgSQLXML.ensureInitialized() method will simply return when _active is false;

 private void ensureInitialized() throws SQLException {
 // [...]
    // Is anyone loading data into us at the moment?
    if (!_active) {
      return;
    }
// [...]
@vlsi
Copy link
Member

vlsi commented Jan 20, 2017

@felipe-louzas , thanks for the analysis. Would you please prepare a pull request & test to fix the issue?

davecramer added a commit that referenced this issue Nov 15, 2019
* fix: PgSQLXML setCharacterStream() results in null value fixes Issue #731
@davecramer
Copy link
Member

Fixed in #1608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants