par
Spols » 09 oct. 2011, 14:54
Salut,
Je comprends tes modifications, mais je garderais malgré tout le type = contact dans la clause where car j'envisage de faire la même requète avec une autre clause, et ainsi la sortir de la jointure permet d'etre plus clair. Est-ce que cela change quelque chose niveau traitement ?
Je fait l'autojointure sur file_usage afin d'avoir une ligne par node du bon type et les fid des deux fichiers (swf et pdf). j'avais commencé par essayer de récupérer les doublonsmais cela ne me semblait pas être une bonne piste.
je te colle les create table et les lignes que j'ai actuellement ci-dessous
Code : Tout sélectionner
-- phpMyAdmin SQL Dump
-- version 3.3.2deb1
-- http://www.phpmyadmin.net
--
-- Serveur: localhost
-- Généré le : Dim 09 Octobre 2011 à 14:26
-- Version du serveur: 5.1.41
-- Version de PHP: 5.3.2-1ubuntu4.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données: `aiif`
--
-- --------------------------------------------------------
--
-- Structure de la table `file_managed`
--
CREATE TABLE IF NOT EXISTS `file_managed` (
`fid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'File ID.',
`uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The users.uid of the user who is associated with the file.',
`filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
`uri` varchar(255) NOT NULL DEFAULT '' COMMENT 'The URI to access the file (either local or remote).',
`filemime` varchar(255) NOT NULL DEFAULT '' COMMENT 'The file’s MIME type.',
`filesize` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The size of the file in bytes.',
`status` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
`timestamp` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'UNIX timestamp for when the file was added.',
PRIMARY KEY (`fid`),
UNIQUE KEY `uri` (`uri`),
KEY `uid` (`uid`),
KEY `status` (`status`),
KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores information for uploaded files.' AUTO_INCREMENT=6 ;
--
-- Contenu de la table `file_managed`
--
INSERT INTO `file_managed` (`fid`, `uid`, `filename`, `uri`, `filemime`, `filesize`, `status`, `timestamp`) VALUES
(1, 1, 'Immoweb_Info_3297871.pdf', 'public://contact/Immoweb_Info_3297871.pdf', 'application/pdf', 204029, 1, 1316119282),
(3, 1, 'php_info_esco.pdf', 'public://contact/php_info_esco.pdf', 'application/pdf', 91967, 1, 1317840181),
(4, 1, 'programme-ISQ-110627.pdf', 'public://contact/programme-ISQ-110627.pdf', 'application/pdf', 94967, 1, 1317843205),
(5, 1, 'test.swf', 'public://contact/test.swf', 'application/x-shockwave-flash', 691653, 1, 1318084021);
-- --------------------------------------------------------
--
-- Structure de la table `file_usage`
--
CREATE TABLE IF NOT EXISTS `file_usage` (
`fid` int(10) unsigned NOT NULL COMMENT 'File ID.',
`module` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the module that is using the file.',
`type` varchar(64) NOT NULL DEFAULT '' COMMENT 'The name of the object type in which the file is used.',
`id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The primary key of the object using the file.',
`count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The number of times this file is used by this object.',
PRIMARY KEY (`fid`,`type`,`id`,`module`),
KEY `type_id` (`type`,`id`),
KEY `fid_count` (`fid`,`count`),
KEY `fid_module` (`fid`,`module`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Track where a file is used.';
--
-- Contenu de la table `file_usage`
--
INSERT INTO `file_usage` (`fid`, `module`, `type`, `id`, `count`) VALUES
(1, 'file', 'node', 5, 1),
(3, 'file', 'node', 7, 1),
(4, 'file', 'node', 6, 1),
(5, 'file', 'node', 6, 1);
-- --------------------------------------------------------
--
-- Structure de la table `node`
--
CREATE TABLE IF NOT EXISTS `node` (
`nid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The primary identifier for a node.',
`vid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The current node_revision.vid version identifier.',
`type` varchar(32) NOT NULL DEFAULT '' COMMENT 'The node_type.type of this node.',
`language` varchar(12) NOT NULL DEFAULT '' COMMENT 'The languages.language of this node.',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT 'The title of this node, always treated as non-markup plain text.',
`uid` int(11) NOT NULL DEFAULT '0' COMMENT 'The users.uid that owns this node; initially, this is the user that created it.',
`status` int(11) NOT NULL DEFAULT '1' COMMENT 'Boolean indicating whether the node is published (visible to non-administrators).',
`created` int(11) NOT NULL DEFAULT '0' COMMENT 'The Unix timestamp when the node was created.',
`changed` int(11) NOT NULL DEFAULT '0' COMMENT 'The Unix timestamp when the node was most recently saved.',
`comment` int(11) NOT NULL DEFAULT '0' COMMENT 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).',
`promote` int(11) NOT NULL DEFAULT '0' COMMENT 'Boolean indicating whether the node should be displayed on the front page.',
`sticky` int(11) NOT NULL DEFAULT '0' COMMENT 'Boolean indicating whether the node should be displayed at the top of lists in which it appears.',
`tnid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The translation set id for this node, which equals the node id of the source post in each set.',
`translate` int(11) NOT NULL DEFAULT '0' COMMENT 'A boolean indicating whether this translation page needs to be updated.',
PRIMARY KEY (`nid`),
UNIQUE KEY `vid` (`vid`),
KEY `node_changed` (`changed`),
KEY `node_created` (`created`),
KEY `node_frontpage` (`promote`,`status`,`sticky`,`created`),
KEY `node_status_type` (`status`,`type`,`nid`),
KEY `node_title_type` (`title`,`type`(4)),
KEY `node_type` (`type`(4)),
KEY `uid` (`uid`),
KEY `tnid` (`tnid`),
KEY `translate` (`translate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='The base table for nodes.' AUTO_INCREMENT=10 ;
--
-- Contenu de la table `node`
--
INSERT INTO `node` (`nid`, `vid`, `type`, `language`, `title`, `uid`, `status`, `created`, `changed`, `comment`, `promote`, `sticky`, `tnid`, `translate`) VALUES
(1, 1, 'page', 'fr', 'Site web de l''AIIF - IMC', 1, 1, 1310159761, 1312743877, 1, 1, 0, 0, 0),
(2, 2, 'page', 'fr', 'STATUTS DE L''A.I.I.F.-I.M.C. ASBL', 1, 1, 1313520108, 1317843954, 1, 0, 0, 0, 0),
(3, 3, 'page', 'fr', 'COMPOSITION DU CONSEIL D''ADMINISTRATION DE L''ASSOCIATION', 1, 1, 1313520739, 1317843648, 1, 0, 0, 0, 0),
(4, 4, 'page', 'fr', 'Contact', 1, 1, 1316118872, 1318152479, 1, 0, 0, 0, 0),
(5, 5, 'contact', 'fr', '27/08/11', 1, 1, 1316119282, 1316119282, 1, 0, 0, 0, 0),
(6, 6, 'contact', 'fr', '22/09/11', 1, 1, 1316119473, 1318084021, 1, 0, 0, 0, 0),
(7, 7, 'contact', 'fr', '05/10/11', 1, 1, 1317840181, 1317840181, 1, 0, 0, 0, 0),
(9, 9, 'page', 'fr', 'Contact', 1, 1, 1318090188, 1318106022, 1, 0, 0, 0, 0);
Salut,
Je comprends tes modifications, mais je garderais malgré tout le type = contact dans la clause where car j'envisage de faire la même requète avec une autre clause, et ainsi la sortir de la jointure permet d'etre plus clair. Est-ce que cela change quelque chose niveau traitement ?
Je fait l'autojointure sur file_usage afin d'avoir une ligne par node du bon type et les fid des deux fichiers (swf et pdf). j'avais commencé par essayer de récupérer les doublonsmais cela ne me semblait pas être une bonne piste.
je te colle les create table et les lignes que j'ai actuellement ci-dessous
[code]-- phpMyAdmin SQL Dump
-- version 3.3.2deb1
-- http://www.phpmyadmin.net
--
-- Serveur: localhost
-- Généré le : Dim 09 Octobre 2011 à 14:26
-- Version du serveur: 5.1.41
-- Version de PHP: 5.3.2-1ubuntu4.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données: `aiif`
--
-- --------------------------------------------------------
--
-- Structure de la table `file_managed`
--
CREATE TABLE IF NOT EXISTS `file_managed` (
`fid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'File ID.',
`uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The users.uid of the user who is associated with the file.',
`filename` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
`uri` varchar(255) NOT NULL DEFAULT '' COMMENT 'The URI to access the file (either local or remote).',
`filemime` varchar(255) NOT NULL DEFAULT '' COMMENT 'The file’s MIME type.',
`filesize` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The size of the file in bytes.',
`status` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
`timestamp` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'UNIX timestamp for when the file was added.',
PRIMARY KEY (`fid`),
UNIQUE KEY `uri` (`uri`),
KEY `uid` (`uid`),
KEY `status` (`status`),
KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Stores information for uploaded files.' AUTO_INCREMENT=6 ;
--
-- Contenu de la table `file_managed`
--
INSERT INTO `file_managed` (`fid`, `uid`, `filename`, `uri`, `filemime`, `filesize`, `status`, `timestamp`) VALUES
(1, 1, 'Immoweb_Info_3297871.pdf', 'public://contact/Immoweb_Info_3297871.pdf', 'application/pdf', 204029, 1, 1316119282),
(3, 1, 'php_info_esco.pdf', 'public://contact/php_info_esco.pdf', 'application/pdf', 91967, 1, 1317840181),
(4, 1, 'programme-ISQ-110627.pdf', 'public://contact/programme-ISQ-110627.pdf', 'application/pdf', 94967, 1, 1317843205),
(5, 1, 'test.swf', 'public://contact/test.swf', 'application/x-shockwave-flash', 691653, 1, 1318084021);
-- --------------------------------------------------------
--
-- Structure de la table `file_usage`
--
CREATE TABLE IF NOT EXISTS `file_usage` (
`fid` int(10) unsigned NOT NULL COMMENT 'File ID.',
`module` varchar(255) NOT NULL DEFAULT '' COMMENT 'The name of the module that is using the file.',
`type` varchar(64) NOT NULL DEFAULT '' COMMENT 'The name of the object type in which the file is used.',
`id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The primary key of the object using the file.',
`count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The number of times this file is used by this object.',
PRIMARY KEY (`fid`,`type`,`id`,`module`),
KEY `type_id` (`type`,`id`),
KEY `fid_count` (`fid`,`count`),
KEY `fid_module` (`fid`,`module`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Track where a file is used.';
--
-- Contenu de la table `file_usage`
--
INSERT INTO `file_usage` (`fid`, `module`, `type`, `id`, `count`) VALUES
(1, 'file', 'node', 5, 1),
(3, 'file', 'node', 7, 1),
(4, 'file', 'node', 6, 1),
(5, 'file', 'node', 6, 1);
-- --------------------------------------------------------
--
-- Structure de la table `node`
--
CREATE TABLE IF NOT EXISTS `node` (
`nid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The primary identifier for a node.',
`vid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The current node_revision.vid version identifier.',
`type` varchar(32) NOT NULL DEFAULT '' COMMENT 'The node_type.type of this node.',
`language` varchar(12) NOT NULL DEFAULT '' COMMENT 'The languages.language of this node.',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT 'The title of this node, always treated as non-markup plain text.',
`uid` int(11) NOT NULL DEFAULT '0' COMMENT 'The users.uid that owns this node; initially, this is the user that created it.',
`status` int(11) NOT NULL DEFAULT '1' COMMENT 'Boolean indicating whether the node is published (visible to non-administrators).',
`created` int(11) NOT NULL DEFAULT '0' COMMENT 'The Unix timestamp when the node was created.',
`changed` int(11) NOT NULL DEFAULT '0' COMMENT 'The Unix timestamp when the node was most recently saved.',
`comment` int(11) NOT NULL DEFAULT '0' COMMENT 'Whether comments are allowed on this node: 0 = no, 1 = closed (read only), 2 = open (read/write).',
`promote` int(11) NOT NULL DEFAULT '0' COMMENT 'Boolean indicating whether the node should be displayed on the front page.',
`sticky` int(11) NOT NULL DEFAULT '0' COMMENT 'Boolean indicating whether the node should be displayed at the top of lists in which it appears.',
`tnid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The translation set id for this node, which equals the node id of the source post in each set.',
`translate` int(11) NOT NULL DEFAULT '0' COMMENT 'A boolean indicating whether this translation page needs to be updated.',
PRIMARY KEY (`nid`),
UNIQUE KEY `vid` (`vid`),
KEY `node_changed` (`changed`),
KEY `node_created` (`created`),
KEY `node_frontpage` (`promote`,`status`,`sticky`,`created`),
KEY `node_status_type` (`status`,`type`,`nid`),
KEY `node_title_type` (`title`,`type`(4)),
KEY `node_type` (`type`(4)),
KEY `uid` (`uid`),
KEY `tnid` (`tnid`),
KEY `translate` (`translate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='The base table for nodes.' AUTO_INCREMENT=10 ;
--
-- Contenu de la table `node`
--
INSERT INTO `node` (`nid`, `vid`, `type`, `language`, `title`, `uid`, `status`, `created`, `changed`, `comment`, `promote`, `sticky`, `tnid`, `translate`) VALUES
(1, 1, 'page', 'fr', 'Site web de l''AIIF - IMC', 1, 1, 1310159761, 1312743877, 1, 1, 0, 0, 0),
(2, 2, 'page', 'fr', 'STATUTS DE L''A.I.I.F.-I.M.C. ASBL', 1, 1, 1313520108, 1317843954, 1, 0, 0, 0, 0),
(3, 3, 'page', 'fr', 'COMPOSITION DU CONSEIL D''ADMINISTRATION DE L''ASSOCIATION', 1, 1, 1313520739, 1317843648, 1, 0, 0, 0, 0),
(4, 4, 'page', 'fr', 'Contact', 1, 1, 1316118872, 1318152479, 1, 0, 0, 0, 0),
(5, 5, 'contact', 'fr', '27/08/11', 1, 1, 1316119282, 1316119282, 1, 0, 0, 0, 0),
(6, 6, 'contact', 'fr', '22/09/11', 1, 1, 1316119473, 1318084021, 1, 0, 0, 0, 0),
(7, 7, 'contact', 'fr', '05/10/11', 1, 1, 1317840181, 1317840181, 1, 0, 0, 0, 0),
(9, 9, 'page', 'fr', 'Contact', 1, 1, 1318090188, 1318106022, 1, 0, 0, 0, 0);[/code]