Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
Parsing out old revisions stored in MYSQL
Old
  (#1)
salvador
Guest
 
Posts: n/a
Default Parsing out old revisions stored in MYSQL - 06-04-2007, 07:48 AM

This seems to be a common issue, but I haven't been able to resolve it
yet, so I thought I'd see if anyone has any suggestions. Drupal has a
table that stores all revisions to a given node and I have been unable
to pull individual records out without also grabbing all revisions.
I'd like to pull out the most recent revision for every given node of
type 'blog' in a given category.

Here's the code I'm using:

select distinct(n.nid), n.title,r.teaser,u.name,n.type,t.tid from node
n INNER JOIN term_node t using n.nid = t.nid INNER JOIN term_data ON
t.tid INNER JOIN users u ON n.uid = u.uid INNER JOIN node_revisions r
ON r.nid = n.nid where t.tid = 1 and n.type="blog";

And the relevent tables.

describe node;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| nid | int(10) unsigned | | PRI | NULL | auto_increment |
| vid | int(10) unsigned | | PRI | 0 | |
| type | varchar(32) | | MUL | | |
| title | varchar(128) | | MUL | | |
| uid | int(10) | | MUL | 0 | |
| status | int(4) | | MUL | 1 | |
| created | int(11) | | MUL | 0 | |
| changed | int(11) | | MUL | 0 | |
| comment | int(2) | | | 0 | |
| promote | int(2) | | MUL | 0 | |
| moderate | int(2) | | MUL | 0 | |
| sticky | int(2) | | | 0 | |
+----------+------------------+------+-----+---------+----------------+
12 rows in set (0.00 sec)

mysql> describe node_revisions;
+-----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+-------+
| nid | int(10) unsigned | | MUL | 0 | |
| vid | int(10) unsigned | | PRI | 0 | |
| uid | int(10) | | MUL | 0 | |
| title | varchar(128) | | | | |
| body | longtext | | | | |
| teaser | longtext | | | | |
| log | longtext | | | | |
| timestamp | int(11) | | | 0 | |
| format | int(4) | | | 0 | |
+-----------+------------------+------+-----+---------+-------+
9 rows in set (0.00 sec)

mysql> describe term_node;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| nid | int(10) unsigned | | PRI | 0 | |
| tid | int(10) unsigned | | PRI | 0 | |
+-------+------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> describe term_data;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra
|
+-------------+------------------+------+-----+---------+----------------+
| tid | int(10) unsigned | | PRI | NULL |
auto_increment |
| vid | int(10) unsigned | | MUL | 0 |
|
| name | varchar(255) | | | |
|
| description | longtext | YES | | NULL |
|
| weight | tinyint(4) | | | 0 |
|
+-------------+------------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)



Any suggestions?

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Parsing out old revisions stored in MYSQL
Old
  (#2)
Captain Paralytic
Guest
 
Posts: n/a
Default Re: Parsing out old revisions stored in MYSQL - 06-04-2007, 07:48 AM


salvador wrote:

> This seems to be a common issue, but I haven't been able to resolve it
> yet, so I thought I'd see if anyone has any suggestions. Drupal has a
> table that stores all revisions to a given node and I have been unable
> to pull individual records out without also grabbing all revisions.
> I'd like to pull out the most recent revision for every given node of
> type 'blog' in a given category.
>
> Here's the code I'm using:
>
> select distinct(n.nid), n.title,r.teaser,u.name,n.type,t.tid from node
> n INNER JOIN term_node t using n.nid = t.nid INNER JOIN term_data ON
> t.tid INNER JOIN users u ON n.uid = u.uid INNER JOIN node_revisions r
> ON r.nid = n.nid where t.tid = 1 and n.type="blog";
>
> And the relevent tables.
>
> describe node;
> +----------+------------------+------+-----+---------+----------------+
> | Field | Type | Null | Key | Default | Extra |
> +----------+------------------+------+-----+---------+----------------+
> | nid | int(10) unsigned | | PRI | NULL | auto_increment |
> | vid | int(10) unsigned | | PRI | 0 | |
> | type | varchar(32) | | MUL | | |
> | title | varchar(128) | | MUL | | |
> | uid | int(10) | | MUL | 0 | |
> | status | int(4) | | MUL | 1 | |
> | created | int(11) | | MUL | 0 | |
> | changed | int(11) | | MUL | 0 | |
> | comment | int(2) | | | 0 | |
> | promote | int(2) | | MUL | 0 | |
> | moderate | int(2) | | MUL | 0 | |
> | sticky | int(2) | | | 0 | |
> +----------+------------------+------+-----+---------+----------------+
> 12 rows in set (0.00 sec)
>
> mysql> describe node_revisions;
> +-----------+------------------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +-----------+------------------+------+-----+---------+-------+
> | nid | int(10) unsigned | | MUL | 0 | |
> | vid | int(10) unsigned | | PRI | 0 | |
> | uid | int(10) | | MUL | 0 | |
> | title | varchar(128) | | | | |
> | body | longtext | | | | |
> | teaser | longtext | | | | |
> | log | longtext | | | | |
> | timestamp | int(11) | | | 0 | |
> | format | int(4) | | | 0 | |
> +-----------+------------------+------+-----+---------+-------+
> 9 rows in set (0.00 sec)
>
> mysql> describe term_node;
> +-------+------------------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +-------+------------------+------+-----+---------+-------+
> | nid | int(10) unsigned | | PRI | 0 | |
> | tid | int(10) unsigned | | PRI | 0 | |
> +-------+------------------+------+-----+---------+-------+
> 2 rows in set (0.00 sec)
>
> mysql> describe term_data;
> +-------------+------------------+------+-----+---------+----------------+
> | Field | Type | Null | Key | Default | Extra
> |
> +-------------+------------------+------+-----+---------+----------------+
> | tid | int(10) unsigned | | PRI | NULL |
> auto_increment |
> | vid | int(10) unsigned | | MUL | 0 |
> |
> | name | varchar(255) | | | |
> |
> | description | longtext | YES | | NULL |
> |
> | weight | tinyint(4) | | | 0 |
> |
> +-------------+------------------+------+-----+---------+----------------+
> 5 rows in set (0.00 sec)
>
>
>
> Any suggestions?


You need to use the "strawberry query". Search this forum for
"strawberry query" (include the quotes).

What in the above tables indicates the the recentness (made up word) of
the revision? If you let me know that, I'll try to construct the query
for you.

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top