/*
* phpMyEdit - instant MySQL table editor and code generator
*
* examples/exampledb.sql - create example database for testing
* ____________________________________________________________
*
* Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net>
* Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net>
* Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net>
* Versions 5.7.2 and higher developed by Yves De Billoëz
* Copyright (c) 2002-2006 Platon Group, http://platon.sk/
* All rights reserved.
*
* See README.md file for more information about this software.
* See COPYING file for license information.
*
* Download the latest version from
* https://sourceforge.net/projects/phpmariaedit/
*/
USE `phpMyEditExamples`;
/* $Platon: phpMyEdit/examples/exampledb.sql,v 5.7.6 2024-01-15 12:57:07 Yves $ */
/* countries table */
/* we need to drop taxrates before dropping countries */
DROP TABLE IF EXISTS `taxrates`;
DROP TABLE IF EXISTS `countries`;
CREATE TABLE `countries` (
`co_name` VARCHAR(60) NOT NULL,
`co_name_en` VARCHAR(60),
`co_code` CHAR(2) NOT NULL,
`co_alpha3code` CHAR(3),
`co_numcode` CHAR(3),
`co_telprefix` CHAR(6),
`co_internetsuffix` VARCHAR(30),
`co_flagimg` BLOB,
`co_imgfromsky` BLOB,
`co_introduction` TEXT,
`co_centre` POINT,
`co_area` POLYGON,
`creation_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE `countries`
ADD `rowid` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
ALTER TABLE `countries` MODIFY COLUMN `co_imgfromsky` LONGBLOB;
ALTER TABLE `countries`
COMMENT = 'specific test for TEXT, BLOB, POINT and POLYGON fields, unique key';
ALTER TABLE `countries`
ADD UNIQUE KEY `co_code_ukey` (`co_code`);
INSERT INTO `countries`
(`co_name`, `co_name_en`, `co_code`, `co_telprefix`, `co_internetsuffix`)
VALUES
('België/Belgique/Belgien', 'Belgium', 'BE', '+32', '.be'),
('Canada', 'Canada', 'CA', '+1', '.ca'),
('France', 'France', 'FR', '+33', '.fr'),
('India', 'India', 'IN', '+91', '.in'),
('La République Démocratique du Congo', 'Democratic Republic of Congo (DRC)', 'CD', '+243', '.cd'),
('United States of America', 'United States of America', 'US', '+1', '.us'),
('United Kingdom', 'United Kingdom', 'UK', '+44', '.uk');
/* taxrates table */
DROP TABLE IF EXISTS `taxrates`;
CREATE TABLE `taxrates` (
`tr_name` VARCHAR(60) NOT NULL,
`tr_name_en` VARCHAR(60),
`tr_code` CHAR(8) NOT NULL,
`tr_country_code` CHAR(2),
`tr_rate` DECIMAL(5,2) NOT NULL DEFAULT 0.0,
`creation_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE `taxrates`
ADD `rowid` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
ALTER TABLE `taxrates`
COMMENT = 'specific test for foreign key to countries, unique key constraint';
ALTER TABLE `taxrates`
ADD UNIQUE KEY `taxrates_ukey` (`tr_code`, `tr_country_code`);
ALTER TABLE `taxrates`
ADD CONSTRAINT `FK_taxrates_countries`
FOREIGN KEY (`tr_country_code`) REFERENCES `countries`(`co_code`);
INSERT INTO `taxrates`
(`tr_name`, `tr_name_en`, `tr_code`, `tr_country_code`, `tr_rate`)
VALUES
('BTW/TVA', 'Value Added Tax (VAT)', 'VAT1', 'BE', 21.5),
('TVA', 'Value Added Tax (VAT)', 'VAT1', 'CD', 16.0),
('Taxe sur le revenue', 'Revenue tax', 'ART15', 'CD', 0.0);
/* products table */
DROP TRIGGER IF EXISTS `products_before_insert`;
DROP TRIGGER IF EXISTS `products_before_update`;
DROP TABLE IF EXISTS `products`;
CREATE TABLE `products` (
`pr_code` CHAR(8) NOT NULL COMMENT 'the product code, uppercase',
`pr_name` VARCHAR(60) NOT NULL COMMENT 'the product code',
`status_code` CHAR(1) DEFAULT 'C' COMMENT 'valid codes: see table pme_statuscodes'
);
ALTER TABLE `products`
COMMENT = 'specific test for no primary key, comments on table and column';
ALTER TABLE `products`
ADD UNIQUE KEY `pr_code_ukey` (`pr_code`);
ALTER TABLE `products`
ADD CONSTRAINT `FK_products_statuscodes`
FOREIGN KEY (`status_code`) REFERENCES `pme_statuscodes`(`code`);
DELIMITER $$
CREATE TRIGGER `products_before_insert` BEFORE INSERT
ON `products` FOR EACH ROW
BEGIN
IF (NEW.`pr_code` IS NULL) THEN SET NEW.`pr_code` = NEW.`pr_name`; END IF;
SET NEW.`pr_code` = UPPER(NEW.`pr_code`);
IF (NEW.`status_code` IS NULL) THEN SET NEW.`status_code` = 'C'; END IF;
END
$$
CREATE TRIGGER `products_before_update` BEFORE UPDATE
ON `products` FOR EACH ROW
BEGIN
IF NEW.`status_code` = OLD.`status_code` THEN
/* set status code only if it has not been changed by the
statement
*/
SET NEW.`status_code` = 'M';
END IF;
IF (NEW.`pr_code` IS NULL) THEN SET NEW.`pr_code` = NEW.`pr_name`; END IF;
IF NEW.`pr_code` != OLD.`pr_code` THEN
SET NEW.`pr_code` = UPPER(NEW.`pr_code`);
END IF;
END
$$
DELIMITER ;
INSERT INTO `products`
(`pr_code`, `pr_name`)
VALUES
('Poule', 'Poule'),
('Chevre', 'Chevre'),
('Vache', 'Vache');
/* incidents table */
DROP TABLE IF EXISTS `incidents`;
CREATE TABLE `incidents` (
`nmbr` INT(10) NOT NULL,
`title` VARCHAR(60) NOT NULL,
`summary` TEXT,
`full_desciption` TEXT,
`importance` ENUM('very', 'normal', 'n.a.') DEFAULT 'normal' COMMENT 'single select',
`impacts` SET('client software', 'server software') COMMENT 'multi-select',
`reporting_year` YEAR,
`opening_date` DATE,
`opening_time` TIME,
`approx_percentage` FLOAT(10) COMMENT 'approximate value',
`absolute_percentage` DECIMAL(6,2) COMMENT 'real value, -100.00 - +100.00',
`total_csost` NUMERIC COMMENT 'real value',
`mask_special` BIT(15) COMMENT 'bitmask',
`metadata` JSON COMMENT 'structured data',
`system_dump` BLOB COMMENT 'binary image',
`creation_date` TIMESTAMP DEFAULT current_timestamp() COMMENT 'created on',
`modification_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'last updated on'
);
ALTER TABLE `incidents`
ADD `rowid` INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY FIRST;
-- tables are modfied after creation, as certain types might not be
-- supported, so script fails on specific unsupported type
ALTER TABLE `incidents` MODIFY COLUMN `summary` TINYTEXT;
ALTER TABLE `incidents` MODIFY COLUMN `full_desciption` LONGTEXT;
ALTER TABLE `incidents` MODIFY COLUMN `system_dump` LONGBLOB;
ALTER TABLE `incidents`
MODIFY COLUMN `modification_date` timestamp NOT NULL DEFAULT current_timestamp()
ON UPDATE current_timestamp();
ALTER TABLE `incidents`
COMMENT = 'test different field types';
ALTER TABLE `incidents`
ADD UNIQUE KEY `nmbr_ukey` (`nmbr`);
/* eof */