Ejemplo n.º 1
0
        //static void DerbytTest1(string dbpath)
        //{
        //    DerbyNET derbyDB = new DerbyNET(dbpath + ";create=true"); // don't use "\" in directory
        //    if (!derbyDB.openConnection())
        //    {
        //        Console.WriteLine(derbyDB.getLastError());
        //        Console.ReadKey();
        //        //Error opening Derby DB
        //        return;
        //    }
        //    DataTable oDT = derbyDB.getRS("SELECT * FROM schemaExample.tblExample") as DataTable;
        //    if (oDT.Columns[0].ColumnName == "Erro")
        //    {
        //        //Read the ** ERRORS ** section below
        //        Thread.sleep(1000);
        //        oDT = derbyDB.getRS("SELECT * FROM schemaExample.tblExample") as DataTable;
        //    }
        //    else if (oDT.Rows.Count == 1 && oDT.Columns.Count == 1)
        //    {
        //        //Some error occured
        //        Console.WriteLine(derbyDB.getLastError());
        //        Console.ReadKey();
        //        return;
        //    }
        //    derbyDB.closeConnection();
        //}
        static void DerbytTest2(string dbpath)
        {
            Console.WriteLine("Set Property: derby.system.home");
            java.lang.System.setProperty("derby.system.home", dbpath);
            Console.WriteLine("Register Driver: EmbeddedDriver");
            DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
            Console.WriteLine("Connection: jdbc:derby:security");
            Connection derbyConn = DriverManager.getConnection(@"jdbc:derby:security;create=true");

            Console.WriteLine("Create Statement... (ITEM_SEC)");
            Statement         sta  = derbyConn.createStatement();
            ResultSet         res  = sta.executeQuery("SELECT * from ITEM_SEC");
            ResultSetMetaData rsmd = res.getMetaData();

            Console.WriteLine("List Columns: ITEM_SEC");
            for (var i = 1; i <= rsmd.getColumnCount() - 1; i++)
            {
                Console.WriteLine("- Column: {0}", rsmd.getColumnName(i));
            }

            res = sta.executeQuery("SELECT COUNT(*) nTotal from ITEM_SEC");
            while (res.next())
            {
                Console.WriteLine("ITEM_SEC ({0} rows)", res.getString("nTotal"));
            }

            res.close();
            sta.close();
            derbyConn.close();
            Console.ReadKey();
        }
        /**
         * Helper function for getResultField returns a 0-based column number
         *
         * @param colName the column name
         * @param rsmd the result set meta data
         * @return the column number (0-based) or -1 on error
         */
        private int getColumnNumber(String colName,
                                    ResultSetMetaData md)

        {
            int numColumns = md.getColumnCount();

            if (colName.indexOf('.') == -1)
            {
                for (int i = 1; i <= numColumns; i++)
                {
                    if (colName.equals(getColumnLabel(md, i)))
                    {
                        return(i - 1);
                    }
                }

                return(-1);
            }
            else
            {
                for (int i = 1; i <= numColumns; i++)
                {
                    if (colName.equals(md.getTableName(i) + '.' + md.getColumnLabel(i)))
                    {
                        return(i - 1);
                    }
                }

                return(-1);
            }
        }
Ejemplo n.º 3
0
        /**
         * Constructor for MysqliResult
         *
         * @param metaData the corresponding result set meta data
         * @param conn the corresponding connection
         */
        public MysqliResult(ResultSetMetaData metaData,
                            Mysqli conn)
        {
            super(metaData);

            _conn = conn;
        }
        protected MysqlResultSetMetaData(ResultSetMetaData metaData)
        {
            _resultSetMetaData = metaData;

            try {
                _columnEncodings = new String[metaData.getColumnCount()];
            } catch (SQLException e) {
                throw new QuercusException(e);
            }
        }
