private void HandleException(Exception ex)
 {
     if (ex is ConnectorException)
     {
         throw ex;
     }
     else
     {
         throw ConnectorExceptionFactory.FromDatabaseException(ex);
     }
 }
 /// <summary>
 /// Executa a Stored Procedure e retorna o primeiro resultado obtido.
 /// </summary>
 public object ExecuteScalar()
 {
     try
     {
         return(cmd.ExecuteScalar());
     }
     catch (Exception ex)
     {
         throw ConnectorExceptionFactory.FromDatabaseException(ex)
               .Detail("Erro ao executar stored procedure {0}", cmd.CommandText);
     }
 }
 /// <summary>
 /// Executa a Stored Procedure e retorna uma <see cref="DataTable"/> com o nome especificado.
 /// </summary>
 /// <param name="table">O nome da <see cref="DataTable"/> a ser retornada</param>
 public DataTable ExecuteDataTable(string table)
 {
     try
     {
         return(cmd.ExecuteDataTable(table));
     }
     catch (Exception ex)
     {
         throw ConnectorExceptionFactory.FromDatabaseException(ex)
               .Detail("Erro ao executar stored procedure {0}", cmd.CommandText);
     }
 }
 /// <summary>
 /// Executa a Stored Procedure.
 /// </summary>
 public void Execute()
 {
     try
     {
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         throw ConnectorExceptionFactory.FromDatabaseException(ex)
               .Detail("Erro ao executar stored procedure {0}", cmd.CommandText);
     }
 }
 /// <summary>
 /// Preenche um <see cref="DataTable"/> com o resultado da Stored Procedure.
 /// </summary>
 public int Fill(DataTable dt)
 {
     try
     {
         using (AdpDataAdapter da = new AdpDataAdapter(cmd))
             return(da.Fill(dt));
     }
     catch (Exception ex)
     {
         throw ConnectorExceptionFactory.FromDatabaseException(ex)
               .Detail("Erro ao executar stored procedure {0}", cmd.CommandText);
     }
 }
        /// <summary>
        /// Preenche a tabela de dados especificada, com os critérios especificados.
        /// </summary>
        /// <param name="dataTable">O nome da tabela no DataSet que deverá ser preenchida.</param>
        /// <param name="query">A consulta de origem dos dados</param>
        public int FillData(string dataTable, ISqlQuery query)
        {
            string sql = null;

            try
            {
#if DEBUG
                Debug.WriteLine("FillData");
                Debug.IndentLevel++;
                Debug.WriteLine("Data Table: " + dataTable);
                Debug.WriteLine("SQL: " + Regex.Replace(query.ToString().Replace(Environment.NewLine, " "), "\\s+", " "));
                Debug.IndentLevel--;
#endif
                sql = query.ToString();
                DataTable dt = ds.Tables[dataTable];
                if (dt != null)
                {
                    sql = Regex.Replace(sql, "FROM\\s+" + dataTable, "FROM " + GetPhysicalTableName(dt), RegexOptions.IgnoreCase);
                }

                using (AdpConnection conn = CreateConnection())
                    using (AdpDataAdapter da = new AdpDataAdapter())
                    {
                        da.SelectCommand = new AdpCommand(sql, conn);

                        return(da.Fill(ds, dataTable));
                    }
            }
            catch (Exception ex)
            {
                if (sql == null)
                {
                    throw new ConnectorException("Erro ao realizar o preenchimento dos dados", ex);
                }
                else
                {
                    throw ConnectorExceptionFactory.FromDatabaseException(ex, sql);
                }
            }
        }