Esempio n. 1
0
        /// <summary>
        /// Insère un nouvel enregistrement.
        /// </summary>
        /// <param name="commandName">Nom de la commande.</param>
        /// <param name="bean">Bean à insérér.</param>
        /// <param name="beanDefinition">Définition du bean.</param>
        /// <param name="primaryKey">Définition de la clef primaire.</param>
        /// <param name="columnSelector">Selecteur de colonnes à mettre à jour ou à ignorer.</param>
        /// <returns>Reader retournant les données du bean inséré.</returns>
        protected override IDataReader Insert(string commandName, T bean, BeanDefinition beanDefinition, BeanPropertyDescriptor primaryKey, ColumnSelector columnSelector)
        {
            string           sql     = this.BuildInsertQuery(beanDefinition, true, columnSelector);
            SqlServerCommand command = new SqlServerCommand(this.DataSourceName, commandName, sql);

            command.CommandTimeout = 0;
            this.AddInsertParameters(bean, beanDefinition, command.Parameters, columnSelector);
            return(command.ExecuteReader());
        }
Esempio n. 2
0
        public void TestParseConstant()
        {
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required)) {
                TestDbProviderFactory.DefinedNextResult(new List <Bean>());

                SqlServerCommand command = new SqlServerCommand("test", SqlResource.ResourceManager, "SqlTestConst");
                command.ExecuteReader();

                Assert.IsTrue(command.CommandText.Contains("'5' = 5"));

                command.Dispose();
            }
        }
Esempio n. 3
0
        public void TestParseCurrentUserId()
        {
            using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required)) {
                TestDbProviderFactory.DefinedNextResult(new List <Bean>());

                SqlServerCommand command = new SqlServerCommand("test", SqlResource.ResourceManager, "SqlTestUserId");
                command.ExecuteReader();

                Assert.IsTrue(command.CommandText.Contains(":CURRENT_USER_ID IS NOT NULL"));

                command.Dispose();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Ajoute tous les champs retournée par la commande comme propriété du document.
        /// </summary>
        /// <param name="command">Commande Sql.</param>
        public void AddProperties(SqlServerCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            using (IDataReader reader = command.ExecuteReader()) {
                if (reader.Read())
                {
                    this.AddProperties(reader);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Insère un nouvel enregistrement.
        /// </summary>
        /// <param name="commandName">Nom de la commande.</param>
        /// <param name="bean">Bean à insérer.</param>
        /// <param name="beanDefinition">Définition du bean.</param>
        /// <param name="primaryKey">Définition de la clef primaire.</param>
        /// <param name="columnSelector">Selecteur de colonnes à mettre à jour ou à ignorer.</param>
        /// <param name="primaryKeyValue">Valeur de la clef primaire.</param>
        /// <returns>Bean inséré.</returns>
        protected override IDataReader Insert(string commandName, T bean, BeanDefinition beanDefinition, BeanPropertyDescriptor primaryKey, ColumnSelector columnSelector, object primaryKeyValue)
        {
            if (primaryKey == null)
            {
                throw new ArgumentNullException("primaryKey");
            }

            string           sql     = this.BuildInsertQuery(beanDefinition, true, columnSelector);
            SqlServerCommand command = new SqlServerCommand(this.DataSourceName, commandName, sql);

            command.CommandTimeout = 0;
            command.Parameters.AddWithValue(primaryKey.MemberName, primaryKeyValue);
            this.AddInsertParameters(bean, beanDefinition, command.Parameters, columnSelector);
            return(command.ExecuteReader());
        }
Esempio n. 6
0
        /// <summary>
        /// Crée une collection de document à partir d'une commande.
        /// </summary>
        /// <param name="command">Commande.</param>
        /// <returns>Collection de document.</returns>
        public static ICollection <ReportDocument> CreateCollection(SqlServerCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            List <ReportDocument> coll = new List <ReportDocument>();

            using (IDataReader reader = command.ExecuteReader()) {
                while (reader.Read())
                {
                    ReportDocument document = new ReportDocument();
                    document.AddProperties(reader);
                    coll.Add(document);
                }
            }

            return(coll);
        }
Esempio n. 7
0
        /// <summary>
        /// Ajoute tous les champs retournée par la commande comme propriété du document.
        /// </summary>
        /// <param name="command">Commande Sql.</param>
        /// <param name="collectionName">Nom de la collection.</param>
        public void AddCollection(SqlServerCommand command, string collectionName)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            using (IDataReader reader = command.ExecuteReader()) {
                List <ReportDocument> collection = new List <ReportDocument>();
                while (reader.Read())
                {
                    ReportDocument document = new ReportDocument();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        document.Add(reader.GetName(i), reader.GetValue(i));
                    }

                    collection.Add(document);
                }

                this.Add(collectionName, collection);
            }
        }