Esempio n. 1
0
        public static T[] GetFieldValues <T>(DBConnector localdbConnector, int contentId, string fieldName, int[] ids = null, bool isAsync = false)
        {
            var asyncString = isAsync ? "_async" : string.Empty;
            var idsString   = ids != null ? $"where content_item_id in ({IdsStr(ids)})" : string.Empty;
            var fn          = SqlQuerySyntaxHelper.FieldName(localdbConnector.DatabaseType, fieldName);
            var sql         = $"select {fn} from content_{contentId}{asyncString} {idsString} order by content_item_id asc";

            return(localdbConnector.GetRealData(sql).Select().Select(row => ConvertHelpers.ChangeType <T>(row[fieldName])).ToArray());
        }
Esempio n. 2
0
        public void AddFormToContent_ThrowsException_ValidateConstraintForDataConflict()
        {
            var titleName  = DbConnector.FieldName(Global.SiteId, ContentName, "Title");
            var numberName = DbConnector.FieldName(Global.SiteId, ContentName, "Number");
            var fn         = SqlQuerySyntaxHelper.FieldName(DbConnector.DatabaseType, "Title");
            var cmd        = DbConnector.CreateDbCommand($"select content_item_id from content_{ContentId}_united where {fn} <> 'Name2'");
            var id         = (int)(decimal)DbConnector.GetRealScalarData(cmd);
            var article1   = new Hashtable
            {
                [titleName]  = "Name2",
                [numberName] = "9,5"
            };

            Assert.That(() => { id = DbConnector.AddFormToContent(Global.SiteId, ContentName, "Published", ref article1, id); }, Throws.Exception.TypeOf <QpInvalidAttributeException>().And.Message.Contains("Unique constraint violation"), "Duplicate of test data should violate rules");
        }
Esempio n. 3
0
        public void MassUpdate_ThrowsException_ValidateConstraintForDataConflict()
        {
            var values   = new List <Dictionary <string, string> >();
            var fn       = SqlQuerySyntaxHelper.FieldName(DbConnector.DatabaseType, "Title");
            var cmd      = DbConnector.CreateDbCommand($"select content_item_id from content_{ContentId}_united where {fn} <> 'Name2'");
            var id       = (decimal)DbConnector.GetRealScalarData(cmd);
            var article1 = new Dictionary <string, string>
            {
                [FieldName.ContentItemId] = id.ToString(CultureInfo.InvariantCulture),
                ["Title"]  = "Name2",
                ["Number"] = "9,5"
            };

            values.Add(article1);
            Assert.That(() => DbConnector.MassUpdate(ContentId, values, 1), Throws.Exception.TypeOf <QpInvalidAttributeException>().And.Message.Contains("for content articles"), "Duplicate of test data should violate rules");
        }
        private string GetSqlCommandSelect(int contentId)
        {
            string select = null;

            if (!string.IsNullOrEmpty(Fields))
            {
                var orderBy      = GetSqlCommandOrderBy();
                var orderByAttrs = string.IsNullOrEmpty(orderBy)
                    ? new string[] { }
                    : orderBy
                .Split(',')
                .Select(n => n.Trim())
                .Select(n => CRegex.Replace(AscRegex.Replace(DescRegex.Replace(n, ""), ""), ""))
                .Select(n => n.Trim().Replace("[", "").Replace("]", ""))
                .ToArray();

                var attrs = new HashSet <string>(
                    DbConnector.GetContentAttributeObjects(contentId)
                    .Select(n => n.Name.ToLowerInvariant())
                    .Union(new[] { "content_item_id", "archive", "visible", "created", "modified", "last_modified_by" })
                    );

                select = string.Join(", ", Fields
                                     .Split(',')
                                     .Select(n => n.Trim().Replace("[", "").Replace("]", ""))
                                     .Union(orderByAttrs, StringComparer.InvariantCultureIgnoreCase)
                                     .Where(n => attrs.Contains(n.ToLowerInvariant()))
                                     .Select(n => SqlQuerySyntaxHelper.FieldName(DbConnector.DatabaseType, n))
                                     .ToArray()
                                     );
            }

            if (string.IsNullOrEmpty(select))
            {
                select = "c.*";
            }

            if (UseSecurity && !FilterRecords)
            {
                select += ", IsNull(pi.permission_level, 0) as current_permission_level ";
            }

            return(select);
        }