Databases: query compatibily

Databases: query compatibily

by Luiz Eduardo Laydner Cruz -
Number of replies: 1
Hi,
I'm Luiz Laydner, I'm working on a project for moodle as part of the google summer of code program.

I'm implementing social networking capabilities for moodle.
(http://docs.moodle.org/en/Student_projects/Social_Networking_features)
Part of it is an API for tags. The idea is that any entity in moodle can be related to a tag. (initially only users and blog entries will be tagged)

The DB schema I came up is the following

CREATE TABLE `mdl_tag` (
`id` int(11) NOT NULL auto_increment,
`userid` bigint(11) NOT NULL,
`name` varchar(255) NOT NULL,
`tagtype` varchar(255) default NULL,
`description` text,
`descriptionformat` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mdl_tag_names_idx` (`name`)
) ;

CREATE TABLE `mdl_tag_instance` (
`id` int(11) NOT NULL auto_increment,
`tagid` int(11) NOT NULL,
`itemtype` varchar(255) NOT NULL,
`itemid` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mdl_tag_taggings` (`tagid`,`itemtype`,`itemid`)
);

the "tag" table holds the names of the tags.

the "tag_instance" table holds the information of associations between tags and entities.
itemtype is the name of the table (example: 'user')
itemid is the identifier of the entity (example: 1 )

Since referential integrity cannot be implemented in this kind of polymorphic many-to-many relationship... i'm creating a cleanup function for the "tag_instance" table.

I've came up with this query:

DELETE
FROM
mdl_tag_instance
WHERE
mdl_tag_instance.id
IN
( SELECT sq1.id
FROM
(SELECT sq2.*
FROM mdl_tag_instance sq2
LEFT JOIN mdl_user item
ON sq2.itemid = item.id
WHERE item.id IS NULL
AND sq2.itemtype = 'user')
AS sq1
)

(by substituting mdl_user and 'user' i can cleanup other types)

This query worked with MySql.

My question is: is this query also ok for the other databases moodle has to work with (postgres, oracle, mssql) ?


Average of ratings: -
In reply to Luiz Eduardo Laydner Cruz

Re: Databases: query compatibily

by Kiril Ilarionov -
May be the question is as follows:
IS THE QUERY ISO SQL-92/99 COMPATIBILY?

It looks to be ISO query.

smile