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

📄 picoresultset.java

📁 picoSQL is a SQL-based, multi-user, client/server RDBMS, released under the GPL
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*_____       _    _    Corso   Italia,  178(_|__   .  (_   |_|_  56125           Pisa(_|_) |)|(()_)()| |   tel.  +39  050 46380  |   |               picosoft@picosoft.it Copyright (C) Picosoft s.r.l. 1995-2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/package IT.picosoft.jdbc;import java.io.InputStream;import java.io.Reader;import java.math.BigDecimal;import java.sql.*;import java.util.*;public class PicoResultSet /* extends PicoDbObject */   implements ResultSet{   protected PicoDbApi odbcApi;   protected PicoConnection con;   private OdbcStatement hStmt;   protected SQLWarning lastWarning;   protected PicoBoundCol boundCols[];   protected int numberOfCols;   protected int numResultCols;   protected int firstPseudoCol;   protected int lastPseudoCol;   protected PicoPseudoCol pseudoCols[];   protected int colMappings[];   protected ResultSetMetaData rsmd;   private Hashtable colNameToNum;   private Hashtable colNumToName;   private boolean lastColumnNull;   private boolean closed;   private int sqlTypeColumn;   private boolean freed;   protected PicoStatement ownerStatement;   protected java.lang.Object data[];   private String rmDot (String num) {      int i;      if ((i = num.indexOf ('.')) >= 0)         num = num.substring(0, i);      return num;   }   private java.lang.Object getData (int nCol, Class c) throws SQLException {      java.lang.Object Return = null;      if (data == null) {         int allCol;         if (firstPseudoCol > 0)            allCol = firstPseudoCol - 1;         else            allCol = getColumnCount();         data = odbcApi.SQLGetAllData (getHSTMT(), boundCols);      }      if (nCol > data.length) {         Return.toString();         if (c == Double.class)            Return = odbcApi.SQLGetDataDouble(getHSTMT(), nCol);         else if (c == Float.class)            Return = odbcApi.SQLGetDataFloat(getHSTMT(), nCol);         else if (c == Integer.class)            Return = odbcApi.SQLGetDataInteger(getHSTMT(), nCol);         else if (c == Timestamp.class)            Return = odbcApi.SQLGetDataTimestamp(getHSTMT(), nCol);         else if (c == byte[].class)            Return = odbcApi.SQLGetDataBytes(getHSTMT(), nCol);         else            Return = odbcApi.SQLGetDataString(getHSTMT(), nCol, 256, false);      } else {         Return = data[nCol - 1];         if (Return != null) {            if (c == String.class) {               if (!(Return instanceof String))                  Return = Return.toString();            } else if (c == Double.class) {               if (!(Return instanceof Double))                  Return = new Double(Return.toString());            } else if (c == Float.class) {               if (!(Return instanceof Float))                  Return = new Float(Return.toString());            } else if (c == Integer.class) {               if (!(Return instanceof Integer))                  Return = new Integer(rmDot(Return.toString()));            } else if (c == Timestamp.class) {               if (!(Return instanceof Timestamp))                  Return = Timestamp.valueOf(Return.toString());            } else if (c == java.sql.Date.class) {               if (!(Return instanceof java.sql.Date))                  Return = java.sql.Date.valueOf(Return.toString());            } else if (c == Time.class) {               if (!(Return instanceof Time))                  Return = Time.valueOf(Return.toString());            }         }      }      return Return;   }   protected OdbcStatement getHSTMT() {      if (ownerStatement != null)         return ownerStatement.getHSTMT();      else         return hStmt;   }   private PicoResultSet (PicoDbApi api, PicoConnection con)                                             throws SQLException {      odbcApi = api;      this.con = con;      hStmt = null;      lastWarning = null;      numResultCols = -1;      lastColumnNull = false;      ownerStatement = null;   }   public PicoResultSet (PicoDbApi api, OdbcStatement hStmt, PicoConnection con)                                  throws SQLException {      this(api, con);      this.hStmt = hStmt;      if(DriverManager.getLogWriter() != null)         DriverManager.println("ResultSet.initialize " + this +                               ",hStmt=" + hStmt);      numberOfCols = getColumnCount();      boundCols = new PicoBoundCol[numberOfCols];      for(int k = 0; k < numberOfCols; k++)         boundCols[k] = new PicoBoundCol();   }   public PicoResultSet (PicoDbApi api, PicoStatement statement)                                  throws SQLException {      this(api, statement.myConnection);      ownerStatement = statement;      if(DriverManager.getLogWriter() != null)         DriverManager.println("ResultSet.initialize " + this +                               ",hStmt=" + getHSTMT() + ",stmt=" + ownerStatement);      numberOfCols = getColumnCount();      boundCols = new PicoBoundCol[numberOfCols];      for(int k = 0; k < numberOfCols; k++)         boundCols[k] = new PicoBoundCol();   }   public boolean absolute(int i) {      throw new UnsupportedOperationException();   }   public void afterLast() {      throw new UnsupportedOperationException();   }   public void beforeFirst() {      throw new UnsupportedOperationException();   }   public void cancelRowUpdates() {      throw new UnsupportedOperationException();   }   public void clearWarnings() throws SQLException {      lastWarning = null;   }   public synchronized void close() throws SQLException {      if(DriverManager.getLogWriter() != null)         DriverManager.println("*close ResultSet=" + getHSTMT() +                                ", freed=" + freed+                               ", stmt=" + ownerStatement+                               ", this=" + this);      if (!closed && !con.isClosed() && odbcApi != null) {         closeInputStreams();         clearWarnings();         lastColumnNull = false;         if(ownerStatement != null) {            if(!freed) {               getHSTMT().close();               freed = true;            }         } else {            getHSTMT().drop();         }      }      closed = true;   }   protected void closeInputStreams() {      for(int i = 0; i < numberOfCols; i++)         boundCols[i].closeInputStream();   }   public void deleteRow() {      throw new UnsupportedOperationException();   }   protected void finalize() {      if(DriverManager.getLogWriter() != null)         DriverManager.println("ResultSet.finalize " + this);      try {         close();      } catch(SQLException _ex) { }   }   public synchronized int findColumn(String s) throws SQLException {      if(rsmd == null) {         rsmd = getMetaData();         colNameToNum = new Hashtable();         colNumToName = new Hashtable();      }      Integer integer = (Integer)colNameToNum.get(s);      if(integer == null) {         for(int i = 1; i <= rsmd.getColumnCount(); i++) {            String s1 = (String)colNumToName.get(new Integer(i));            if(s1 == null) {               s1 = rsmd.getColumnName(i);               colNameToNum.put(s1, new Integer(i));               colNumToName.put(new Integer(i), s1);            }            if(s1.equalsIgnoreCase(s))               return i;         }         throw new SQLException("Column not found", "S0022");      } else {         return integer.intValue();      }   }   public boolean first() {      throw new UnsupportedOperationException();   }   public Array getArray(int i) {      throw new UnsupportedOperationException();   }   public Array getArray(String s) {      throw new UnsupportedOperationException();   }   public void updateArray(int columnIndex, Array x) {      throw new UnsupportedOperationException();   }   public void updateArray(String columnName, Array x) {      throw new UnsupportedOperationException();   }   public InputStream getAsciiStream(int i) throws SQLException {      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      int j = getColumnType(i);      byte byte0 = -2;      switch(j) {      case -1:       case 1: // '\001'      case 12: // '\f'         byte0 = 1;         break;      }      PicoInputStream jdbcodbcinputstream = new PicoInputStream(odbcApi, getHSTMT(), i, (short)1, byte0, ownerStatement);      setInputStream(i, jdbcodbcinputstream);      return jdbcodbcinputstream;   }   public InputStream getAsciiStream(String s) throws SQLException {      return getAsciiStream(findColumn(s));   }   public BigDecimal getBigDecimal(int i) throws SQLException {      BigDecimal Return = null;      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      if(getPseudoCol(i) == null) {         String s = getDataString (i,                               PicoLimits.DEFAULT_BUFFER_LENGTH, true);         if(s != null) {            Return = new BigDecimal(s.trim());         }      } else {         lastColumnNull = true;      }      return Return;   }   public BigDecimal getBigDecimal(int i, int j) throws SQLException {      BigDecimal Return = null;      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      if(getPseudoCol(i) == null) {         String s = getDataString (i,                               PicoLimits.DEFAULT_BUFFER_LENGTH, true);         if(s != null) {            Return = new BigDecimal(s.trim());            Return = Return.setScale(j, BigDecimal.ROUND_HALF_UP);         }      } else {         lastColumnNull = true;      }      return Return;   }   public BigDecimal getBigDecimal(String s) throws SQLException {      return getBigDecimal(findColumn(s));   }   public BigDecimal getBigDecimal(String s, int i) throws SQLException {      return getBigDecimal(findColumn(s), i);   }   public InputStream getBinaryStream(int i) throws SQLException {      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      int j = getColumnType(i);      byte byte0 = -2;      switch(j) {      case -1:       case 1: // '\001'      case 12: // '\f'         byte0 = 1;         break;      }      PicoInputStream jdbcodbcinputstream = new PicoInputStream(odbcApi, getHSTMT(), i, (short)3, byte0, ownerStatement);      setInputStream(i, jdbcodbcinputstream);      return jdbcodbcinputstream;   }   public InputStream getBinaryStream(String s) throws SQLException {      return getBinaryStream(findColumn(s));   }   public Blob getBlob(int i) {      throw new UnsupportedOperationException();   }   public Blob getBlob(String s) {      throw new UnsupportedOperationException();   }   public void updateBlob(int columnIndex, Blob x) {      throw new UnsupportedOperationException();   }   public void updateBlob(String columnName, Blob x) {      throw new UnsupportedOperationException();   }   public boolean getBoolean(int i) throws SQLException {      boolean flag = false;      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      if(getPseudoCol(i) == null)         flag = getInt(i) != 0;      else         lastColumnNull = true;      return flag;   }   public boolean getBoolean(String s) throws SQLException {      return getBoolean(findColumn(s));   }   public byte getByte(int i) throws SQLException {      byte byte0 = 0;      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      if(getPseudoCol(i) == null)         byte0 = (byte)getInt(i);      else         lastColumnNull = true;      return byte0;   }   public byte getByte(String s) throws SQLException {      return getByte(findColumn(s));   }   public synchronized byte[] getBytes(int i) throws SQLException {      byte[] Return = null;      clearWarnings();      lastColumnNull = false;      i = mapColumn(i);      if(getPseudoCol(i) == null) {         Return = (byte[]) getData (i, byte[].class);      } else {         lastColumnNull = true;      }      return Return;   }   public byte[] getBytes(String s) throws SQLException {      return getBytes(findColumn(s));   }   public Reader getCharacterStream(int i) {      throw new UnsupportedOperationException();   }   public Reader getCharacterStream(String s) {      throw new UnsupportedOperationException();   }   public Clob getClob(int i) {      throw new UnsupportedOperationException();   }   public Clob getClob(String s) {      throw new UnsupportedOperationException();   }   public void updateClob(int columnIndex, Clob x) {      throw new UnsupportedOperationException();   }   public void updateClob(String columnName, Clob x) {      throw new UnsupportedOperationException();   }   public int getColAttribute(int col, short t) throws SQLException {      int Return = 0;      clearWarnings();      try {         Return = odbcApi.SQLColAttributes(getHSTMT(), (short) col, t);         if (t == OdbcDef.SQL_COLUMN_TYPE)            Return = OdbcDef.odbcTypeToJdbc(Return);      } catch(PicoSQLWarning jdbcodbcsqlwarning) {         BigDecimal bigdecimal = (BigDecimal)jdbcodbcsqlwarning.value;         Return = bigdecimal.intValue();         setWarning(PicoDbApi.convertWarning(jdbcodbcsqlwarning));      }      return Return;   }   public int getColumnCount() throws SQLException {      int i = 0;      clearWarnings();      if(lastPseudoCol > 0)         return lastPseudoCol;      if(colMappings != null)         return colMappings.length;      try {         if(numResultCols == -1)            numResultCols = odbcApi.SQLNumResultCols(getHSTMT());         i = numResultCols;      } catch(PicoSQLWarning jdbcodbcsqlwarning) {         BigDecimal bigdecimal = (BigDecimal)jdbcodbcsqlwarning.value;         i = bigdecimal.intValue();         setWarning(PicoDbApi.convertWarning(jdbcodbcsqlwarning));      }      return i;   }   public int getColumnLength(int i) throws SQLException {      int j = -1;      if(i > 0 && i <= numberOfCols)         j = boundCols[i - 1].getLength();      if(j == -1)

⌨️ 快捷键说明

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