Ejemplo n.º 1
0
  protected SQLException readError() throws SQLException {
    SQLException ex = null;
    int status = msg.readInt();
    String sqlState = msg.readString(5);
    byte type = msg.readByte();
    String message = msg.readString();

    switch (type) {
      case MSG_ET_ERR:
        if (trace.enabled(1))
          trace.write(
              tr_id
                  + ": Received error '"
                  + sqlState
                  + "' 0x"
                  + Integer.toHexString(status)
                  + " -- "
                  + message);

        ex = SqlExFactory.get(message, sqlState, status);
        break;

      case MSG_ET_WRN:
        if (trace.enabled(1))
          trace.write(
              tr_id
                  + ": Received warning '"
                  + sqlState
                  + "' 0x"
                  + Integer.toHexString(status)
                  + " -- "
                  + message);

        setWarning(new SqlWarn(message, sqlState, status));
        break;

      case MSG_ET_MSG:
        if (trace.enabled(3))
          trace.write(
              tr_id
                  + ": Received message '"
                  + sqlState
                  + "' 0x"
                  + Integer.toHexString(status)
                  + " -- "
                  + message);

        setWarning(new SqlWarn(message, sqlState, status));
        break;

      case MSG_ET_XA:
        if (trace.enabled(1)) trace.write(tr_id + ": Received XA error " + status);

        ex = new XaEx(status);
        break;
    }

    return (ex);
  } // readError
Ejemplo n.º 2
0
  protected JdbcRSMD readResults() throws SQLException, XaEx {
    SQLException ex_list = null;
    XaEx xa_list = null;
    JdbcRSMD rsmd = null;
    byte msg_id;

    try {
      msg_process_loop:
      do {
        switch (msg_id = msg.receive()) {
          case MSG_DESC:
            rsmd = readDesc();
            break;

          case MSG_DATA:
            if (readData()) break msg_process_loop; // interrupt
            break;

          case MSG_INFO:
            readInfo();
            break;

          case MSG_ERROR:
            SQLException ex = readError();

            if (ex != null)
              if (ex instanceof XaEx) xa_list = (XaEx) ex; /* Save only last error */
              else if (ex_list == null) ex_list = ex;
              else ex_list.setNextException(ex);
            break;

          case MSG_RESULT:
            if (readResult()) break msg_process_loop; // interrupt
            break;

          default:
            if (trace.enabled(1)) trace.write(tr_id + ": Invalid message ID " + msg_id);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
        }

        if (msg.moreData()) {
          if (trace.enabled(1)) trace.write(tr_id + ": end-of-message not reached");
          throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
        }
      } while (msg.moreMessages());
    } catch (SQLException ex) {
      if (ex_list == null) ex_list = ex;
      else ex_list.setNextException(ex);
    }

    if (xa_list != null) throw xa_list;
    if (ex_list != null) throw ex_list;
    return (rsmd);
  } // readResults
Ejemplo n.º 3
0
  protected void writeQueryText(String text) throws SQLException {
    byte ba[];

    try {
      ba = msg.getCharSet().getBytes(text);
    } catch (Exception ex) {
      throw SqlExFactory.get(ERR_GC401E_CHAR_ENCODE);
    } // Should not happen!

    for (int offset = 0; offset < ba.length; ) {
      int length = Math.min(ba.length - offset, 32000);
      msg.write(MSG_QP_QTXT);
      msg.write((short) length);
      msg.write(ba, offset, length);
      offset += length;
    }

    return;
  }
Ejemplo n.º 4
0
  protected void readInfo() throws SQLException {
    while (msg.moreData()) {
      short param_id = msg.readShort();
      short param_len = msg.readShort();

      switch (param_id) {
        case MSG_IP_TRACE:
          {
            if (trace.enabled() || conn.dbms_log.enabled()) {
              String txt = msg.readString(param_len);
              trace.log("DBMS TRACE: " + txt);
              conn.dbms_log.write(txt);
            } else msg.skip(param_len);
            break;
          }

        default:
          if (trace.enabled(1)) trace.write(tr_id + ": Invalid info param ID " + param_id);
          throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
      }
    }

    return;
  } // readInfo
