⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tds.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            }

            PacketResult res = processSubPacket();

            if( res instanceof PacketOutputParamResult && statement!=null &&
                statement instanceof CallableStatement_base )
            {
                ((CallableStatement_base)statement).addOutputParam(
                    ((PacketOutputParamResult)res).getValue() );
            }
            else if( res instanceof PacketEndTokenResult )
            {
                if( ((PacketEndTokenResult)res).wasCanceled() )
                    warningChain.addException(
                        new SQLException("Query was canceled or timed out."));
            }
            else if( res instanceof PacketMsgResult )
                warningChain.addOrReturn( (PacketMsgResult)res );
        }
    }

    EncodingHelper getEncoder()
    {
        return encoder;
    }

    /**
     *  Accessor method to determine the TDS level used.
     *
     *@return    TDS42, TDS50, or TDS70.
     */
    int getTdsVer()
    {
        return tdsVer;
    }


    /**
     *  Return the name that this database server program calls itself.
     *
     *@return    The DatabaseProductName value
     */
    String getDatabaseProductName()
    {
        return databaseProductName;
    }


    /**
     * Return the version that this database server program identifies itself with.
     *
     * @return    The DatabaseProductVersion value
     */
    String getDatabaseProductVersion()
    {
        return databaseProductVersion;
    }

    /**
     * Return the major version that this database server program identifies itself with.
     *
     * @return    The databaseMajorVersion value
     */
    int getDatabaseMajorVersion()
    {
        return databaseMajorVersion;
    }



   /**
    * Process an output parameter subpacket.
    * <p>
    * This routine assumes that the TDS_PARAM byte has already
    * been read.
    *
    * @return a <code>PacketOutputParamResult</code> wrapping an output
    *         parameter
    *
    * @exception net.sourceforge.jtds.jdbc.TdsException
    * @exception java.io.IOException
    * Thrown if some sort of error occured reading bytes from the network.
    */
   private PacketOutputParamResult processOutputParam()
      throws net.sourceforge.jtds.jdbc.TdsException, java.io.IOException
   {
      getSubPacketLength(); // Packet length
      comm.getString(comm.getByte() & 0xff); // Column name
      comm.skip(5);

      byte colType = comm.getByte();

      /** @todo Refactor to combine this code with that in getRow() */
      Object element;
      switch (colType)
      {
         case SYBINTN:
         {
            comm.getByte(); // Column size
            element = getIntValue(colType);
            break;
         }
         case SYBINT1:
         case SYBINT2:
         case SYBINT4:
         {
            element = getIntValue(colType);
            break;
         }
         case SYBIMAGE:
         {
            comm.getByte(); // Column size
            element = getImageValue();
            break;
         }
         case SYBTEXT:
         {
            comm.getByte(); // Column size
            element = getTextValue(false);
            break;
         }
         case SYBNTEXT:
         {
            comm.getByte(); // Column size
            element = getTextValue(true);
            break;
         }
         case SYBCHAR:
         case SYBVARCHAR:
         {
            comm.getByte(); // Column size
            element = getCharValue(false, true);
            break;
         }
         case SYBBIGVARBINARY:
         {
            comm.getTdsShort(); // Column size
            int len = comm.getTdsShort();
            // if (tdsVer == Tds.TDS70 && len == 0xffff)
            element = comm.getBytes(len, true);
            break;
         }
         case SYBBIGVARCHAR:
         {
            comm.getTdsShort(); // Column size
            element = getCharValue(false, false);
            break;
         }
         case SYBNCHAR:
         case SYBNVARCHAR:
         {
            comm.getByte(); // Column size
            element = getCharValue(true, true);
            break;
         }
         case SYBREAL:
         {
            element = readFloatN(4);
            break;
         }
         case SYBFLT8:
         {
            element = readFloatN(8);
            break;
         }
         case SYBFLTN:
         {
            comm.getByte(); // Column size
            int actual_size = comm.getByte();
            element = readFloatN(actual_size);
            break;
         }
         case SYBSMALLMONEY:
         case SYBMONEY:
         case SYBMONEYN:
         {
            comm.getByte(); // Column size
            element = getMoneyValue(colType);
            break;
         }
         case SYBNUMERIC:
         case SYBDECIMAL:
         {
            comm.getByte(); // Column size
            comm.getByte(); // Precision
            int scale = comm.getByte();
            element = getDecimalValue(scale);
            break;
         }
         case SYBDATETIMN:
         {
            comm.getByte(); // Column size
            element = getDatetimeValue(colType);
            break;
         }
         case SYBDATETIME4:
         case SYBDATETIME:
         {
            element = getDatetimeValue(colType);
            break;
         }
         case SYBVARBINARY:
         case SYBBINARY:
         {
            comm.getByte(); // Column size
            int len = (comm.getByte() & 0xff);
            element = comm.getBytes(len, true);
            break;
         }
         case SYBBITN:
         {
            comm.getByte(); // Column size
            if (comm.getByte() == 0)
               element = null;
            else
               element = new Boolean((comm.getByte()!=0) ? true : false);
            break;
         }
         case SYBBIT:
         {
            int column_size = comm.getByte();
            element = new Boolean((column_size != 0) ? true : false);
            break;
         }
         case SYBUNIQUEID:
         {
            int len = comm.getByte() & 0xff;
            element = len==0 ? null : TdsUtil.uniqueIdToString(comm.getBytes(len, false));
            break;
         }
         default:
         {
            element = null;
            throw new TdsNotImplemented("Don't now how to handle " +
                                        "column type 0x" +
                                        Integer.toHexString(colType));
         }
      }

      return new PacketOutputParamResult(element);
   }

    /**
     *  Process a subpacket reply <p>
     *
     *  <b>Note-</b> All subpackets must be processed through here. This is the
     *  only routine has the proper locking to support the cancel method in the
     *  Statement class. <br>
     *
     *
     *@return                                            packet subtype the was
     *      processed.
     *@exception  TdsUnknownPacketSubType                Description of
     *      Exception
     *@exception  java.io.IOException                    Description of
     *      Exception
     *@exception  net.sourceforge.jtds.jdbc.TdsException  Description of
     *      Exception
     */
    PacketResult processSubPacket()
             throws TdsUnknownPacketSubType,
            java.io.IOException,
            net.sourceforge.jtds.jdbc.TdsException,
            SQLException
    {
        return processSubPacket(null);
    }


    /**
     *  Process a subpacket reply <p>
     *
     *  <b>Note-</b> All subpackets must be processed through here. Only this
     *  routine has the proper locking to support the cancel method in the
     *  Statement class. <br>
     *
     *
     *@param  context                                    Description of
     *      Parameter
     *@return                                            packet subtype the was
     *      processed.
     *@exception  TdsUnknownPacketSubType                Description of
     *      Exception
     *@exception  java.io.IOException                    Description of
     *      Exception
     *@exception  net.sourceforge.jtds.jdbc.TdsException  Description of
     *      Exception
     */
    synchronized PacketResult processSubPacket(Context context)
             throws TdsUnknownPacketSubType,
            SQLException,
            java.io.IOException,
            net.sourceforge.jtds.jdbc.TdsException
    {
        // NOTE!!! Before adding anything to this list you must
        // consider the ramifications to the the handling of cancels
        // as implemented by the CancelController class.
        //
        // The CancelController class might implicitly assume it can call
        // processSubPacket() whenever it is looking for a cancel
        // acknowledgment.  It assumes that any results of the call
        // can be discarded.

        PacketResult result = null;

        moreResults = false;

        byte packetSubType = comm.getByte();

        if( Logger.isActive() )
            Logger.println("processSubPacket: " +
                    Integer.toHexString(packetSubType & 0xFF) + " " +
                    "moreResults: " + moreResults());

        switch (packetSubType) {
            case TDS_ENVCHANGE:
            {
                result = processEnvChange();
                break;
            }
            case TDS_ERROR:
            case TDS_INFO:
            case TDS_MSG50_TOKEN:
            {
                result = processMsg(packetSubType);
                break;
            }
            case TDS_PARAM:
            {
              result = processOutputParam();
              break;
            }
            case TDS_LOGINACK:
            {
                result = processLoginAck();
                break;
            }
            case TDS_RETURNSTATUS:
            {
                result = processRetStat();
                break;
            }
            case TDS_PROCID:
            {
                result = processProcId();
                break;
            }
            case TDS_DONE:
            case TDS_DONEPROC:
            case TDS_DONEINPROC:
            {
                result = processEndToken(packetSubType);
                moreResults2 = ((PacketEndTokenResult) result).moreResults();
                break;
            }
            case TDS_COL_NAME_TOKEN:
            {
                result = processColumnNames();
                break;
            }
            case TDS_COL_INFO_TOKEN:
            {
                result = processColumnInfo();
                break;
            }
            case TDS_UNKNOWN_0xA5:
            case TDS_UNKNOWN_0xA7:
            case TDS_UNKNOWN_0xA8:
            {
                // XXX Need to figure out what this packet is
                comm.skip(comm.getTdsShort());
                result = new PacketUnknown(packetSubType);
                break;
            }
            case TDS_TABNAME:
            {
                result = processTabName();
                break;
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -