コード例 #1
0
        protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            Check.NotNull(providerManifest, "providerManifest");
            Check.NotNull(commandTree, "commandTree");

            return CreateDbCommandDefinition(providerManifest, commandTree, new DbInterceptionContext());
        }
コード例 #2
0
        static LegacyDbProviderManifestWrapperTests()
        {
            LegacyProviderManifest =
                ((Legacy.DbProviderServices)
                 ((IServiceProvider)Legacy.DbProviderFactories.GetFactory("System.Data.SqlClient"))
                     .GetService(typeof(Legacy.DbProviderServices)))
                    .GetProviderManifest("2008");

            ProviderManifestWrapper = new LegacyDbProviderManifestWrapper(LegacyProviderManifest);

            const string emptyCsdl =
                @"<Schema xmlns=""http://schemas.microsoft.com/ado/2009/11/edm"" Namespace=""dummy"" />";

            using (var reader = XmlReader.Create(new StringReader(emptyCsdl)))
            {
                EdmPrimitiveTypes =
                    new EdmItemCollection(new[] { reader }).GetItems<PrimitiveType>().ToDictionary(t => t.Name, t => t);
            }

            using (var reader = XmlReader.Create(new StringReader(emptyCsdl)))
            {
                LegacyEdmPrimitiveTypes =
                    new LegacyMetadata.EdmItemCollection(new[] { reader })
                        .GetItems<LegacyMetadata.PrimitiveType>()
                        .ToDictionary(t => t.Name, t => t);
            }
        }
コード例 #3
0
 /// <summary>
 /// Creates the provider manifest wrapper.
 /// </summary>
 /// <param name="providerInvariantName">Provider invariant name.</param>
 /// <param name="providerManifest">The provider manifest to be wrapped.</param>
 /// <returns><see cref="DbProviderManifest"/> wrapper for given provider invariant name wrapping given provider manifest.</returns>
 public virtual DbProviderManifest CreateProviderManifest(string providerInvariantName, DbProviderManifest providerManifest)
 {
     return new DbProviderManifestWrapper(
         this.ProviderInvariantName,
         providerInvariantName,
         providerManifest);
 }
コード例 #4
0
        /// <summary>
        ///     Create a Command Definition object, given the connection and command tree
        /// </summary>
        /// <param name="connection"> connection to the underlying provider </param>
        /// <param name="commandTree"> command tree for the statement </param>
        /// <returns> an executable command definition object </returns>
        /// <exception cref="ArgumentNullException">connection and commandTree arguments must not be null</exception>
        protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            Check.NotNull(providerManifest, "providerManifest");
            Check.NotNull(commandTree, "commandTree");

            var storeMetadata = (StoreItemCollection)commandTree.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
            return CreateCommandDefinition(storeMetadata.StoreProviderFactory, commandTree);
        }
コード例 #5
0
 protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
 {
     return new CachingCommandDefinition(
         _providerServices.CreateCommandDefinition(providerManifest, commandTree), 
         new CommandTreeFacts(commandTree),
         _cacheTransactionHandler,
         _cachingPolicy);
 }
コード例 #6
0
 private void InitializeProviderServices(string providerManifestToken)
 {
     using (var connection = CreateConnection())
     {
         _providerServices = DbProviderServices.GetProviderServices(connection);
         _providerManifest = _providerServices.GetProviderManifest(providerManifestToken);
     }
 }
コード例 #7
0
        protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            Debug.Assert(providerManifest != null, "CreateCommandDefinition passed null provider manifest to CreateDbCommandDefinition?");
            Debug.Assert(commandTree != null, "CreateCommandDefinition did not validate commandTree argument?");

            var prototype = CreateCommand(providerManifest, commandTree);
            var result = CreateCommandDefinition(prototype);
            return result;
        }