Ejemplo n.º 5
0
  protected boolean readResult() throws SQLException {
    while (msg.moreData()) {
      short param_id = msg.readShort();
      short param_len = msg.readShort();

      switch (param_id) {
        case MSG_RP_ROWCOUNT:
          switch (param_len) {
            case 1:
              rslt_val_rowcnt = msg.readByte();
              break;
            case 2:
              rslt_val_rowcnt = msg.readShort();
              break;
            case 4:
              rslt_val_rowcnt = msg.readInt();
              break;

            default:
              if (trace.enabled(1)) trace.write(tr_id + ": Invalid row count length: " + param_len);
              throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_items |= RSLT_ROW_CNT;
          break;

        case MSG_RP_XACT_END:
          if (param_len > 0) {
            if (trace.enabled(1)) trace.write(tr_id + ": Invalid XACT param length: " + param_len);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_flags |= MSG_RF_XACT_END;
          conn.endXact();
          break;

        case MSG_RP_STMT_ID:
          if (param_len != 8) {
            if (trace.enabled(1)) trace.write(tr_id + ": Invalid stmt ID length: " + param_len);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_val_stmt = (((long) msg.readInt()) << 32) | (((long) msg.readInt()) & 0xffffffff);
          rslt_items |= RSLT_STMT_ID;
          break;

        case MSG_RP_FETCH_LIMIT:
          switch (param_len) {
            case 1:
              rslt_val_fetch = msg.readByte();
              break;
            case 2:
              rslt_val_fetch = msg.readShort();
              break;
            case 4:
              rslt_val_fetch = msg.readInt();
              break;

            default:
              if (trace.enabled(1))
                trace.write(tr_id + ": Invalid fetch limit length: " + param_len);
              throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_items |= RSLT_PREFETCH;
          break;

        case MSG_RP_EOD:
          if (param_len != 0) {
            trace.write(tr_id + ": Invalid EOD length: " + param_len);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_flags |= MSG_RF_EOD;
          break;

        case MSG_RP_PROC_RESULT:
          switch (param_len) {
            case 1:
              setProcResult((int) msg.readByte());
              break;
            case 2:
              setProcResult((int) msg.readShort());
              break;
            case 4:
              setProcResult(msg.readInt());
              break;

            default:
              if (trace.enabled(1))
                trace.write(tr_id + ": Invalid proc result length: " + param_len);
              throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }
          break;

        case MSG_RP_READ_ONLY:
          if (param_len != 0) {
            trace.write(tr_id + ": Invalid READ_ONLY length: " + param_len);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_flags |= MSG_RF_READ_ONLY;
          break;

        case MSG_RP_TBLKEY:
          if (param_len != MSG_RPV_TBLKEY_LEN) {
            if (trace.enabled(1)) trace.write(tr_id + ": Invalid table key length: " + param_len);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          if (rslt_val_tblkey == null) rslt_val_tblkey = new byte[param_len];
          msg.readBytes(rslt_val_tblkey, 0, param_len);
          rslt_items |= RSLT_TBLKEY;
          break;

        case MSG_RP_OBJKEY:
          if (param_len != MSG_RPV_OBJKEY_LEN) {
            if (trace.enabled(1)) trace.write(tr_id + ": Invalid object key length: " + param_len);
            throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          if (rslt_val_objkey == null) rslt_val_objkey = new byte[param_len];
          msg.readBytes(rslt_val_objkey, 0, param_len);
          rslt_items |= RSLT_OBJKEY;
          break;

        case MSG_RP_FLAGS:
          {
            int flags;

            switch (param_len) {
              case 1:
                flags = (int) msg.readByte();
                break;
              case 2:
                flags = (int) msg.readShort();
                break;
              case 4:
                flags = msg.readInt();
                break;

              default:
                if (trace.enabled(1))
                  trace.write(tr_id + ": Invalid result flags length: " + param_len);
                throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
            }

            rslt_flags |= flags;
            if ((flags & MSG_RF_XACT_END) != 0) conn.endXact();
            break;
          }

        case MSG_RP_ROW_STATUS:
          switch (param_len) {
            case 1:
              rslt_val_rowstat = msg.readByte();
              break;
            case 2:
              rslt_val_rowstat = msg.readShort();
              break;
            case 4:
              rslt_val_rowstat = msg.readInt();
              break;

            default:
              if (trace.enabled(1))
                trace.write(tr_id + ": Invalid row status length: " + param_len);
              throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_items |= RSLT_ROW_STAT;
          break;

        case MSG_RP_ROW_POS:
          switch (param_len) {
            case 1:
              rslt_val_rowpos = msg.readByte();
              break;
            case 2:
              rslt_val_rowpos = msg.readShort();
              break;
            case 4:
              rslt_val_rowpos = msg.readInt();
              break;

            default:
              if (trace.enabled(1))
                trace.write(tr_id + ": Invalid row position length: " + param_len);
              throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
          }

          rslt_items |= RSLT_ROW_POS;
          break;

        default:
          if (trace.enabled(1)) trace.write(tr_id + ": Invalid result param ID " + param_id);
          throw SqlExFactory.get(ERR_GC4002_PROTOCOL_ERR);
      }
    }

    return (false);
  } // readResult