Ejemplo n.º 5
0
        public static void Dump(ResultSet rs)
        {
            // the order of the rows in a cursor
            // are implementation dependent unless you use the SQL ORDER statement
            ResultSetMetaData meta = rs.GetMetaData();

            int    colmax = meta.GetColumnCount();
            int    i;
            object o = null;



            for (i = 0; i < colmax; ++i)
            {
                Console.Write(meta.GetColumnName(i + 1));
                Console.Write('\t');
            }
            Console.WriteLine();
            //Console.WriteLine(meta.GetCatalogName(0));
            Console.WriteLine(colmax);

            // the result set is a cursor into the data.  You can only
            // point to one row at a time
            // assume we are pointing to BEFORE the first row
            // rs.next() points to next row and returns true
            // or false if there is no next row, which breaks the loop
            for (; rs.Next();)
            {
                for (i = 0; i < colmax; ++i)
                {
                    // Is SQL the first column is indexed
                    try
                    {
                        o = rs.GetObject(i + 1);
                        // with 1 not 0
                        if (o != null)
                        {
                            Console.Write("{0}\t", o.ToString());
                        }
                        else
                        {
                            Console.Write(".\t");
                        }
                    }

                    catch (System.Exception ex)
                    {
                        Console.Write("-\t");
                    }
                }

                Console.WriteLine("");
            }
        }
        /**
         * Returns an object with properties that correspond to the fetched row and
         * moves the internal data pointer ahead.
         *
         * @param env the PHP executing environment
         * @return an object representing the current fetched row
         */
        protected Value fetchObject(Env env, string className, Value[] args)
        {
            if (_rs == null)
            {
                return(NullValue.NULL);
            }

            try {
                if (_rs.next())
                {
                    _isValid = true;

                    Value result;

                    if (className != null)
                    {
                        QuercusClass cls = env.findClass(className);

                        if (args == null)
                        {
                            args = Value.NULL_ARGS;
                        }

                        result = cls.callNew(env, args);
                    }
                    else
                    {
                        result = env.createObject();
                    }

                    ResultSetMetaData md = getMetaData();

                    int count = md.getColumnCount();

                    for (int i = 0; i < count; i++)
                    {
                        string name  = getColumnLabel(md, i + 1);
                        Value  value = getColumnValue(env, i + 1);

                        result.putField(env, name, value);
                    }

                    return(result);
                }
                else
                {
                    return(NullValue.NULL);
                }
            } catch (SQLException e) {
                log.log(Level.FINE, e.ToString(), e);
                return(NullValue.NULL);
            }
        }
        public ResultSet(XE resultSet)
        {
            var resultSetMetaDataElement = ExpectElement(resultSet, C.ResultSetMetaData);
            var metadata = new ResultSetMetaData(resultSetMetaDataElement);

            ResultSetMetaDataColumns = metadata.Columns;

            var rowsElement = ExpectElement(resultSet, C.Rows);
            var rowElements = rowsElement.Elements(C.Row);

            ResultSetRows = rowElements.Select(r => new Row(ResultSetMetaDataColumns, r)).ToArray();
        }
Ejemplo n.º 8
0
        /// <summary>Returns a new table with a unique name and the given table definition.</summary>
        /// <remarks>Returns a new table with a unique name and the given table definition.</remarks>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="Sharpen.SQLException"></exception>
        private static Table CreateUniqueTable(Database db, string name, IList <Column> columns
                                               , ResultSetMetaData md, ImportFilter filter)
        {
            // otherwise, find unique name and create new table
            string baseName = name;
            int    counter  = 2;

            while (db.GetTable(name) != null)
            {
                name = baseName + (counter++);
            }
            db.CreateTable(name, filter.FilterColumns(columns, md));
            return(db.GetTable(name));
        }
        protected override Value getClobValue(Env env,
                                              ResultSet rs,
                                              ResultSetMetaData metaData,
                                              int column)

        {
            Clob         clob   = rs.getClob(column);
            OracleOciLob ociLob = new OracleOciLob(_conn,
                                                   OracleModule.OCI_D_LOB);

            ociLob.setLob(clob);

            return(env.wrapJava(ociLob));
        }