コード例 #8
0
    protected override DbCommandDefinition CreateDbCommandDefinition(
        DbProviderManifest providerManifest, DbCommandTree commandTree)
    {
      if (commandTree == null)
        throw new ArgumentNullException("commandTree");

      SqlGenerator generator = null;
      if (commandTree is DbQueryCommandTree)
        generator = new SelectGenerator();
      else if (commandTree is DbInsertCommandTree)
        generator = new InsertGenerator();
      else if (commandTree is DbUpdateCommandTree)
        generator = new UpdateGenerator();
      else if (commandTree is DbDeleteCommandTree)
        generator = new DeleteGenerator();
      else if (commandTree is DbFunctionCommandTree)
        generator = new FunctionGenerator();

      string sql = generator.GenerateSQL(commandTree);

      EFMySqlCommand cmd = new EFMySqlCommand();
      cmd.CommandText = sql;
      if (generator is FunctionGenerator)
        cmd.CommandType = (generator as FunctionGenerator).CommandType;

      SetExpectedTypes(commandTree, cmd);

      EdmFunction function = null;
      if (commandTree is DbFunctionCommandTree)
        function = (commandTree as DbFunctionCommandTree).EdmFunction;

      // Now make sure we populate the command's parameters from the CQT's parameters:
      foreach (KeyValuePair<string, TypeUsage> queryParameter in commandTree.Parameters)
      {
        DbParameter parameter = cmd.CreateParameter();
        parameter.ParameterName = queryParameter.Key;
        parameter.Direction = ParameterDirection.Input;
        parameter.DbType = Metadata.GetDbType(queryParameter.Value);

        FunctionParameter funcParam;
        if (function != null &&
            function.Parameters.TryGetValue(queryParameter.Key, false, out funcParam))
        {
          parameter.ParameterName = funcParam.Name;
          parameter.Direction = Metadata.ModeToDirection(funcParam.Mode);
          parameter.DbType = Metadata.GetDbType(funcParam.TypeUsage);
        }
        cmd.Parameters.Add(parameter);
      }

      // Now add parameters added as part of SQL gen 
      foreach (DbParameter p in generator.Parameters)
        cmd.Parameters.Add(p);

      return CreateCommandDefinition(cmd);
    }
コード例 #9
0
        protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            var entityCommandDefinition = EntityCommandDefinition;
            if (entityCommandDefinition == null)
            {
                entityCommandDefinition = new Mock<EntityCommandDefinition>(MockBehavior.Loose, null, null, null).Object;
            }

            return entityCommandDefinition;
        }
コード例 #10
0
        // used by EntityStoreSchemaGenerator to start with an empty (primitive types only) StoreItemCollection and 
        // add types discovered from the database
        internal StoreItemCollection(DbProviderFactory factory, DbProviderManifest manifest, string providerManifestToken)
            : base(DataSpace.SSpace)
        {
            Debug.Assert(factory != null, "factory is null");
            Debug.Assert(manifest != null, "manifest is null");

            _providerFactory = factory;
            _providerManifest = manifest;
            _providerManifestToken = providerManifestToken;
            _cachedCTypeFunction = new Memoizer<EdmFunction, EdmFunction>(ConvertFunctionSignatureToCType, null);
            LoadProviderManifest(_providerManifest);
        }
コード例 #11
0
        private void InitializeProviderServices(string providerManifestToken)
        {
            Check.NotEmpty(providerManifestToken, "providerManifestToken");

            using (var connection = CreateConnection())
            {
                _providerManifest
                    = DbProviderServices
                        .GetProviderServices(connection)
                        .GetProviderManifest(providerManifestToken);
            }
        }
コード例 #12
0
        internal override DbCommandDefinition CreateDbCommandDefinition(
            DbProviderManifest providerManifest,
            DbCommandTree commandTree,
            DbInterceptionContext interceptionContext)
        {
            DebugCheck.NotNull(providerManifest);
            DebugCheck.NotNull(commandTree);
            DebugCheck.NotNull(interceptionContext);

            var storeMetadata = (StoreItemCollection)commandTree.MetadataWorkspace.GetItemCollection(DataSpace.SSpace);
            return CreateCommandDefinition(storeMetadata.StoreProviderFactory, commandTree, interceptionContext);
        }
コード例 #13
0
        public static DbProviderInfo GetProviderInfo(
            this DbConnection connection, out DbProviderManifest providerManifest)
        {
            Contract.Requires(connection != null);

            var providerServices = DbProviderServices.GetProviderServices(connection);
            var providerManifestToken = providerServices.GetProviderManifestTokenChecked(connection);
            var providerInfo = new DbProviderInfo(connection.GetProviderInvariantName(), providerManifestToken);

            providerManifest = providerServices.GetProviderManifest(providerManifestToken);

            return providerInfo;
        }
コード例 #14
0
    public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken)
    {
      List<MigrationStatement> stmts = new List<MigrationStatement>();
      MySqlConnection con = new MySqlConnection();
      providerManifest = DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken);

      foreach (MigrationOperation op in migrationOperations)
      {
        OpDispatcher opdis = dispatcher[op.GetType().Name];
        stmts.Add(opdis(op));
      }
      return stmts;
    }
