Example #1
0
        public static IList executeSQL(string sql)
        {
            IList result = new ArrayList();

            ISessionFactoryImplementor sf;
            IDbCommand cmd;
            IDbConnection conn;

            try
            {
                Configuration cfg = new Configuration();
                cfg.Configure();
                sf = (ISessionFactoryImplementor)cfg.BuildSessionFactory();

                SqlString queryString = new NHibernate.SqlCommand.SqlString(sql);

                NHibernate.SqlTypes.SqlType[] Types = new NHibernate.SqlTypes.SqlType[] { };

                cmd = sf.ConnectionProvider.Driver.GenerateCommand(CommandType.Text, queryString, Types);

                cmd.CommandText = sql;

                conn = sf.OpenConnection();
            }
            catch (HibernateException ex)
            {
                throw new HibernateException("Fatal error occured, Can not connect the database!", ex);
            }

            try
            {
                cmd.Connection = conn;

                IDataReader rs = cmd.ExecuteReader();

                while (rs.Read())
                {
                    Array subList = new object[rs.FieldCount];
                    for (int i = 0; i < rs.FieldCount; i++)
                    {
                        subList.SetValue(rs.GetValue(i), i);
                    }
                    result.Add(subList);
                }
            }
            catch (HibernateException ex)
            {
                throw new HibernateException(ex);
            }
            finally
            {
                sf.CloseConnection(conn);
            }
            return result;
        }
Example #2
0
        public static IList executeSQL(string sql)
        {
            IList result = new ArrayList();

            ISessionFactoryImplementor sf;
            IDbCommand    cmd;
            IDbConnection conn;

            try
            {
                Configuration cfg = new Configuration();
                cfg.Configure();
                sf = (ISessionFactoryImplementor)cfg.BuildSessionFactory();

                SqlString queryString = new NHibernate.SqlCommand.SqlString(sql);

                NHibernate.SqlTypes.SqlType[] Types = new NHibernate.SqlTypes.SqlType[] { };

                cmd = sf.ConnectionProvider.Driver.GenerateCommand(CommandType.Text, queryString, Types);

                cmd.CommandText = sql;

                conn = sf.OpenConnection();
            }
            catch (HibernateException ex)
            {
                throw new HibernateException("Fatal error occured, Can not connect the database!", ex);
            }

            try
            {
                cmd.Connection = conn;

                IDataReader rs = cmd.ExecuteReader();

                while (rs.Read())
                {
                    Array subList = new object[rs.FieldCount];
                    for (int i = 0; i < rs.FieldCount; i++)
                    {
                        subList.SetValue(rs.GetValue(i), i);
                    }
                    result.Add(subList);
                }
            }
            catch (HibernateException ex)
            {
                throw new HibernateException(ex);
            }
            finally
            {
                sf.CloseConnection(conn);
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// NHibernate는 BinaryBlobSqlType을 기본적으로 varbinary(8000)으로 변경한다. 이를 Image 형식으로 변경히기 위해 재정의하였다.
        /// </summary>
        /// <param name="dbParam"></param>
        /// <param name="name"></param>
        /// <param name="sqlType"></param>
        protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name,
                                                    NHibernate.SqlTypes.SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            if (sqlType is NHibernate.SqlTypes.BinarySqlType)
            {
                if (IsDebugEnabled)
                {
                    log.Debug("BinaryBlobSqlType이므로 SqlDbType.Image 로 변경합니다.");
                }

                var parameter = (SqlParameter)dbParam;
                parameter.SqlDbType = SqlDbType.Image;
            }
        }
        /// <summary>
        /// The initialize parameter.
        /// </summary>
        /// <param name="dbParam">
        /// The db param.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sqlType">
        /// The sql type.
        /// </param>
        protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name,
                                                    NHibernate.SqlTypes.SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);
            var oraParam = dbParam as OracleParameter;

            if (oraParam != null)
            {
                if (sqlType.DbType == System.Data.DbType.Binary)
                {
                    oraParam.OracleDbType = OracleDbType.Blob;
                }
                else if (sqlType.DbType == System.Data.DbType.String && sqlType.LengthDefined && sqlType.Length >= 32768)
                {
                    oraParam.OracleDbType = OracleDbType.Clob;
                }
            }
        }
Example #5
0
        protected override void InitializeParameter(IDbDataParameter dbParam, string name, NHibernate.SqlTypes.SqlType sqlType)
        {
            base.InitializeParameter(dbParam, name, sqlType);

            // Since the .NET currency type has 4 decimal places, we use a decimal type in PostgreSQL
            // instead of its native 2 decimal currency type.
            if (sqlType.DbType == DbType.Currency)
            {
                dbParam.DbType = DbType.Decimal;
            }
        }