esDataResponse IDataProvider.FillDataTable(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();

            try
            {
                switch (request.QueryType)
                {
                case esQueryType.StoredProcedure:

                    response = LoadDataTableFromStoredProcedure(request);
                    break;

                case esQueryType.Text:

                    response = LoadDataTableFromText(request);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                response.Exception = ex;
            }

            return(response);
        }
        esDataResponse IDataProvider.esSaveDataTable(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();

            try
            {
                if (request.EntitySavePacket.CurrentValues == null)
                {
                    SaveDynamicCollection(request);
                }
                else
                {
                    SaveDynamicEntity(request);
                }
            }
            catch (SqlCeException ex)
            {
                esException es = Shared.CheckForConcurrencyException(ex);
                if (es != null)
                {
                    response.Exception = es;
                }
                else
                {
                    response.Exception = ex;
                }
            }
            catch (DBConcurrencyException dbex)
            {
                response.Exception = new esConcurrencyException("Error in SqlServerCeProvider.esSaveDataTable", dbex);
            }

            response.Table = request.Table;
            return(response);
        }
        esDataResponse IDataProvider.ExecuteNonQuery(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            VistaDBCommand cmd      = null;

            try
            {
                cmd = new VistaDBCommand();
                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }
                if (request.Parameters != null)
                {
                    Shared.AddParameters(cmd, request);
                }

                switch (request.QueryType)
                {
                case esQueryType.TableDirect:
                    cmd.CommandType = CommandType.TableDirect;
                    cmd.CommandText = request.QueryText;
                    break;

                case esQueryType.StoredProcedure:
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = Shared.CreateFullName(request);
                    break;

                case esQueryType.Text:
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = request.QueryText;
                    break;
                }

                try
                {
                    esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);
                    response.RowsEffected = cmd.ExecuteNonQuery();
                }
                finally
                {
                    esTransactionScope.DeEnlist(cmd);
                }

                if (request.Parameters != null)
                {
                    Shared.GatherReturnParameters(cmd, request, response);
                }
            }
            catch (Exception ex)
            {
                CleanupCommand(cmd);
                response.Exception = ex;
            }

            return(response);
        }
        esDataResponse IDataProvider.esLoadDataTable(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();

            try
            {
                switch (request.QueryType)
                {
                case esQueryType.StoredProcedure:

                    response = LoadDataTableFromStoredProcedure(request);
                    break;

                case esQueryType.Text:

                    response = LoadDataTableFromText(request);
                    break;

                case esQueryType.DynamicQuery:

                    response = new esDataResponse();
                    SACommand cmd = QueryBuilder.PrepareCommand(request);
                    LoadDataTableFromDynamicQuery(request, response, cmd);
                    break;

                case esQueryType.DynamicQueryParseOnly:

                    response = new esDataResponse();
                    SACommand cmd1 = QueryBuilder.PrepareCommand(request);
                    response.LastQuery = cmd1.CommandText;
                    break;

#if (LINQ)
                case esQueryType.IQueryable:

                    response = new esDataResponse();
                    LoadDataTableForLinqToSql(request, response);
                    break;
#endif

                case esQueryType.ManyToMany:

                    response = LoadManyToMany(request);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                response.Exception = ex;
            }

            return(response);
        }
        static private esDataResponse LoadDataSetFromStoredProcedure(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            VistaDBCommand cmd      = null;

            try
            {
                DataSet dataSet = new DataSet();

                cmd             = new VistaDBCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = Shared.CreateFullName(request);

                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }
                if (request.Parameters != null)
                {
                    Shared.AddParameters(cmd, request);
                }

                VistaDBDataAdapter da = new VistaDBDataAdapter();
                da.SelectCommand = cmd;

                try
                {
                    esTransactionScope.Enlist(da.SelectCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Fill(dataSet);
                }
                finally
                {
                    esTransactionScope.DeEnlist(da.SelectCommand);
                }

                response.DataSet = dataSet;

                if (request.Parameters != null)
                {
                    Shared.GatherReturnParameters(cmd, request, response);
                }
            }
            catch (Exception)
            {
                CleanupCommand(cmd);
                throw;
            }
            finally
            {
            }

            return(response);
        }
        esDataResponse IDataProvider.ExecuteReader(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            VistaDBCommand cmd      = null;

            try
            {
                cmd = new VistaDBCommand();
                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }
                if (request.Parameters != null)
                {
                    Shared.AddParameters(cmd, request);
                }

                switch (request.QueryType)
                {
                case esQueryType.TableDirect:
                    cmd.CommandType = CommandType.TableDirect;
                    cmd.CommandText = request.QueryText;
                    break;

                case esQueryType.StoredProcedure:
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = Shared.CreateFullName(request);
                    break;

                case esQueryType.Text:
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = request.QueryText;
                    break;

                case esQueryType.DynamicQuery:
                    cmd = QueryBuilder.PrepareCommand(request);
                    break;
                }

                cmd.Connection = new VistaDBConnection(request.ConnectionString);
                cmd.Connection.Open();

                response.DataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception ex)
            {
                CleanupCommand(cmd);
                response.Exception = ex;
            }

            return(response);
        }
        static private esDataResponse LoadDataTableFromText(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            SACommand      cmd      = null;

            try
            {
                DataTable dataTable = new DataTable(request.ProviderMetadata.Destination);

                cmd             = new SACommand();
                cmd.CommandType = CommandType.Text;
                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }
                if (request.Parameters != null)
                {
                    Shared.AddParameters(cmd, request);
                }

                SADataAdapter da = new SADataAdapter();
                cmd.CommandText  = request.QueryText;
                da.SelectCommand = cmd;

                try
                {
                    esTransactionScope.Enlist(da.SelectCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Fill(dataTable);
                }
                finally
                {
                    esTransactionScope.DeEnlist(da.SelectCommand);
                }

                response.Table = dataTable;

                if (request.Parameters != null)
                {
                    Shared.GatherReturnParameters(cmd, request, response);
                }
            }
            catch (Exception)
            {
                CleanupCommand(cmd);
                throw;
            }
            finally
            {
            }

            return(response);
        }
        static private esDataResponse LoadDataSetFromText(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            SqlCeCommand   cmd      = null;

            try
            {
                DataSet dataSet = new DataSet();

                cmd = new SqlCeCommand();
                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }
                if (request.Parameters != null)
                {
                    Shared.AddParameters(cmd, request);
                }

                SqlCeDataAdapter da = new SqlCeDataAdapter();
                cmd.CommandText  = request.QueryText;
                da.SelectCommand = cmd;

                try
                {
                    esTransactionScope.Enlist(da.SelectCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Fill(dataSet);
                }
                finally
                {
                    esTransactionScope.DeEnlist(da.SelectCommand);
                }

                response.DataSet = dataSet;

                if (request.Parameters != null)
                {
                    Shared.GatherReturnParameters(cmd, request, response);
                }
            }
            catch (Exception ex)
            {
                CleanupCommand(cmd);
                throw ex;
            }
            finally
            {
            }

            return(response);
        }
        esDataResponse IDataProvider.esSaveDataTable(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();

            try
            {
                if (request.SqlAccessType == esSqlAccessType.StoredProcedure)
                {
                    if (request.CollectionSavePacket != null)
                    {
                        SaveStoredProcCollection(request);
                    }
                    else
                    {
                        SaveStoredProcEntity(request);
                    }
                }
                else
                {
                    if (request.EntitySavePacket.CurrentValues == null)
                    {
                        SaveDynamicCollection(request);
                    }
                    else
                    {
                        SaveDynamicEntity(request);
                    }
                }
            }
            catch (VistaDBException ex)
            {
                esException es = Shared.CheckForConcurrencyException(ex);
                if (es != null)
                {
                    response.Exception = es;
                }
                else
                {
                    response.Exception = ex;
                }
            }
            catch (DBConcurrencyException dbex)
            {
                response.Exception = new esConcurrencyException("Error in VistaDBProvider.esSaveDataTable", dbex);
            }

            response.Table = request.Table;
            return(response);
        }
        // This is used only to execute the Dynamic Query API
        static private void LoadDataTableFromDynamicQuery(esDataRequest request, esDataResponse response, VistaDBCommand cmd)
        {
            try
            {
                response.LastQuery = cmd.CommandText;

                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }

                DataTable dataTable = new DataTable(request.ProviderMetadata.Destination);

                VistaDBDataAdapter da = new VistaDBDataAdapter();
                da.SelectCommand = cmd;

                try
                {
                    esTransactionScope.Enlist(da.SelectCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Fill(dataTable);
                }
                finally
                {
                    esTransactionScope.DeEnlist(da.SelectCommand);
                }

                response.Table = dataTable;
            }
            catch (Exception)
            {
                CleanupCommand(cmd);
                throw;
            }
            finally
            {
            }
        }