コード例 #15
0
        // used by EntityStoreSchemaGenerator to start with an empty (primitive types only) StoreItemCollection and 
        // add types discovered from the database
        internal StoreItemCollection(
            DbProviderFactory factory, DbProviderManifest manifest, string providerInvariantName, string providerManifestToken)
            : base(DataSpace.SSpace)
        {
            DebugCheck.NotNull(factory);
            DebugCheck.NotNull(manifest);

            _providerFactory = factory;
            _providerManifest = manifest;
            _providerInvariantName = providerInvariantName;
            _providerManifestToken = providerManifestToken;
            _cachedCTypeFunction = new Memoizer<EdmFunction, EdmFunction>(ConvertFunctionSignatureToCType, null);
            LoadProviderManifest(_providerManifest);
        }
コード例 #16
0
        public static DbProviderInfo GetProviderInfo(
            this DbConnection connection, out DbProviderManifest providerManifest)
        {
            DebugCheck.NotNull(connection);

            var providerManifestToken = DbConfiguration
                .GetService<IManifestTokenService>()
                .GetProviderManifestToken(connection);

            var providerInfo = new DbProviderInfo(connection.GetProviderInvariantName(), providerManifestToken);

            providerManifest = DbProviderServices.GetProviderServices(connection).GetProviderManifest(providerManifestToken);

            return providerInfo;
        }
コード例 #17
0
        /// <summary>
        ///     Converts a set of migration operations into Microsoft SQL Server specific SQL.
        /// </summary>
        /// <param name = "migrationOperations">The operations to be converted.</param>
        /// <param name = "providerManifestToken">Token representing the version of SQL Server being targeted (i.e. "2005", "2008").</param>
        /// <returns>A list of SQL statements to be executed to perform the migration operations.</returns>
        public override IEnumerable<MigrationStatement> Generate(
            IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken)
        {
            _statements = new List<MigrationStatement>();
            _generatedSchemas = new HashSet<string>();
            _variableCounter = 0;

            using (var connection = CreateConnection())
            {
                _providerManifest
                    = DbProviderServices.GetProviderServices(connection)
                        .GetProviderManifest(providerManifestToken);
            }

            migrationOperations.Each<dynamic>(o => Generate(o));

            return _statements;
        }
コード例 #18
0
        /// <summary>
        ///     Create a Command Definition object given a command tree.
        /// </summary>
        /// <param name="commandTree"> command tree for the statement </param>
        /// <returns> an executable command definition object </returns>
        /// <remarks>
        ///     This method simply delegates to the provider's implementation of CreateDbCommandDefinition.
        /// </remarks>
        public DbCommandDefinition CreateCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            Contract.Requires(providerManifest != null);
            Contract.Requires(commandTree != null);

            try
            {
                return CreateDbCommandDefinition(providerManifest, commandTree);
            }
            catch (ProviderIncompatibleException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (e.IsCatchableExceptionType())
                {
                    throw new ProviderIncompatibleException(Strings.ProviderDidNotCreateACommandDefinition, e);
                }
                throw;
            }
        }
コード例 #19
0
        protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            Debug.Assert(providerManifest != null, "providerManifest != null");
            Debug.Assert(
                providerManifest is LegacyDbProviderManifestWrapper, "providerManifest expected to be LegacyDbProviderManifestWrapper");
            Debug.Assert(commandTree != null, "commandTree != null");
            Debug.Assert(commandTree is DbQueryCommandTree, "Only query trees are supported");
            Debug.Assert(commandTree.DataSpace == DataSpace.SSpace, "SSpace tree expected");

            try
            {
                var legacyMetadata = commandTree.MetadataWorkspace.ToLegacyMetadataWorkspace();

                var legacyQuery =
                    ((DbQueryCommandTree)commandTree).Query.Accept(
                        new LegacyDbExpressionConverter(
                            (LegacyMetadata.StoreItemCollection)
                            legacyMetadata.GetItemCollection(LegacyMetadata.DataSpace.SSpace)));

                var legacyCommandTree =
                    (LegacyCommandTrees.DbCommandTree)LegacyDbQueryCommandTreeCtor.Invoke(
                        new object[]
                            {
                                legacyMetadata,
                                LegacyMetadata.DataSpace.SSpace,
                                legacyQuery
                            });

                return new LegacyDbCommandDefinitionWrapper(
                    _wrappedProviderServices.CreateCommandDefinition(
                        ((LegacyDbProviderManifestWrapper)providerManifest).WrappedManifest,
                        legacyCommandTree));
            }
            catch (SystemData.ProviderIncompatibleException exception)
            {
                throw new ProviderIncompatibleException(exception.Message, exception.InnerException);
            }
        }