Ejemplo n.º 10
0
        public JDBCInputAdapter(Connection connection, string sql)
        {
            try
            {
                Statement stmt = connection.createStatement();      // Get a statement from the connection
                resultSet = stmt.executeQuery(sql);                 // Execute the query
                ResultSetMetaData rsmd = resultSet.getMetaData();
                inputSize = rsmd.getColumnCount();
            }
            catch (SQLException ex)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                throw new NeurophInputException("Error executing query at JdbcInputAdapter", ex);
            }
        }
  /**
   * @param column 1-based column index
   * @param var reference that receives the value
   * @param type a PARM_* type, -1 for default
   */
  public BoundColumn(ResultSetMetaData metaData,
                     Value column, Value var, ColumnType type)
    
  {
    if (column.isNumberConvertible()) {
      _column = column.toInt();
      _columnAsName = null;
    }
    else {
      _columnAsName = column.ToString();
    }

    _var = var;

    init(metaData);
  }
        protected int getColumnCount(Env env)
        {
            try {
                ResultSetMetaData md = getMetaData();

                if (md == null)
                {
                    return(-1);
                }

                return(md.getColumnCount());
            }
            catch (SQLException e) {
                setError(env, e);

                return(-1);
            }
        }
  private bool init(ResultSetMetaData metaData)
    
  {
    int columnCount = metaData.getColumnCount();

    if (_columnAsName != null) {
      for (int i = 1; i <= columnCount; i++) {
        string name = metaData.getColumnName(i);
        if (name.equals(_columnAsName)) {
          _column = i;
          break;
        }
      }
    }

    _isValid = _column > 0 && _column <= columnCount;

    return true;
  }
        protected override void SetSchemaType(DataRow schemaRow, ResultSetMetaData metaData, int columnIndex)
        {
            JavaSqlTypes columnType = (JavaSqlTypes)metaData.getColumnType(columnIndex);

            switch (columnType)
            {
            case JavaSqlTypes.BINARY_FLOAT:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfFloat;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.BINARY_DOUBLE:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfDouble;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.ROWID:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfString;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.CURSOR:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfDouble;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.TIMESTAMPNS:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.TIMESTAMPTZ:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.TIMESTAMPLTZ:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.INTERVALYM:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfUInt32;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            case JavaSqlTypes.INTERVALDS:
                schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
                schemaRow [(int)SCHEMA_TABLE.DataType]     = OracleConvert.TypeOfTimespan;
                schemaRow [(int)SCHEMA_TABLE.IsLong]       = false;
                break;

            default:
                base.SetSchemaType(schemaRow, metaData, columnIndex);
                break;
            }
        }
Ejemplo n.º 15
0
 /// <exception cref="Sharpen.SQLException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public virtual IList <Column> FilterColumns(IList <Column> destColumns, ResultSetMetaData
                                             srcColumns)
 {
     return(destColumns);
 }
Ejemplo n.º 16
0
		protected virtual void SetSchemaType(DataRow schemaRow, ResultSetMetaData metaData, int columnIndex) {
			DbConvert.JavaSqlTypes columnType = (DbConvert.JavaSqlTypes)metaData.getColumnType(columnIndex);

			switch (columnType) {
				case DbConvert.JavaSqlTypes.ARRAY: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = typeof (java.sql.Array);
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.BIGINT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfInt64;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.BINARY: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfByteArray;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				case DbConvert.JavaSqlTypes.BIT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfBoolean;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.BLOB: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfByteArray;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				case DbConvert.JavaSqlTypes.VARCHAR:
				case DbConvert.JavaSqlTypes.CHAR: {
					// FIXME : specific for Microsoft SQl Server driver
					if (String.CompareOrdinal(metaData.getColumnTypeName(columnIndex), "uniqueidentifier") == 0) {
						schemaRow [(int)SCHEMA_TABLE.ProviderType] = DbType.Guid;
						schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfGuid;
						schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					}
					else
					if (String.CompareOrdinal(metaData.getColumnTypeName(columnIndex), "sql_variant") == 0) {
						schemaRow [(int)SCHEMA_TABLE.ProviderType] = DbType.Object;
						schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfObject;
						schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					}
					else {
						schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
						schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfString;
						schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					}
					break;
				}
				case DbConvert.JavaSqlTypes.CLOB: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfString; // instead og .java.sql.Clob
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				case DbConvert.JavaSqlTypes.DATE: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfDateTime;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
					//                else if(DbConvert.JavaSqlTypes.DISTINCT)
					//                {
					//                    schemaRow ["ProviderType = (int)GetProviderType((int)columnType);
					//                    schemaRow ["DataType = typeof (?);
					//                    schemaRow ["IsLong = false;
					//                }
				case DbConvert.JavaSqlTypes.DOUBLE: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfDouble; // was typeof(float)
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.FLOAT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfDouble;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.REAL: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfFloat;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.INTEGER: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfInt32;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.JAVA_OBJECT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfObject;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.LONGVARBINARY: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfByteArray;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				case DbConvert.JavaSqlTypes.LONGVARCHAR: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfString;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				case DbConvert.JavaSqlTypes.DECIMAL:
				case DbConvert.JavaSqlTypes.NUMERIC: {
					int scale = ResultsMetaData.getScale(columnIndex);
					if (scale == -127) {
						schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
						schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfDouble;
						schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					}
					else {
						schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
						schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfDecimal;
						schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					}
					break;
				}
				case DbConvert.JavaSqlTypes.REF: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = typeof (java.sql.Ref);
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				case DbConvert.JavaSqlTypes.SMALLINT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfInt16;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.STRUCT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = typeof (java.sql.Struct);
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.TIME: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfTimespan;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.TIMESTAMP: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfDateTime;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.TINYINT: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfByte;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				}
				case DbConvert.JavaSqlTypes.VARBINARY: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfByteArray;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
				default: {
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = DbType.Object;
					schemaRow [(int)SCHEMA_TABLE.DataType] = DbTypes.TypeOfObject;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = true;
					break;
				}
			}
		}
