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

📄 tdsresultsetmetadata.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//
// Copyright 1998 CDS Networks, Inc., Medford Oregon
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
//    must display the following acknowledgement:
//      This product includes software developed by CDS Networks, Inc.
// 4. The name of CDS Networks, Inc.  may not be used to endorse or promote
//    products derived from this software without specific prior
//    written permission.
//
// THIS SOFTWARE IS PROVIDED BY CDS NETWORKS, INC. ``AS IS'' AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED.  IN NO EVENT SHALL CDS NETWORKS, INC. BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//


package net.sourceforge.jtds.jdbc;

import java.sql.*;


/**
 * A ResultSetMetaData object can be used to find out about the types
 * and properties of the columns in a ResultSet.
 *
 * @author Craig Spannring
 * @version $Id: TdsResultSetMetaData.java,v 1.1 2002/10/14 10:48:59 alin_sinpalean Exp $
 */
public class TdsResultSetMetaData implements java.sql.ResultSetMetaData
{
   public static final String cvsVersion = "$Id: TdsResultSetMetaData.java,v 1.1 2002/10/14 10:48:59 alin_sinpalean Exp $";

   /**
    * Does not allow NULL values.
    */
   public static final int columnNoNulls = 0;

   /**
    * Allows NULL values.
    */
   public static final int columnNullable = 1;

   /**
    * Nullability unknown.
    */
   public static final int columnNullableUnknown = 2;

   private Columns  columnsInfo;


   public TdsResultSetMetaData(Columns columns_)
   {
      columnsInfo = columns_;
   }

   /**
    * What's a column's table's catalog name?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return column name or "" if not applicable.
    * @exception SQLException if a database-access error occurs.
    */
   public String getCatalogName(int column) throws SQLException
   {
      String res = columnsInfo.getCatalog(column);
      return res==null ? "" : res;
   }

   /**
    * What's the number of columns in the ResultSet?
    *
    * @return the number
    * @exception SQLException if a database-access error occurs.
    */
   public int getColumnCount() throws SQLException
   {
      return columnsInfo.fakeColumnCount();
   }

   /**
    * What's the column's normal max width in chars?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return max width
    * @exception SQLException if a database-access error occurs.
    */
   public int getColumnDisplaySize(int column) throws SQLException
   {
      return columnsInfo.getDisplaySize(column);
   }

   /**
    * What's the suggested column title for use in printouts and
    * displays?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return true if so
    * @exception SQLException if a database-access error occurs.
    */
   public String getColumnLabel(int column) throws SQLException
   {
      return columnsInfo.getLabel(column);
   }

   /**
    * What's a column's name?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return column name
    * @exception SQLException if a database-access error occurs.
    */
   public String getColumnName(int column) throws SQLException
   {
      return columnsInfo.getName(column);
   }

   /**
    * What's a column's SQL type?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return SQL type
    * @exception SQLException if a database-access error occurs.
    */
   public int getColumnType(int column) throws SQLException
   {
      switch( columnsInfo.getNativeType(column) )
      {
         case Tds.SYBNCHAR:
         case Tds.SYBNTEXT:
         case Tds.SYBNVARCHAR:
         case Tds.SYBUNIQUEID:
            return Types.OTHER;
         default:
            return columnsInfo.getJdbcType(column);
      }
   }

   /**
    * What's a column's data source specific type name?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return type name
    * @exception SQLException if a database-access error occurs.
    */
   public String getColumnTypeName(int column) throws SQLException
   {
      if( columnsInfo.isAutoIncrement(column).booleanValue() )
         return getCleanTypeName(column)+" identity";
      return getCleanTypeName(column);
   }

   /**
    * Get the native data type name (i.e. without 'identity').
    */
   private String getCleanTypeName(int column) throws SQLException
   {
      switch (columnsInfo.getNativeType(column))
      {
         case Tds.SYBVOID: return "void";
         case Tds.SYBIMAGE: return "image";
         case Tds.SYBTEXT: return "text";
         case Tds.SYBUNIQUEID: return "uniqueidentifier";
         case Tds.SYBVARBINARY: return "varbinary";
         case Tds.SYBVARCHAR: return "varchar";
         case Tds.SYBBINARY: return "binary";
         case Tds.SYBCHAR: return "char";
         case Tds.SYBINT1: return "tinyint";
         case Tds.SYBBIT: case Tds.SYBBITN: return "bit";
         case Tds.SYBINT2: return "smallint";
         case Tds.SYBINT4: return "int";
         case Tds.SYBDATETIME4: return "smalldatetime";
         case Tds.SYBREAL: return "real";
         case Tds.SYBMONEY: return "money";
         case Tds.SYBDATETIME: return "datetime";
         case Tds.SYBFLT8: return "float";
         case Tds.SYBDECIMAL: return "decimal";
         case Tds.SYBNUMERIC: return "numeric";
         case Tds.SYBMONEY4: return "smallmoney";
         case Tds.SYBNCHAR: return "nchar";
         case Tds.SYBNTEXT: return "ntext";
         case Tds.SYBNVARCHAR: return "nvarchar";
         case Tds.SYBSMALLMONEY: return "smallmoney";
         case Tds.SYBINTN:
         {
            switch( columnsInfo.getBufferSize(column) )
            {
                case 1: return "tinyint";
                case 2: return "smallint";
                case 4: return "int";
            }
            break;
         }
         case Tds.SYBFLTN:
         {
            switch( columnsInfo.getBufferSize(column) )
            {
                case 4: return "real";
                case 8: return "float";
            }
            break;
         }
         case Tds.SYBMONEYN:
         {
            switch( columnsInfo.getBufferSize(column) )
            {
                case 4: return "smallmoney";
                case 8: return "money";
            }
            break;
         }
         case Tds.SYBDATETIMN:
         {
            switch( columnsInfo.getBufferSize(column) )
            {
                case 4: return "smalldatetime";
                case 8: return "datetime";
            }
            break;
         }
      }

      throw new SQLException("Unknown native type for column "+column+": "
         +columnsInfo.getNativeType(column));
   }

   /**
    * What's a column's number of decimal digits?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return precision
    * @exception SQLException if a database-access error occurs.
    */
   public int getPrecision(int column) throws SQLException
   {
      return columnsInfo.getPrecision(column);
   }

   /**
    * What's a column's number of digits to right of the decimal point?
    *
    * @param column the first column is 1, the second is 2, ...
    * @return scale
    * @exception SQLException if a database-access error occurs.

⌨️ 快捷键说明

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