コード例 #20
0
ファイル: NpgsqlServices.cs プロジェクト: neisbut/npgsql
 protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
 {
     return CreateCommandDefinition(CreateDbCommand(((NpgsqlProviderManifest)providerManifest).Version, commandTree));
 }
コード例 #21
0
 protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
 {
     return new GlimpseDbCommandDefinition(InnerProviderServices.CreateCommandDefinition(commandTree));
 }
コード例 #22
0
		private DbCommand CreateCommand(DbProviderManifest manifest, DbCommandTree commandTree)
		{
			if (manifest == null)
				throw new ArgumentNullException("manifest");

			if (commandTree == null)
				throw new ArgumentNullException("commandTree");

			SQLiteCommand command = new SQLiteCommand();
			try
			{
				List<DbParameter> parameters;
				CommandType commandType;

				command.CommandText = SqlGenerator.GenerateSql((SQLiteProviderManifest)manifest, commandTree, out parameters, out commandType);
				command.CommandType = commandType;

				// Get the function (if any) implemented by the command tree since this influences our interpretation of parameters
				EdmFunction function = null;
				if (commandTree is DbFunctionCommandTree)
				{
					function = ((DbFunctionCommandTree)commandTree).EdmFunction;
				}

				// Now make sure we populate the command's parameters from the CQT's parameters:
				foreach (KeyValuePair<string, TypeUsage> queryParameter in commandTree.Parameters)
				{
					SQLiteParameter parameter;

					// Use the corresponding function parameter TypeUsage where available (currently, the SSDL facets and 
					// type trump user-defined facets and type in the EntityCommand).
					FunctionParameter functionParameter;
					if (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter))
					{
						parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value);
					}
					else
					{
						parameter = CreateSqlParameter(queryParameter.Key, queryParameter.Value, ParameterMode.In, DBNull.Value);
					}

					command.Parameters.Add(parameter);
				}

				// Now add parameters added as part of SQL gen (note: this feature is only safe for DML SQL gen which
				// does not support user parameters, where there is no risk of name collision)
				if (null != parameters && 0 < parameters.Count)
				{
					if (!(commandTree is DbInsertCommandTree) &&
					  !(commandTree is DbUpdateCommandTree) &&
					  !(commandTree is DbDeleteCommandTree))
					{
						throw new InvalidOperationException("SqlGenParametersNotPermitted");
					}

					foreach (DbParameter parameter in parameters)
					{
						command.Parameters.Add(parameter);
					}
				}

				return command;
			}
			catch
			{
				command.Dispose();
				throw;
			}
		}
コード例 #23
0
        protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
        {
            if (providerManifest == null)
                throw new ArgumentNullException("providerManifest");

            if (commandTree == null)
                throw new ArgumentNullException("commandTree");

            List<DbParameter> parameters;
            CommandType commandType;
            string commandText = SqlGenerator.GenerateSql(commandTree, out parameters, out commandType);
            DbCommand command = null;
            if (commandType == NuoDbMultipleCommands.MultipleTexts)
                command = new NuoDbMultipleCommands(PrepareTypeCoercions(commandTree));
            else
                command = new NuoDbCommand(PrepareTypeCoercions(commandTree));
            command.CommandText = commandText;
            command.CommandType = commandType;

            // Get the function (if any) implemented by the command tree since this influences our interpretation of parameters
            EdmFunction function = null;
            if (commandTree is DbFunctionCommandTree)
            {
                function = ((DbFunctionCommandTree)commandTree).EdmFunction;
            }

            foreach (KeyValuePair<string, TypeUsage> queryParameter in commandTree.Parameters)
            {
                NuoDbParameter parameter;

                // Use the corresponding function parameter TypeUsage where available (currently, the SSDL facets and 
                // type trump user-defined facets and type in the EntityCommand).
                FunctionParameter functionParameter;
                if (null != function && function.Parameters.TryGetValue(queryParameter.Key, false, out functionParameter))
                {
                    parameter = CreateSqlParameter(functionParameter.Name, functionParameter.TypeUsage, functionParameter.Mode, DBNull.Value);
                }
                else
                {
                    parameter = CreateSqlParameter(queryParameter.Key, queryParameter.Value, ParameterMode.In, DBNull.Value);
                }

                command.Parameters.Add(parameter);
            }

            // Now add parameters added as part of SQL gen (note: this feature is only safe for DML SQL gen which
            // does not support user parameters, where there is no risk of name collision)
            if (null != parameters && 0 < parameters.Count)
            {
                if (!(commandTree is DbInsertCommandTree) &&
                  !(commandTree is DbUpdateCommandTree) &&
                  !(commandTree is DbDeleteCommandTree))
                {
                    throw new InvalidOperationException("SqlGenParametersNotPermitted");
                }

                foreach (DbParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }
            }

            return CreateCommandDefinition(command);
        }