Ejemplo n.º 17
0
		internal void CloseInternal()
		{
			_resultsMetaData = null;
			_readerCache = null;
			_isClosed = true;
		}
Ejemplo n.º 18
0
		private bool CloseCurrentResultSet() {
			if (_resultSetStack.Count > 0) {
				try{
					_resultsMetaData = null;
					_readerCache = null;
					_readerState = ReaderState.Uninitialized;
					ResultSet rs = (ResultSet)_resultSetStack.Pop();
					rs.close();
					return true;
				}
				catch (SQLException exp) {
					throw CreateException(exp);
				}
			}

			return false;
		}
		protected override void SetSchemaType(DataRow schemaRow, ResultSetMetaData metaData, int columnIndex) {
			JavaSqlTypes columnType = (JavaSqlTypes)metaData.getColumnType(columnIndex);
			switch (columnType) {
				case JavaSqlTypes.BINARY_FLOAT:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfFloat;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.BINARY_DOUBLE:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfDouble;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.ROWID:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfString;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.CURSOR:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfDouble;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.TIMESTAMPNS:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfTimespan;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.TIMESTAMPTZ:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfTimespan;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.TIMESTAMPLTZ: 
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfTimespan;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.INTERVALYM:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfUInt32;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				case JavaSqlTypes.INTERVALDS:
					schemaRow [(int)SCHEMA_TABLE.ProviderType] = GetProviderType((int)columnType);
					schemaRow [(int)SCHEMA_TABLE.DataType] = OracleConvert.TypeOfTimespan;
					schemaRow [(int)SCHEMA_TABLE.IsLong] = false;
					break;
				default:
					base.SetSchemaType(schemaRow, metaData, columnIndex);
					break;
			}
		}
