Archive for the ‘SQL of the yesterday’ Category

Search some people

Friday, January 25th, 2008 by nils


SELECT *
FROM people AS p
INNER JOIN people_category_link AS c ON p.people_id = c.people_id
INNER JOIN photocell as photo ON photo.people_id = p.people_id
WHERE (
(
(
(
(
date_of_birth <19970125
AND date_of_birth >19930125
)
OR (
date_of_birth <19670125
AND date_of_birth >19530125
)
)
AND gender = 'f'
)
OR (
(
(
date_of_birth <19870125
AND date_of_birth >19780125
)
OR (
date_of_birth <19670125
AND date_of_birth >19530125
)
)
AND gender = 'm'
)
)
AND (
category_id =9
OR category_id =10
OR category_id =4
OR category_id =1
)
AND last_name LIKE (
'%destoop%'
)
)
GROUP BY p.people_id
LIMIT 0 , 30

Trigger date in a SQL

Monday, January 21st, 2008 by nils

CREATE TRIGGER current_date
BEFORE INSERT ON b_projects
FOR EACH ROW
SET NEW.p_date = curdate();

Product Manager goes nuts

Friday, October 26th, 2007 by Thijs

Wat krijg je als je een catalogus met 7 talen moet maken?

SELECT

 `p_launchDate` AS `launchDate`,

 `p_articleId` AS `articleId`,

 `p_image` AS `image`,

 `p_pType` AS `pType`,

 `nl`.`p_productName` AS `productName_nl`,

 `nl`.`p_description` AS `description_nl`,

 `nl`.`p_availableIn` AS `availableIn_nl`,

 `nl`.`p_extraInfo` AS `extraInfo_nl`,

 `en`.`p_productName` AS `productName_en`,

 `en`.`p_description` AS `description_en`,

 `en`.`p_availableIn` AS `availableIn_en`,

 `en`.`p_extraInfo` AS `extraInfo_en`,

 `fr`.`p_productName` AS `productName_fr`,

 `fr`.`p_description` AS `description_fr`,

 `fr`.`p_availableIn` AS `availableIn_fr`,

 `fr`.`p_extraInfo` AS `extraInfo_fr`,

 `de`.`p_productName` AS `productName_de`,

 `de`.`p_description` AS `description_de`,

 `de`.`p_availableIn` AS `availableIn_de`,

 `de`.`p_extraInfo` AS `extraInfo_de`,

 `it`.`p_productName` AS `productName_it`,

 `it`.`p_description` AS `description_it`,

 `it`.`p_availableIn` AS `availableIn_it`,

 `it`.`p_extraInfo` AS `extraInfo_it`,

 `es`.`p_productName` AS `productName_es`,

 `es`.`p_description` AS `description_es`,

 `es`.`p_availableIn` AS `availableIn_es`,

 `es`.`p_extraInfo` AS `extraInfo_es`,

 `pt`.`p_productName` AS `productName_pt`,

 `pt`.`p_description` AS `description_pt`,

 `pt`.`p_availableIn` AS `availableIn_pt`,

 `pt`.`p_extraInfo` AS `extraInfo_pt`

FROM

 `products`

LEFT JOIN `products_desc` `nl` ON `products`.`p_id` = `nl`.`pd_p_id` AND `nl`.`pd_lang` = 'nl'

LEFT JOIN `products_desc` `en` ON `products`.`p_id` = `en`.`pd_p_id` AND `en`.`pd_lang` = 'en'

LEFT JOIN `products_desc` `fr` ON `products`.`p_id` = `fr`.`pd_p_id` AND `fr`.`pd_lang` = 'fr'

LEFT JOIN `products_desc` `de` ON `products`.`p_id` = `de`.`pd_p_id` AND `de`.`pd_lang` = 'de'

LEFT JOIN `products_desc` `it` ON `products`.`p_id` = `it`.`pd_p_id` AND `it`.`pd_lang` = 'it'

LEFT JOIN `products_desc` `es` ON `products`.`p_id` = `es`.`pd_p_id` AND `es`.`pd_lang` = 'es'

LEFT JOIN `products_desc` `pt` ON `products`.`p_id` = `pt`.`pd_p_id` AND `pt`.`pd_lang` = 'pt'

regulaire expressie van den dag

Wednesday, October 24th, 2007 by stalski

Geen sql of the yesterday, maar een regulaire expressie van vandaag en te gebruiken vanaf morgen :)
Theeft toch een beetje met sql te maken, namelijk de bedoeling was om uit het field-type van een database tabel zo te behandelen dat ik in
- deel 1 mijn formulier veld type heb en
- deel 2 mijn info krijg over dat veld.
De input aFieldProps[’Type’] is een resultaat verkregen door een DESCRIBE op de tabel in kwestie.

$bMatched = preg_match(’/(^[a-zA-Z]+)\(([^.]+)\)$/’, $aFieldProps[’Type’], $aTypeMatches);

Resultaat:

Array
(
    [0] => varchar(150)
    [1] => varchar
    [2] => 150
)
Array
(
    [0] => enum('hotel','restaurant')
    [1] => enum
    [2] => 'hotel','restaurant'
)
Array
(
    [0] => int(6)
    [1] => int
    [2] => 6
)
Array
(
    [0] => bigint(13)
    [1] => bigint
    [2] => 13
)

Naast deze info krijg je uit de describe de auto-increment, MUL als external key, de default value en is null kun je behandelen als required or not.

Genoeg informatie dus om je formulier uit een database tabel te genereren. :)

Do not forget!

Wednesday, October 10th, 2007 by Thijs

Exploits