Esempio n. 1
0
        /// <summary>
        /// Adds a RIGHT JOIN clause.
        /// </summary>
        /// <param name="Select">The OracleSqlBuilderSelectCount instance.</param>
        /// <param name="TableAlias">The alias of the table.</param>
        /// <param name="ConditionStatement">The condition statment/s of the joined table.</param>
        /// <returns>The current instance of this class.</returns>
        public OracleSqlBuilderSelectCount SetRightJoin(OracleSqlBuilderSelectCount Select, string TableAlias, string ConditionStatement)
        {
            if (Select == null)
            {
                throw new ArgumentException("Select argument should not be null.");
            }
            string strQuery = Select.ToString();

            if (String.IsNullOrWhiteSpace(strQuery))
            {
                throw new ArgumentException("Select argument should not be empty.");
            }
            TableAlias = this._RemoveBackTick(TableAlias);
            if (String.IsNullOrWhiteSpace(TableAlias))
            {
                throw new ArgumentException("TableAlias argument should not be empty.");
            }
            ConditionStatement = this._RemoveBackTick(ConditionStatement);
            if (String.IsNullOrWhiteSpace(ConditionStatement))
            {
                throw new ArgumentException("Condition argument should not be empty.");
            }
            this._Joins.Add(String.Format("RIGHT JOIN (\n{0}\n) AS {1}\n\tON ({2})", this._AddTab(strQuery), this._EncloseBackTick(TableAlias), this._Name(ConditionStatement)));
            return(this);
        }
 /// <summary>
 /// Executes a query and returns a OracleSqlData instance.
 /// </summary>
 /// <param name="SelectCount">The instance of OracleSqlBuilderSelectCount.</param>
 /// <returns>The instance of OracleSqlData.</returns>
 internal OracleSqlData Execute(OracleSqlBuilderSelectCount SelectCount)
 {
     return(this.Execute(OracleSqlConnectionString.Read(), SelectCount));
 }
        /// <summary>
        /// Executes a query and returns a OracleSqlData instance.
        /// </summary>
        /// <param name="ConnectionString">The connection string.</param>
        /// <param name="SelectCount">The instance of OracleSqlBuilderSelectCount.</param>
        /// <returns>The instance of OracleSqlData.</returns>
        internal OracleSqlData Execute(string ConnectionString, OracleSqlBuilderSelectCount SelectCount)
        {
            if (String.IsNullOrWhiteSpace(ConnectionString))
            {
                throw new ArgumentNullException("Connection String argument should not be null.");
            }
            if (SelectCount == null)
            {
                throw new ArgumentNullException("Select argument should not be null.");
            }
            var watch = new Stopwatch();

            watch.Start();
            var data = new OracleSqlData();

            using (var cn = new OracleConnection()) {
                cn.ConnectionString = ConnectionString;
                try {
                    cn.Open();
                    using (var cmd = new OracleCommand()) {
                        cmd.Connection  = cn;
                        cmd.CommandText = SelectCount.ToString();
                        cmd.CommandType = CommandType.Text;
                        SelectCount.PrintQuery();
                        if (SelectCount.GetParameters().Count > 0)
                        {
                            foreach (var kvp in SelectCount.GetParameters())
                            {
                                cmd.Parameters.Add(new OracleParameter(kvp.Key, kvp.Value));
                            }
                            SelectCount.PrintParameters();
                        }
                        using (var da = new OracleDataAdapter()) {
                            da.SelectCommand = cmd;
                            try {
                                da.Fill(data.DataSetResult);
                                data.DataTableResult = data.DataSetResult.Tables[0];
                                data.DataViewResult  = data.DataTableResult.AsDataView();
                                data.RowCount        = Convert.ToInt64(data.DataTableResult.Rows[0][0]);
                                if (data.RowCount > 0)
                                {
                                    foreach (DataRow dr in data.DataTableResult.Rows)
                                    {
                                        Dictionary <string, object> dicRow = new Dictionary <string, object>();
                                        foreach (DataColumn dc in data.DataTableResult.Columns)
                                        {
                                            dicRow.Add(dc.ColumnName, dr[dc.ColumnName]);
                                        }
                                        data.ListResults.Add(dicRow);
                                    }
                                }
                            } catch (OracleException ex) {
                                Debug.WriteLine("An error occured while trying to execute the query.");
                                Debug.WriteLine(String.Format("OracleSQL Error: {0} - {1}", ex.ErrorCode, ex.Message));
                                Debug.WriteLine(ex);
                                if (OracleSqlConfig.ThrowExceptions)
                                {
                                    throw;
                                }
                            } catch (Exception ex) {
                                Debug.WriteLine("An error occured while trying to execute the query.");
                                Debug.WriteLine(String.Format("Error: {0}", ex.Message));
                                Debug.WriteLine(ex);
                                if (OracleSqlConfig.ThrowExceptions)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                } catch (OracleException ex) {
                    Debug.WriteLine("Unable to connect to the specified OracleSQL host.");
                    Debug.WriteLine(String.Format("OracleSQL Error: {0} - {1}", ex.ErrorCode, ex.Message));
                    Debug.WriteLine(ex);
                    if (OracleSqlConfig.ThrowExceptions)
                    {
                        throw;
                    }
                } catch (Exception ex) {
                    Debug.WriteLine("Unable to connect to the specified OracleSQL host.");
                    Debug.WriteLine(String.Format("Error: {0}", ex.Message));
                    Debug.WriteLine(ex);
                    if (OracleSqlConfig.ThrowExceptions)
                    {
                        throw;
                    }
                } finally {
                    if (cn != null && cn.State == ConnectionState.Open)
                    {
                        cn.Close();
                    }
                }
            }
            watch.Stop();
            data.Duration = watch.Elapsed;
            this._PrintRowsFound(data.RowCount);
            this._PrintDuration(data.Duration);
            return(data);
        }