Ejemplo n.º 20
0
        internal static object JavaResultSetToClrWrapper(CallableStatement results, int columnIndex, JavaSqlTypes javaSqlType, int maxLength, ResultSetMetaData resultsMetaData)
        {
            object returnValue = null;

            sbyte[] sbyteArray;
            long    milliseconds;
            long    ticks;
            string  s;

            columnIndex++;             //jdbc style
            switch (javaSqlType)
            {
            case JavaSqlTypes.ARRAY:
                returnValue = results.getArray(columnIndex);
                break;

            case JavaSqlTypes.BIGINT:
                returnValue = results.getLong(columnIndex);
                break;

            case JavaSqlTypes.BINARY:
            case JavaSqlTypes.VARBINARY:
            case JavaSqlTypes.LONGVARBINARY:
                // FIXME : comsider using maxLength
                sbyteArray = results.getBytes(columnIndex);
                if (sbyteArray != null)
                {
                    returnValue = vmw.common.TypeUtils.ToByteArray(sbyteArray);
                }
                break;

            case JavaSqlTypes.BIT:
                returnValue = results.getBoolean(columnIndex);
                break;

            case JavaSqlTypes.BLOB:
                // FIXME : comsider using maxLength
                java.sql.Blob blob = results.getBlob(columnIndex);
                if (blob != null)
                {
                    InputStream input = blob.getBinaryStream();
                    if (input == null)
                    {
                        returnValue = new byte[0];
                    }
                    else
                    {
                        long    length     = blob.length();
                        byte[]  byteValue  = new byte[length];
                        sbyte[] sbyteValue = vmw.common.TypeUtils.ToSByteArray(byteValue);
                        input.read(sbyteValue);
                        returnValue = byteValue;
                    }
                }
                break;

            case JavaSqlTypes.CHAR:
                if (resultsMetaData != null && "uniqueidentifier".Equals(resultsMetaData.getColumnTypeName(columnIndex)))
                {
                    returnValue = new Guid(results.getString(columnIndex));
                }
                else
                {
                    // Oracle Jdbc driver returns extra trailing 0 chars for NCHAR columns, so we threat this at parameter.Size level
                    s = results.getString(columnIndex);
                    if ((s != null) && (maxLength < s.Length))
                    {
                        s = s.Substring(0, maxLength);
                    }
                    returnValue = s;
                }
                break;

            case JavaSqlTypes.CLOB:
                // FIXME : comsider using maxLength
                java.sql.Clob clob = results.getClob(columnIndex);
                if (clob != null)
                {
                    java.io.Reader reader = clob.getCharacterStream();
                    if (reader == null)
                    {
                        returnValue = String.Empty;
                    }
                    else
                    {
                        long   length    = clob.length();
                        char[] charValue = new char[length];
                        reader.read(charValue);
                        returnValue = new string(charValue);
                    }
                }
                break;

            case JavaSqlTypes.TIME:
                Time t = results.getTime(columnIndex);
                if (t != null)
                {
                    returnValue = new TimeSpan(JavaTimeToClrTicks(t));
                }
                break;

            case JavaSqlTypes.DATE:
                Date d = results.getDate(columnIndex);
                if (d != null)
                {
                    returnValue = new DateTime(JavaDateToClrTicks(d));
                }
                break;

            case JavaSqlTypes.TIMESTAMP:
                Timestamp ts = results.getTimestamp(columnIndex);
                if (ts != null)
                {
                    returnValue = new DateTime(JavaTimestampToClrTicks(ts));
                }
                break;

            case JavaSqlTypes.DECIMAL:
            case JavaSqlTypes.NUMERIC:
                // java.sql.Types.NUMERIC (2), columnTypeName NUMBER, columnClassName java.math.BigDecimal
                // therefore we rely on scale
                if (resultsMetaData != null && resultsMetaData.getScale(columnIndex) == -127)
                {
                    // Oracle db type FLOAT
                    returnValue = results.getDouble(columnIndex);
                }
                else
                {
                    java.math.BigDecimal bigDecimal = results.getBigDecimal(columnIndex);
                    if (bigDecimal != null)
                    {
                        returnValue = vmw.common.PrimitiveTypeUtils.BigDecimalToDecimal(bigDecimal);
                    }
                }
                break;

            case JavaSqlTypes.DISTINCT:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.DOUBLE:
                returnValue = results.getDouble(columnIndex);
                break;

            case JavaSqlTypes.FLOAT:
                //float f = results.getFloat(columnIndex);
                returnValue = results.getDouble(columnIndex);
                break;

            case JavaSqlTypes.INTEGER:
                returnValue = results.getInt(columnIndex);
                break;

            case JavaSqlTypes.JAVA_OBJECT:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.LONGVARCHAR:
                returnValue = results.getString(columnIndex);
                break;

            case JavaSqlTypes.NULL:
                returnValue = DBNull.Value;
                break;

            case JavaSqlTypes.OTHER:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.REAL:
                returnValue = results.getFloat(columnIndex);
                break;

            case JavaSqlTypes.REF:
                returnValue = results.getRef(columnIndex);
                break;

            case JavaSqlTypes.SMALLINT:
                returnValue = results.getShort(columnIndex);
                break;

            case JavaSqlTypes.STRUCT:
                returnValue = results.getObject(columnIndex);
                break;

            case JavaSqlTypes.TINYINT:
                returnValue = Convert.ToByte(results.getByte(columnIndex));
                break;

            case JavaSqlTypes.VARCHAR:
                s = results.getString(columnIndex);
                if ((s != null) && (maxLength < s.Length))
                {
                    s = s.Substring(0, maxLength);
                }
                returnValue = s;
                break;

            default:
                returnValue = results.getObject(columnIndex);
                break;
            }

            if (results.wasNull() || results == null)
            {
                return(DBNull.Value);
            }
            return(returnValue);
        }
        public JdbcResultResource(ResultSetMetaData metaData, int columnCase)
        {
            _metaData = metaData;

            _columnCase = columnCase;
        }
        protected Value fetchArray(Env env, int type, bool isOrderIndexBeforeName)
        {
            try {
                if (_rs == null)
                {
                    return(NullValue.NULL);
                }

                if (_rs.next())
                {
                    _isValid = true;

                    ArrayValue array = new ArrayValueImpl();

                    ResultSetMetaData md = getMetaData();

                    int count = md.getColumnCount();

                    if ((type & FETCH_ASSOC) != 0)
                    {
                        _columnNames = new Value[count];

                        for (int i = 0; i < count; i++)
                        {
                            string columnName = getColumnLabel(md, i + 1);

                            _columnNames[i] = env.createString(columnName);
                        }
                    }

                    for (int i = 0; i < count; i++)
                    {
                        Value value = getColumnValue(env, i + 1);

                        if (isOrderIndexBeforeName)
                        {
                            if ((type & FETCH_NUM) != 0)
                            {
                                array.put(LongValue.create(i), value);
                            }

                            if ((type & FETCH_ASSOC) != 0)
                            {
                                array.put(_columnNames[i], value);
                            }
                        }
                        else
                        {
                            if ((type & FETCH_ASSOC) != 0)
                            {
                                array.put(_columnNames[i], value);
                            }

                            if ((type & FETCH_NUM) != 0)
                            {
                                array.put(LongValue.create(i), value);
                            }
                        }
                    }

                    return(array);
                }
                else
                {
                    return(NullValue.NULL);
                }
            }
            catch (SQLException e) {
                log.log(Level.FINE, e.ToString(), e);
                return(NullValue.NULL);
            }
        }
 /**
  * Constructor for JdbcResultResource
  *
  * @param metaData the corresponding result set meta data
  * @param conn the corresponding connection
  */
 public JdbcResultResource(ResultSetMetaData metaData)
 {
     _metaData = metaData;
 }
