private void CommitNewObjectsToDb(ObjectsByPropertyIndexSet plan)
        {
            List <MetadataProperty> metaProps = this.GetMetaProps(plan.IndexSet);
            StringBuilder           sql       = new StringBuilder(string.Format("INSERT INTO [{0}]([{1}]", (object)this.FClass.DataTable, (object)this.FClass.IDProperty.DataField));
            int paramIndex1 = 1;

            StorageCommitPlan.MetaPropsToSql((IList <MetadataProperty>)metaProps, sql, ",", "[{0}]", (DataType[])null, ref paramIndex1);
            sql.Append(") VALUES (?");
            DataType[] paramTypes = new DataType[paramIndex1];
            object[]   values     = new object[paramIndex1];
            paramTypes[0] = DataType.String;
            int paramIndex2 = 1;

            StorageCommitPlan.MetaPropsToSql((IList <MetadataProperty>)metaProps, sql, ",", "?", paramTypes, ref paramIndex2);
            sql.Append(")");
            InDbCommand command = this.FSession.Db.CreateCommand(sql.ToString(), paramTypes);

            try
            {
                for (int index1 = 0; index1 < plan.Count; ++index1)
                {
                    DataObject dataObject = plan[index1];
                    int        index2     = 1;
                    values[0] = (object)dataObject.Id.ToString();
                    StorageCommitPlan.CopyPropsToParams(dataObject, (IList <MetadataProperty>)metaProps, values, ref index2);
                    command.Execute(values);
                }
            }
            finally
            {
                command.Dispose();
            }
        }
示例#2
0
        internal override void Load(InDbDatabase db, DataObjectList dstObjs)
        {
            int count = this.FIds.Count;

            if (count == 0)
            {
                return;
            }
            DataId[] dataIdArray = new DataId[count];
            this.FIds.Keys.CopyTo((Array)dataIdArray, 0);
            this.FIds.Clear();
            StringBuilder stringBuilder = new StringBuilder(this.SelectSql);

            stringBuilder.Append(" WHERE [").Append(this.InProperty.DataField).Append("] IN ('");
            int length = stringBuilder.Length;
            int index1 = 0;

            while (index1 < count)
            {
                stringBuilder.Length = length;
                for (int index2 = 0; index1 < count && index2 < 100; ++index2)
                {
                    if (index2 > 0)
                    {
                        stringBuilder.Append("','");
                    }
                    stringBuilder.Append(dataIdArray[index1].ToString());
                    ++index1;
                }
                stringBuilder.Append("')");
                InDbCommand command = db.CreateCommand(stringBuilder.ToString());
                IDataReader reader  = command.ExecuteReader();
                try
                {
                    this.Load(reader, dstObjs, (LoadContext)0);
                }
                finally
                {
                    reader.Dispose();
                    command.Dispose();
                }
            }
            if (!this.InProperty.IsId)
            {
                return;
            }
            for (int index2 = 0; index2 < count; ++index2)
            {
                DataId id = dataIdArray[index2];
                if (!this.LoadedObjects.ContainsKey((object)id))
                {
                    this.FStorage.EnsureCacheItem(id).SetSessionState(ObjectSessionState.Error);
                }
            }
        }
        private ListDictionary GetOriginalValues(
            string deletedId,
            InDbDatabase dbForOriginalValues)
        {
            ListDictionary properties = new ListDictionary();
            string         sql        = string.Format("SELECT * FROM [{0}] WHERE [{1}]=?", (object)this.Class.DataTable, (object)this.Class.IDProperty.DataField);

            using (InDbCommand command = dbForOriginalValues.CreateCommand(sql, DataType.String))
            {
                using (IDataReader originalValuesReader = command.ExecuteReader((object)deletedId))
                {
                    if (originalValuesReader.Read())
                    {
                        this.AddOriginalValues(properties, originalValuesReader);
                    }
                }
            }
            return(properties);
        }
示例#4
0
        internal override void Load(InDbDatabase db, DataObjectList dstObjs)
        {
            StringBuilder sql     = new StringBuilder();
            bool          onePass = true;

            if (this.Condition.Length == 0)
            {
                sql.Append(this.SelectSql);
            }
            else
            {
                this.GenerateLoadSql(sql, ref onePass);
            }
            if (onePass || this.ObjectLoader.Count == 0)
            {
                using (InDbCommand command = db.CreateCommand(sql.ToString(), this.FParamTypes))
                {
                    using (IDataReader reader = command.ExecuteReader(this.FParamValues))
                    {
                        LoadContext loadContext = this.Condition == string.Empty ? LoadContext.FetchAllObjects : (LoadContext)0;
                        this.Load(reader, dstObjs, loadContext);
                    }
                }
            }
            else
            {
                List <DataId> dataIdList = new List <DataId>();
                using (InDbCommand command = db.CreateCommand(sql.ToString(), this.FParamTypes))
                {
                    using (IDataReader dataReader = command.ExecuteReader(this.FParamValues))
                    {
                        while (dataReader.Read())
                        {
                            dataIdList.Add(new DataId(dataReader.GetString(0)));
                        }
                    }
                }
                this.FStorage.Session.LoadData(this.ObjectLoader.BasePlan, dstObjs, dataIdList.ToArray(), (string)null);
            }
        }
        public Totals Execute()
        {
            ArrayList   arrayList  = new ArrayList();
            InDbCommand command    = this.FStorage.Session.Db.CreateCommand(this.FSql.ToString(), this.FSqlParamTypes);
            IDataReader dataReader = command.ExecuteReader(this.FSqlParamValues);

            try
            {
                while (dataReader.Read())
                {
                    object[] values = new object[dataReader.FieldCount];
                    dataReader.GetValues(values);
                    arrayList.Add((object)new Totals.Row(values));
                }
            }
            finally
            {
                dataReader.Dispose();
                command.Dispose();
            }
            return(new Totals((Totals.Row[])arrayList.ToArray(typeof(Totals.Row))));
        }
        private void CommitModifiedObjectsToDb(ObjectsByPropertyIndexSet plan)
        {
            if (plan.IndexSet.IsEmpty)
            {
                return;
            }
            List <MetadataProperty> metaProps = this.GetMetaProps(plan.IndexSet);
            StringBuilder           sql       = new StringBuilder(string.Format("UPDATE [{0}] SET ", (object)this.FClass.DataTable));
            int paramIndex1 = 0;

            StorageCommitPlan.MetaPropsToSql((IList <MetadataProperty>)metaProps, sql, (string)null, "[{0}]=?", (DataType[])null, ref paramIndex1);
            sql.Append(string.Format(" WHERE [{0}]=?", (object)this.FClass.IDProperty.DataField));
            DataType[] paramTypes  = new DataType[paramIndex1 + 1];
            object[]   values      = new object[paramIndex1 + 1];
            int        paramIndex2 = 0;

            StorageCommitPlan.MetaPropsToSql((IList <MetadataProperty>)metaProps, (StringBuilder)null, (string)null, (string)null, paramTypes, ref paramIndex2);
            paramTypes[paramIndex2] = DataType.String;
            InDbCommand command = this.FSession.Db.CreateCommand(sql.ToString(), paramTypes);

            try
            {
                for (int index1 = 0; index1 < plan.Count; ++index1)
                {
                    DataObject dataObject = plan[index1];
                    int        index2     = 0;
                    StorageCommitPlan.CopyPropsToParams(dataObject, (IList <MetadataProperty>)metaProps, values, ref index2);
                    values[index2] = (object)dataObject.Id.ToString();
                    command.Execute(values);
                }
            }
            finally
            {
                command.Dispose();
            }
        }