コード例 #24
0
ファイル: NpgsqlServices.cs プロジェクト: NoeGarcia/Npgsql
 protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
 {
     return CreateCommandDefinition(CreateDbCommand(commandTree));
 }
コード例 #25
0
		protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest manifest, DbCommandTree commandTree)
		{
			DbCommand prototype = CreateCommand(manifest, commandTree);
			DbCommandDefinition result = this.CreateCommandDefinition(prototype);
			return result;
		}
コード例 #26
0
 protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
 {
     return new Mock<EntityCommandDefinition>(MockBehavior.Loose, null, null).Object;
 }
コード例 #27
0
    public override string GenerateProcedureBody(ICollection<DbModificationCommandTree> commandTrees, string rowsAffectedParameter, string providerManifestToken)
    {
      MySqlConnection con = new MySqlConnection();
      MigrationStatement stmt = new MigrationStatement();
      _providerManifest = DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken);

      var cmdStr = "";
      SqlGenerator generator = new SelectGenerator();
      foreach (var commandTree in commandTrees)
      {
        switch (commandTree.CommandTreeKind)
        {
          case DbCommandTreeKind.Insert:
            generator = new InsertGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Delete:
            generator = new DeleteGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Update:
            generator = new UpdateGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Query:
            generator = new SelectGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
          case DbCommandTreeKind.Function:
            generator = new FunctionGenerator();
            cmdStr = generator.GenerateSQL(commandTree);
            break;
        }
        stmt.Sql += cmdStr.Replace("dbo.", "") + ";";
      }
      return stmt.Sql;
    }
コード例 #28
0
    public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken)
    {      
      MySqlConnection con = new MySqlConnection();
      List<MigrationStatement> stmts = new List<MigrationStatement>();
      _providerManifestToken = providerManifestToken;
      _providerManifest = DbProviderServices.GetProviderServices(con).GetProviderManifest(providerManifestToken);
      
      //verify if there is one or more add/alter column operation, if there is then look for primary key operations. Alter in case that the user wants to change the current PK column
      if ((from cols in migrationOperations.OfType<AddColumnOperation>() select cols).Count() > 0 || (from cols in migrationOperations.OfType<AlterColumnOperation>() select cols).Count() > 0)
        _pkOperations = (from pks in migrationOperations.OfType<AddPrimaryKeyOperation>() select pks).ToList();

      foreach (MigrationOperation op in migrationOperations)
      {
        if (!_dispatcher.ContainsKey(op.GetType().Name))
          throw new NotImplementedException(op.GetType().Name);
        OpDispatcher opdis = _dispatcher[op.GetType().Name];
        stmts.Add(opdis(op)); 
      }
      if (_specialStmts.Count > 0)
      {
        foreach (var item in _specialStmts)
          stmts.Add(item);
      }
      return stmts;
    }
コード例 #29
0
 /// <summary>Creates a command definition object for the specified provider manifest and command tree.</summary>
 /// <returns>An executable command definition object.</returns>
 /// <param name="providerManifest">Provider manifest previously retrieved from the store provider.</param>
 /// <param name="commandTree">Command tree for the statement.</param>
 protected abstract DbCommandDefinition CreateDbCommandDefinition(
     DbProviderManifest providerManifest,
     DbCommandTree commandTree);
コード例 #30
0
        /// <summary>Creates command definition from specified manifest and command tree.</summary>
        /// <returns>The created command definition.</returns>
        /// <param name="providerManifest">The manifest.</param>
        /// <param name="commandTree">The command tree.</param>
        public DbCommandDefinition CreateCommandDefinition(
            DbProviderManifest providerManifest,
            DbCommandTree commandTree)
        {
            Check.NotNull(providerManifest, "providerManifest");
            Check.NotNull(commandTree, "commandTree");

            try
            {
                return CreateDbCommandDefinition(providerManifest, commandTree);
            }
            catch (ProviderIncompatibleException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (e.IsCatchableExceptionType())
                {
                    throw new ProviderIncompatibleException(Strings.ProviderDidNotCreateACommandDefinition, e);
                }
                throw;
            }
        }