Ejemplo n.º 24
0
 /**
  * Constructor for PostgresResult
  *
  * @param metaData the corresponding result set meta data
  * @param conn the corresponding connection
  */
 public PostgresResult(Postgres conn, ResultSetMetaData metaData)
     : base(metaData)
 {
     _conn = conn;
 }
Ejemplo n.º 25
0
		internal static object JavaResultSetToClrWrapper(CallableStatement results,int columnIndex,JavaSqlTypes javaSqlType,int maxLength ,ResultSetMetaData resultsMetaData)
		{
			object returnValue = null;	
			sbyte[] sbyteArray;
			long milliseconds;
			long ticks;
			string s;
			columnIndex++; //jdbc style
			switch (javaSqlType) {
				case JavaSqlTypes.ARRAY :
					returnValue = results.getArray(columnIndex);
					break;
				case JavaSqlTypes.BIGINT :
					returnValue = results.getLong(columnIndex);
					break;
				case JavaSqlTypes.BINARY :
				case JavaSqlTypes.VARBINARY :
				case JavaSqlTypes.LONGVARBINARY :
					// FIXME : comsider using maxLength
					sbyteArray = results.getBytes(columnIndex);
					if (sbyteArray != null) {
						returnValue = vmw.common.TypeUtils.ToByteArray(sbyteArray);
					}
					break;
				case JavaSqlTypes.BIT :
					returnValue = results.getBoolean(columnIndex);
					break;
				case JavaSqlTypes.BLOB :
					// FIXME : comsider using maxLength
					java.sql.Blob blob = results.getBlob(columnIndex);
					if (blob != null) {
						InputStream input = blob.getBinaryStream();					
						if (input == null) {
							returnValue = new byte[0];
						}
						else {
							long length = blob.length();
							byte[] byteValue = new byte[length];
							sbyte[] sbyteValue = vmw.common.TypeUtils.ToSByteArray(byteValue);
							input.read(sbyteValue);
							returnValue = byteValue;
						}
					}
					break;	
				case JavaSqlTypes.CHAR :						
					if (resultsMetaData != null && "uniqueidentifier".Equals(resultsMetaData.getColumnTypeName(columnIndex))) {
						returnValue = new Guid(results.getString(columnIndex));
					}
					else {
						// Oracle Jdbc driver returns extra trailing 0 chars for NCHAR columns, so we threat this at parameter.Size level
						s = results.getString(columnIndex);
						if ((s != null) && (maxLength < s.Length)) {
							s = s.Substring(0,maxLength);
						}
						returnValue = s;
					}
					break;
				case JavaSqlTypes.CLOB :
					// FIXME : comsider using maxLength
					java.sql.Clob clob = results.getClob(columnIndex);
					if (clob != null) {
						java.io.Reader reader = clob.getCharacterStream();					
						if (reader == null) {
							returnValue = String.Empty;
						}
						else {
							long length = clob.length();
							char[] charValue = new char[length];
							reader.read(charValue);
							returnValue = new string(charValue);
						}
					}
					break;		
				case JavaSqlTypes.TIME :
					Time t = results.getTime(columnIndex);
					if (t != null) {
						returnValue = new TimeSpan(JavaTimeToClrTicks(t));
					}
					break;	
				case JavaSqlTypes.DATE :
					Date d = results.getDate(columnIndex);
					if (d != null) {
						returnValue = new DateTime(JavaDateToClrTicks(d));
					}
					break;
				case JavaSqlTypes.TIMESTAMP :				
					Timestamp ts = results.getTimestamp(columnIndex);
					if (ts != null) {
						returnValue = new DateTime(JavaTimestampToClrTicks(ts));
					}
					break;		
				case JavaSqlTypes.DECIMAL :
				case JavaSqlTypes.NUMERIC :
					// java.sql.Types.NUMERIC (2), columnTypeName NUMBER, columnClassName java.math.BigDecimal 
					// therefore we rely on scale
					if (resultsMetaData != null &&  resultsMetaData.getScale(columnIndex) == -127) {
						// Oracle db type FLOAT
						returnValue = results.getDouble(columnIndex);
					}
					else {
						java.math.BigDecimal bigDecimal = results.getBigDecimal(columnIndex);
						if (bigDecimal != null) {
							returnValue = vmw.common.PrimitiveTypeUtils.BigDecimalToDecimal(bigDecimal);
						}
					}
					break;		
				case JavaSqlTypes.DISTINCT :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.DOUBLE :
					returnValue = results.getDouble(columnIndex);
					break;
				case JavaSqlTypes.FLOAT :
					//float f = results.getFloat(columnIndex);
					returnValue = results.getDouble(columnIndex);
					break;
				case JavaSqlTypes.INTEGER :
					returnValue = results.getInt(columnIndex);
					break;
				case JavaSqlTypes.JAVA_OBJECT :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.LONGVARCHAR :
					returnValue = results.getString(columnIndex);
					break;
				case JavaSqlTypes.NULL :
					returnValue = DBNull.Value;
					break;
				case JavaSqlTypes.OTHER :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.REAL :
					returnValue = results.getFloat(columnIndex);
					break;
				case JavaSqlTypes.REF :
					returnValue = results.getRef(columnIndex);
					break;
				case JavaSqlTypes.SMALLINT :
					returnValue = results.getShort(columnIndex);
					break;
				case JavaSqlTypes.STRUCT :
					returnValue = results.getObject(columnIndex);
					break;
				case JavaSqlTypes.TINYINT :
					returnValue = Convert.ToByte(results.getByte(columnIndex));
					break;
				case JavaSqlTypes.VARCHAR :
					s = results.getString(columnIndex);
					if ((s != null) && (maxLength < s.Length)) {
						s = s.Substring(0,maxLength);
					}
					returnValue = s;
					break;
				default :
					returnValue = results.getObject(columnIndex);
					break;
			}
				
			if (results.wasNull() || results == null) {
				return DBNull.Value;
			}                
			return  returnValue;
		}
 /**
  * Constructor for OracleResult
  *
  * @param metaData the corresponding result set meta data
  * @param conn the corresponding connection
  */
 public OracleResult(ResultSetMetaData metaData, Oracle conn)
     : base(metaData)
 {
     _conn = conn;
 }