Exemplo n.º 11
0
        static public void GatherReturnParameters(VistaDBCommand cmd, esDataRequest request, esDataResponse response)
        {
            if (cmd.Parameters.Count > 0)
            {
                if (request.Parameters != null && request.Parameters.Count > 0)
                {
                    response.Parameters = new esParameters();

                    foreach (esParameter esParam in request.Parameters)
                    {
                        if (esParam.Direction != esParameterDirection.Input)
                        {
                            response.Parameters.Add(esParam);
                            VistaDBParameter p = cmd.Parameters[Delimiters.Param + esParam.Name];
                            esParam.Value = p.Value;
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        static public void GatherReturnParameters(OracleCommand cmd, esDataRequest request, esDataResponse response)
        {
            if (cmd.Parameters.Count > 0)
            {
                if (request.Parameters != null && request.Parameters.Count > 0)
                {
                    string paramPrefix = request.QueryType == esQueryType.StoredProcedure ? String.Empty : Delimiters.Param;
                    paramPrefix = request.ProviderMetadata.spLoadByPrimaryKey == request.QueryText ? "p" : paramPrefix;

                    response.Parameters = new esParameters();

                    foreach (esParameter esParam in request.Parameters)
                    {
                        if (esParam.Direction != esParameterDirection.Input)
                        {
                            response.Parameters.Add(esParam);
                            OracleParameter p = cmd.Parameters[paramPrefix + esParam.Name];
                            esParam.Value = p.Value;
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        static public void GatherReturnParameters(MySqlCommand cmd, esDataRequest request, esDataResponse response)
        {
            if (cmd.Parameters.Count > 0)
            {
                if (request.Parameters != null && request.Parameters.Count > 0)
                {
                    string paramPrefix = request.ProviderMetadata.spLoadByPrimaryKey == cmd.CommandText ? Delimiters.Param + "p" : Delimiters.Param;

                    response.Parameters = new esParameters();

                    foreach (esParameter esParam in request.Parameters)
                    {
                        if (esParam.Direction != esParameterDirection.Input)
                        {
                            response.Parameters.Add(esParam);
                            MySqlParameter p = cmd.Parameters[paramPrefix + esParam.Name];
                            esParam.Value = p.Value;
                        }
                    }
                }
            }
        }
        static private esDataResponse LoadManyToMany(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            VistaDBCommand cmd      = null;

            try
            {
                DataTable dataTable = new DataTable(request.ProviderMetadata.Destination);

                cmd             = new VistaDBCommand();
                cmd.CommandType = CommandType.Text;
                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }

                string mmQuery = request.QueryText;

                string[] sections = mmQuery.Split('|');
                string[] tables   = sections[0].Split(',');
                string[] columns  = sections[1].Split(',');

                // We build the query, we don't use Delimiters to avoid tons of extra concatentation
                string sql = "SELECT * FROM [" + tables[0];
                sql += "] JOIN [" + tables[1] + "] ON [" + tables[0] + "].[" + columns[0] + "] = [";
                sql += tables[1] + "].[" + columns[1];
                sql += "] WHERE [" + tables[1] + "].[" + sections[2] + "] = @";

                if (request.Parameters != null)
                {
                    foreach (esParameter esParam in request.Parameters)
                    {
                        sql += esParam.Name;
                    }

                    Shared.AddParameters(cmd, request);
                }

                VistaDBDataAdapter da = new VistaDBDataAdapter();
                cmd.CommandText = sql;

                da.SelectCommand = cmd;

                try
                {
                    esTransactionScope.Enlist(da.SelectCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Fill(dataTable);
                }
                finally
                {
                    esTransactionScope.DeEnlist(da.SelectCommand);
                }

                response.Table = dataTable;
            }
            catch (Exception)
            {
                CleanupCommand(cmd);
                throw;
            }
            finally
            {
            }

            return(response);
        }
        static private esDataResponse LoadManyToMany(esDataRequest request)
        {
            esDataResponse response = new esDataResponse();
            SACommand      cmd      = null;

            try
            {
                DataTable dataTable = new DataTable(request.ProviderMetadata.Destination);

                cmd             = new SACommand();
                cmd.CommandType = CommandType.Text;
                if (request.CommandTimeout != null)
                {
                    cmd.CommandTimeout = request.CommandTimeout.Value;
                }

                string mmQuery = request.QueryText;

                string[] sections = mmQuery.Split('|');
                string[] tables   = sections[0].Split(',');
                string[] columns  = sections[1].Split(',');

                string prefix = String.Empty;

                if (request.Catalog != null || request.ProviderMetadata.Catalog != null)
                {
                    prefix += Delimiters.TableOpen;
                    prefix += request.Catalog != null ? request.Catalog : request.ProviderMetadata.Catalog;
                    prefix += Delimiters.TableClose + ".";
                }

                if (request.Schema != null || request.ProviderMetadata.Schema != null)
                {
                    prefix += Delimiters.TableOpen;
                    prefix += request.Schema != null ? request.Schema : request.ProviderMetadata.Schema;
                    prefix += Delimiters.TableClose + ".";
                }

                string table0 = prefix + Delimiters.TableOpen + tables[0] + Delimiters.TableClose;
                string table1 = prefix + Delimiters.TableOpen + tables[1] + Delimiters.TableClose;

                string sql = "SELECT * FROM " + table0 + " JOIN " + table1 + " ON " + table0 + ".[" + columns[0] + "] = ";
                sql += table1 + ".[" + columns[1] + "] WHERE " + table1 + ".[" + sections[2] + "] = ?";

                if (request.Parameters != null)
                {
                    Shared.AddParameters(cmd, request);
                }

                SADataAdapter da = new SADataAdapter();
                cmd.CommandText = sql;

                da.SelectCommand = cmd;

                try
                {
                    esTransactionScope.Enlist(da.SelectCommand, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Fill(dataTable);
                }
                finally
                {
                    esTransactionScope.DeEnlist(da.SelectCommand);
                }

                response.Table = dataTable;
            }
            catch (Exception)
            {
                CleanupCommand(cmd);
                throw;
            }
            finally
            {
            }

            return(response);
        }
 // This is used only to execute the Dynamic Query API
 static private void LoadDataTableForLinqToSql(esDataRequest request, esDataResponse response)
 {
 }