简体   繁体   中英

Database integrity problem while sorting pages

I have almost finished building my cms with drag and drop page sorting and heirarchy editing.

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...

|-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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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