简体   繁体   English

对页面进行排序时的数据库完整性问题

[英]Database integrity problem while sorting pages

I have almost finished building my cms with drag and drop page sorting and heirarchy editing. 通过拖放页面排序和层次结构编辑,我几乎完成了cms的构建。

Here is my pages table in my db. 这是我数据库中的页面表。

CREATE TABLE `pages` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `metatitle` varchar(255) DEFAULT NULL,
 `metadesc` text,
 `metakw` varchar(255) DEFAULT NULL,
 `create_time` datetime DEFAULT NULL,
 `update_time` datetime DEFAULT NULL,
 `name` varchar(255) DEFAULT NULL,
 `url` varchar(255) DEFAULT NULL,
 `parent` int(11) DEFAULT NULL,
 `active` tinyint(1) DEFAULT NULL,
 `sort` int(11) DEFAULT NULL,
 `nofollow` tinyint(1) DEFAULT NULL,
 `deletable` tinyint(1) DEFAULT NULL,
 `navshow` tinyint(1) DEFAULT NULL,
 `type` enum('basic','dynamic','virtual') DEFAULT NULL COMMENT 'basic: only contains basic content\ndynamic: contains both dynamic and basic content\nvirtual: redirects to another page',
 `virtual_redirect` int(11) DEFAULT NULL,
 `route` varchar(255) DEFAULT NULL,
 `dynamic_desc` varchar(255) DEFAULT NULL,
 `content1` blob,
 `content2` blob,
 PRIMARY KEY (`id`),
 UNIQUE KEY `url_UNIQUE` (`url`),
 UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1

As you can see from parent field, I'm using the adjacency list model for creating my page heirarchy. 从父字段可以看到,我正在使用邻接列表模型来创建页面层次结构。

Say I had this page structure... 说我有这个页面结构...

|-Page 1
| |-Page 3
| |-Page 2
| |-Page 4
| |-Page 5
|-Page 6

If I moved page 3 up a level the structure would now look like this... 如果我将第3页上移一个级别,结构现在将如下所示:

|-Page 1
| |-Page 2
| |-Page 4
| |-Page 5
|-Page 3
|-Page 6

Here's my problem. 这是我的问题。

The above example involves a fairly substantial number of query's ( for such a small tree). 上面的示例涉及相当数量的查询(对于这样的小树)。 I have to change the sort numbers of pages 2-6 and the parent of page 3. That's 7 querys. 我必须更改第2-6页和第3页的父级的排序号。这就是7个查询。

What i'm experiencing is that the moving operation produces different results each time I use it. 我正在经历的是,每次使用移动操作都会产生不同的结果。 ie: sometimes it works perfectly, other times the sort numbers don't update properly. 即:有时效果很好,有时排序编号无法正确更新。

It's as though the database craps out on a few of the queries and pretty soon the consistency of the database is ruined. 好像数据库在一些查询中出现问题,很快数据库的一致性就被破坏了。

I'm not sure whether it's because there are too many queries or some other factor. 我不确定是否是因为查询过多或其他因素。 But I'm finding it very difficult to diagnose. 但是我发现很难诊断。

Any ideas what the problem might be? 任何想法可能是什么问题?

Cheers Tom 干杯汤姆

我建议您阅读如何管理数据库中的分层数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM