summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Dorn <jeremy@jeremydorn.com>2013-06-12 20:56:09 -0700
committerJeremy Dorn <jeremy@jeremydorn.com>2013-06-12 20:56:09 -0700
commit3c7983d6d638233ea8e0e7705a3a8f3e4921ca75 (patch)
treeeb22ed4f7f26107be94eedcbeedcce16162b89ae
parentbd1f09133f6dbbe0713856910e58ea9480c2be58 (diff)
downloadsql-formatter-3c7983d6d638233ea8e0e7705a3a8f3e4921ca75.zip
sql-formatter-3c7983d6d638233ea8e0e7705a3a8f3e4921ca75.tar.gz
sql-formatter-3c7983d6d638233ea8e0e7705a3a8f3e4921ca75.tar.bz2
Added new compress method. Fixes #41
Added test cases for CLI mode and compress method. Bumped patch version.
-rw-r--r--README.md30
-rw-r--r--examples/examples.php24
-rw-r--r--lib/SqlFormatter.php44
-rw-r--r--tests/SqlFormatterTest.php55
-rw-r--r--tests/clihighlight.html245
-rw-r--r--tests/compress.html67
6 files changed, 459 insertions, 6 deletions
diff --git a/README.md b/README.md
index d9a9942..a144323 100644
--- a/README.md
+++ b/README.md
@@ -75,10 +75,36 @@ Output:
![](http://jdorn.github.com/sql-formatter/highlight.png)
+Compress Query
+--------------------------
+
+The compress method removes all comments and compresses whitespace.
+
+This is useful for outputting queries that can be copy pasted to the command line easily.
+
+```
+-- This is a comment
+ SELECT
+ /* This is another comment
+ On more than one line */
+ Id #This is one final comment
+ as temp, DateCreated as Created FROM MyTable;
+```
+
+```php
+echo SqlFormatter::compress($query)
+```
+
+Output:
+
+```
+SELECT Id as temp, DateCreated as Created FROM MyTable;
+```
+
Remove Comments
------------------------
-
-There is a removeComments method that, you guessed it, removes all comments from a query.
+If you want to keep all original whitespace formatting and just remove comments,
+you can use the removeComments method instead of compress.
```
-- This is a comment
diff --git a/examples/examples.php b/examples/examples.php
index 0d3c641..9d69182 100644
--- a/examples/examples.php
+++ b/examples/examples.php
@@ -183,6 +183,30 @@ $comment_statements = array(
</table>
+<h1>Compress Query</h1>
+
+<div>
+ Usage:
+ <pre>
+ <?php highlight_string('<?php' . "\n" . '$compressed = SqlFormatter::compress($sql);' . "\n" . '?>'); ?>
+ </pre>
+</div>
+<table>
+ <tr>
+ <th>Original</th>
+ <th>Compressed</th>
+ </tr>
+ <?php foreach ($statements as $sql) { ?>
+ <tr>
+ <td>
+ <pre><?php echo $sql; ?></pre>
+ </td>
+ <td><pre><?php echo SqlFormatter::compress($sql); ?></pre></td>
+ </tr>
+ <?php } ?>
+</table>
+
+
<h1>Splitting SQL Strings Into Individual Queries</h1>
<div>
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php
index fec46e3..3a511a7 100644
--- a/lib/SqlFormatter.php
+++ b/lib/SqlFormatter.php
@@ -9,7 +9,7 @@
* @copyright 2013 Jeremy Dorn
* @license http://opensource.org/licenses/MIT
* @link http://github.com/jdorn/sql-formatter
- * @version 1.2.9
+ * @version 1.2.10
*/
class SqlFormatter
{
@@ -701,6 +701,48 @@ class SqlFormatter
}
/**
+ * Compress a query by collapsing white space and removing comments
+ *
+ * @param String $string The SQL string
+ *
+ * @return String The SQL string without comments
+ */
+ public static function compress($string)
+ {
+ $result = '';
+
+ $tokens = self::tokenize($string);
+
+
+ $whitespace = true;
+ foreach ($tokens as $token) {
+ // Skip comment tokens
+ if ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_COMMENT || $token[self::TOKEN_TYPE] === self::TOKEN_TYPE_BLOCK_COMMENT) {
+ continue;
+ }
+
+ if($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_WHITESPACE) {
+ // If the last token was whitespace, don't add another one
+ if($whitespace) {
+ continue;
+ }
+ else {
+ $whitespace = true;
+ // Convert all whitespace to a single space
+ $token[self::TOKEN_VALUE] = ' ';
+ }
+ }
+ else {
+ $whitespace = false;
+ }
+
+ $result .= $token[self::TOKEN_VALUE];
+ }
+
+ return rtrim($result);
+ }
+
+ /**
* Highlights a token depending on its type.
*
* @param Array $token An associative array containing type and value.
diff --git a/tests/SqlFormatterTest.php b/tests/SqlFormatterTest.php
index a1679b9..2c587e4 100644
--- a/tests/SqlFormatterTest.php
+++ b/tests/SqlFormatterTest.php
@@ -25,6 +25,20 @@ class SqlFormatterTest extends PHPUnit_Framework_TestCase {
function testHighlight($sql, $html) {
$this->assertEquals(trim($html), trim(SqlFormatter::highlight($sql)));
}
+ /**
+ * @dataProvider highlightCliData
+ */
+ function testCliHighlight($sql, $html) {
+ SqlFormatter::$cli = true;
+ $this->assertEquals(trim($html), trim(SqlFormatter::highlight($sql)));
+ SqlFormatter::$cli = false;
+ }
+ /**
+ * @dataProvider compressData
+ */
+ function testCompress($sql, $html) {
+ $this->assertEquals(trim($html), trim(SqlFormatter::compress($sql)));
+ }
function testUsePre() {
SqlFormatter::$use_pre = false;
@@ -82,7 +96,20 @@ class SqlFormatterTest extends PHPUnit_Framework_TestCase {
);
}
- //$return = array_slice($return, 0, 50);
+ return $return;
+ }
+
+ function highlightCliData() {
+ $clidata = explode("\n\n",file_get_contents(__DIR__."/clihighlight.html"));
+ $sqlData = $this->sqlData();
+
+ $return = array();
+ foreach($clidata as $i=>$data) {
+ $return[] = array(
+ $sqlData[$i],
+ $data
+ );
+ }
return $return;
}
@@ -99,7 +126,21 @@ class SqlFormatterTest extends PHPUnit_Framework_TestCase {
);
}
- //$return = array_slice($return, 0, 50);
+ return $return;
+ }
+
+ function compressData() {
+ $compressData = explode("\n\n",file_get_contents(__DIR__."/compress.html"));
+ $sqlData = $this->sqlData();
+
+ $return = array();
+ foreach($compressData as $i=>$data) {
+ $return[] = array(
+ $sqlData[$i],
+ $data
+ );
+ }
+
return $return;
}
@@ -115,7 +156,6 @@ class SqlFormatterTest extends PHPUnit_Framework_TestCase {
);
}
- //$return = array_slice($return, 0, 50);
return $return;
}
@@ -130,16 +170,25 @@ class SqlFormatterTest extends PHPUnit_Framework_TestCase {
$formatHighlight = array();
$highlight = array();
$format = array();
+ $compress = array();
+ $clihighlight = array();
foreach($this->sqlData as $sql) {
$formatHighlight[] = trim(SqlFormatter::format($sql));
$highlight[] = trim(SqlFormatter::highlight($sql));
$format[] = trim(SqlFormatter::format($sql, false));
+ $compress[] = trim(SqlFormatter::compress($sql));
+
+ SqlFormatter::$cli = true;
+ $clihighlight[] = trim(SqlFormatter::highlight($sql));
+ SqlFormatter::$cli = false;
}
file_put_contents(__DIR__."/format-highlight.html", implode("\n\n",$formatHighlight));
file_put_contents(__DIR__."/highlight.html", implode("\n\n",$highlight));
file_put_contents(__DIR__."/format.html", implode("\n\n",$format));
+ file_put_contents(__DIR__."/compress.html", implode("\n\n",$compress));
+ file_put_contents(__DIR__."/clihighlight.html", implode("\n\n",$clihighlight));
/**/
return $this->sqlData;
diff --git a/tests/clihighlight.html b/tests/clihighlight.html
new file mode 100644
index 0000000..936df43
--- /dev/null
+++ b/tests/clihighlight.html
@@ -0,0 +1,245 @@
+SELECT customer_id, customer_name, COUNT(order_id) as total
+FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
+GROUP BY customer_id, customer_name
+HAVING COUNT(order_id) > 5
+ORDER BY COUNT(order_id) DESC;
+
+UPDATE customers
+ SET totalorders = ordersummary.total
+ FROM (SELECT customer_id, count(order_id) As total
+FROM orders GROUP BY customer_id) As ordersummary
+ WHERE customers.customer_id = ordersummary.customer_id
+
+SELECT * FROM sometable
+UNION ALL
+SELECT * FROM someothertable;
+
+SET NAMES 'utf8';
+
+CREATE TABLE `PREFIX_address` (
+ `id_address` int(10) unsigned NOT NULL auto_increment,
+ `id_country` int(10) unsigned NOT NULL,
+ `id_state` int(10) unsigned default NULL,
+ `id_customer` int(10) unsigned NOT NULL default '0',
+ `id_manufacturer` int(10) unsigned NOT NULL default '0',
+ `id_supplier` int(10) unsigned NOT NULL default '0',
+ `id_warehouse` int(10) unsigned NOT NULL default '0',
+ `alias` varchar(32) NOT NULL,
+ `company` varchar(64) default NULL,
+ `lastname` varchar(32) NOT NULL,
+ `firstname` varchar(32) NOT NULL,
+ `address1` varchar(128) NOT NULL,
+ `address2` varchar(128) default NULL,
+ `postcode` varchar(12) default NULL,
+ `city` varchar(64) NOT NULL,
+ `other` text,
+ `phone` varchar(16) default NULL,
+ `phone_mobile` varchar(16) default NULL,
+ `vat_number` varchar(32) default NULL,
+ `dni` varchar(16) DEFAULT NULL,
+ `date_add` datetime NOT NULL,
+ `date_upd` datetime NOT NULL,
+ `active` tinyint(1) unsigned NOT NULL default '1',
+ `deleted` tinyint(1) unsigned NOT NULL default '0',
+ PRIMARY KEY (`id_address`),
+ KEY `address_customer` (`id_customer`),
+ KEY `id_country` (`id_country`),
+ KEY `id_state` (`id_state`),
+ KEY `id_manufacturer` (`id_manufacturer`),
+ KEY `id_supplier` (`id_supplier`),
+ KEY `id_warehouse` (`id_warehouse`)
+) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+CREATE TABLE `PREFIX_alias` (
+ `id_alias` int(10) unsigned NOT NULL auto_increment,
+ `alias` varchar(255) NOT NULL,
+ `search` varchar(255) NOT NULL,
+ `active` tinyint(1) NOT NULL default '1',
+ PRIMARY KEY (`id_alias`),
+ UNIQUE KEY `alias` (`alias`)
+) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+CREATE TABLE `PREFIX_carrier` (
+ `id_carrier` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `id_reference` int(10) unsigned NOT NULL,
+ `id_tax_rules_group` int(10) unsigned DEFAULT '0',
+ `name` varchar(64) NOT NULL,
+ `url` varchar(255) DEFAULT NULL,
+ `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `shipping_handling` tinyint(1) unsigned NOT NULL DEFAULT '1',
+ `range_behavior` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `is_module` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `is_free` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `shipping_external` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `need_range` tinyint(1) unsigned NOT NULL DEFAULT '0',
+ `external_module_name` varchar(64) DEFAULT NULL,
+ `shipping_method` int(2) NOT NULL DEFAULT '0',
+ `position` int(10) unsigned NOT NULL default '0',
+ `max_width` int(10) DEFAULT 0,
+ `max_height` int(10) DEFAULT 0,
+ `max_depth` int(10) DEFAULT 0,
+ `max_weight` int(10) DEFAULT 0,
+ `grade` int(10) DEFAULT 0,
+ PRIMARY KEY (`id_carrier`),
+ KEY `deleted` (`deleted`,`active`),
+ KEY `id_tax_rules_group` (`id_tax_rules_group`)
+) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+CREATE TABLE IF NOT EXISTS `PREFIX_specific_price_rule` (
+ `id_specific_price_rule` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` VARCHAR(255) NOT NULL,
+ `id_shop` int(11) unsigned NOT NULL DEFAULT '1',
+ `id_currency` int(10) unsigned NOT NULL,
+ `id_country` int(10) unsigned NOT NULL,
+ `id_group` int(10) unsigned NOT NULL,
+ `from_quantity` mediumint(8) unsigned NOT NULL,
+ `price` DECIMAL(20,6),
+ `reduction` decimal(20,6) NOT NULL,
+ `reduction_type` enum('amount','percentage') NOT NULL,
+ `from` datetime NOT NULL,
+ `to` datetime NOT NULL,
+ PRIMARY KEY (`id_specific_price_rule`),
+ KEY `id_product` (`id_shop`,`id_currency`,`id_country`,`id_group`,`from_quantity`,`from`,`to`)
+) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+UPDATE `PREFIX_configuration` SET value = '6' WHERE name = 'PS_SEARCH_WEIGHT_PNAME'
+
+UPDATE `PREFIX_hook_module` SET position = 1
+WHERE
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayPayment') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'cheque')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayPaymentReturn') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'cheque')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayHome') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'homeslider')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionAuthentication') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statsdata')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionShopDataDuplication') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'homeslider')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayTop') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blocklanguages')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCustomerAccountAdd') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statsdata')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayCustomerAccount') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'favoriteproducts')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayAdminStatsModules') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statsvisits')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayAdminStatsGraphEngine') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'graphvisifire')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayAdminStatsGridEngine') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'gridhtml')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayLeftColumnProduct') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blocksharefb')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionSearch') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statssearch')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCategoryAdd') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCategoryUpdate') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCategoryDelete') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionAdminMetaSave') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayMyAccountBlock') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'favoriteproducts')
+ OR
+ id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayFooter') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockreinsurance')
+
+ALTER TABLE `PREFIX_employee` ADD `bo_color` varchar(32) default NULL AFTER `stats_date_to`
+
+INSERT INTO `PREFIX_cms_category_lang` VALUES(1, 3, 'Inicio', '', 'home', NULL, NULL, NULL)
+
+INSERT INTO `PREFIX_cms_category` VALUES(1, 0, 0, 1, NOW(), NOW(),0)
+
+UPDATE `PREFIX_cms_category` SET `position` = 0
+
+ALTER TABLE `PREFIX_customer` ADD `note` text AFTER `secure_key`
+
+ALTER TABLE `PREFIX_contact` ADD `customer_service` tinyint(1) NOT NULL DEFAULT 0 AFTER `email`
+
+INSERT INTO `PREFIX_specific_price` (`id_product`, `id_shop`, `id_currency`, `id_country`, `id_group`, `priority`, `price`, `from_quantity`, `reduction`, `reduction_type`, `from`, `to`)
+ ( SELECT dq.`id_product`, 1, 1, 0, 1, 0, 0.00, dq.`quantity`, IF(dq.`id_discount_type` = 2, dq.`value`, dq.`value` / 100), IF (dq.`id_discount_type` = 2, 'amount', 'percentage'), '0000-00-00 00:00:00', '0000-00-00 00:00:00'
+ FROM `PREFIX_discount_quantity` dq
+ INNER JOIN `PREFIX_product` p ON (p.`id_product` = dq.`id_product`)
+ )
+
+DROP TABLE `PREFIX_discount_quantity`
+
+INSERT INTO `PREFIX_specific_price` (`id_product`, `id_shop`, `id_currency`, `id_country`, `id_group`, `priority`, `price`, `from_quantity`, `reduction`, `reduction_type`, `from`, `to`) (
+ SELECT
+ p.`id_product`,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0.00,
+ 1,
+ IF(p.`reduction_price` > 0, p.`reduction_price`, p.`reduction_percent` / 100),
+ IF(p.`reduction_price` > 0, 'amount', 'percentage'),
+ IF (p.`reduction_from` = p.`reduction_to`, '0000-00-00 00:00:00', p.`reduction_from`),
+ IF (p.`reduction_from` = p.`reduction_to`, '0000-00-00 00:00:00', p.`reduction_to`)
+ FROM `PREFIX_product` p
+ WHERE p.`reduction_price` OR p.`reduction_percent`
+)
+
+ALTER TABLE `PREFIX_product`
+ DROP `reduction_price`,
+ DROP `reduction_percent`,
+ DROP `reduction_from`,
+ DROP `reduction_to`
+
+INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES
+('PS_SPECIFIC_PRICE_PRIORITIES', 'id_shop;id_currency;id_country;id_group', NOW(), NOW()),
+('PS_TAX_DISPLAY', 0, NOW(), NOW()),
+('PS_SMARTY_FORCE_COMPILE', 1, NOW(), NOW()),
+('PS_DISTANCE_UNIT', 'km', NOW(), NOW()),
+('PS_STORES_DISPLAY_CMS', 0, NOW(), NOW()),
+('PS_STORES_DISPLAY_FOOTER', 0, NOW(), NOW()),
+('PS_STORES_SIMPLIFIED', 0, NOW(), NOW()),
+('PS_STATSDATA_CUSTOMER_PAGESVIEWS', 1, NOW(), NOW()),
+('PS_STATSDATA_PAGESVIEWS', 1, NOW(), NOW()),
+('PS_STATSDATA_PLUGINS', 1, NOW(), NOW())
+
+INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES ('PS_CONDITIONS_CMS_ID', IFNULL((SELECT `id_cms` FROM `PREFIX_cms` WHERE `id_cms` = 3), 0), NOW(), NOW())
+
+CREATE TEMPORARY TABLE `PREFIX_configuration_tmp` (
+ `value` text
+)
+
+SET @defaultOOS = (SELECT value FROM `PREFIX_configuration` WHERE name = 'PS_ORDER_OUT_OF_STOCK')
+
+UPDATE `PREFIX_product` p SET `cache_default_attribute` = 0 WHERE `id_product` NOT IN (SELECT `id_product` FROM `PREFIX_product_attribute`)
+
+INSERT INTO `PREFIX_hook` (`name`, `title`, `description`, `position`) VALUES ('processCarrier', 'Carrier Process', NULL, 0)
+
+INSERT INTO `PREFIX_stock_mvt_reason_lang` (`id_stock_mvt_reason`, `id_lang`, `name`) VALUES
+(1, 1, 'Order'),
+(1, 2, 'Commande'),
+(2, 1, 'Missing Stock Movement'),
+(2, 2, 'Mouvement de stock manquant'),
+(3, 1, 'Restocking'),
+(3, 2, 'Réassort')
+
+INSERT INTO `PREFIX_meta_lang` (`id_lang`, `id_meta`, `title`, `url_rewrite`) VALUES
+(1, (SELECT `id_meta` FROM `PREFIX_meta` WHERE `page` = 'authentication'), 'Authentication', 'authentication'),
+(2, (SELECT `id_meta` FROM `PREFIX_meta` WHERE `page` = 'authentication'), 'Authentification', 'authentification'),
+(3, (SELECT `id_meta` FROM `PREFIX_meta` WHERE `page` = 'authentication'), 'Autenticación', 'autenticacion')
+
+LOCK TABLES `admin_assert` WRITE
+
+UNLOCK TABLES
+
+DROP TABLE IF EXISTS `admin_role`
+
+SELECT * FROM
+-- This is another comment
+MyTable # One final comment
+/* This is a block comment
+*/ WHERE 1 = 2;
+
+SELECT -- This is a test
+
+SELECT Test FROM Test WHERE
+(
+ MyColumn = 1 )) AND ((( SomeOtherColumn = 2); \ No newline at end of file
diff --git a/tests/compress.html b/tests/compress.html
new file mode 100644
index 0000000..24fb38e
--- /dev/null
+++ b/tests/compress.html
@@ -0,0 +1,67 @@
+SELECT customer_id, customer_name, COUNT(order_id) as total FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id GROUP BY customer_id, customer_name HAVING COUNT(order_id) > 5 ORDER BY COUNT(order_id) DESC;
+
+UPDATE customers SET totalorders = ordersummary.total FROM (SELECT customer_id, count(order_id) As total FROM orders GROUP BY customer_id) As ordersummary WHERE customers.customer_id = ordersummary.customer_id
+
+SELECT * FROM sometable UNION ALL SELECT * FROM someothertable;
+
+SET NAMES 'utf8';
+
+CREATE TABLE `PREFIX_address` ( `id_address` int(10) unsigned NOT NULL auto_increment, `id_country` int(10) unsigned NOT NULL, `id_state` int(10) unsigned default NULL, `id_customer` int(10) unsigned NOT NULL default '0', `id_manufacturer` int(10) unsigned NOT NULL default '0', `id_supplier` int(10) unsigned NOT NULL default '0', `id_warehouse` int(10) unsigned NOT NULL default '0', `alias` varchar(32) NOT NULL, `company` varchar(64) default NULL, `lastname` varchar(32) NOT NULL, `firstname` varchar(32) NOT NULL, `address1` varchar(128) NOT NULL, `address2` varchar(128) default NULL, `postcode` varchar(12) default NULL, `city` varchar(64) NOT NULL, `other` text, `phone` varchar(16) default NULL, `phone_mobile` varchar(16) default NULL, `vat_number` varchar(32) default NULL, `dni` varchar(16) DEFAULT NULL, `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, `active` tinyint(1) unsigned NOT NULL default '1', `deleted` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`id_address`), KEY `address_customer` (`id_customer`), KEY `id_country` (`id_country`), KEY `id_state` (`id_state`), KEY `id_manufacturer` (`id_manufacturer`), KEY `id_supplier` (`id_supplier`), KEY `id_warehouse` (`id_warehouse`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+CREATE TABLE `PREFIX_alias` ( `id_alias` int(10) unsigned NOT NULL auto_increment, `alias` varchar(255) NOT NULL, `search` varchar(255) NOT NULL, `active` tinyint(1) NOT NULL default '1', PRIMARY KEY (`id_alias`), UNIQUE KEY `alias` (`alias`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+CREATE TABLE `PREFIX_carrier` ( `id_carrier` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_reference` int(10) unsigned NOT NULL, `id_tax_rules_group` int(10) unsigned DEFAULT '0', `name` varchar(64) NOT NULL, `url` varchar(255) DEFAULT NULL, `active` tinyint(1) unsigned NOT NULL DEFAULT '0', `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0', `shipping_handling` tinyint(1) unsigned NOT NULL DEFAULT '1', `range_behavior` tinyint(1) unsigned NOT NULL DEFAULT '0', `is_module` tinyint(1) unsigned NOT NULL DEFAULT '0', `is_free` tinyint(1) unsigned NOT NULL DEFAULT '0', `shipping_external` tinyint(1) unsigned NOT NULL DEFAULT '0', `need_range` tinyint(1) unsigned NOT NULL DEFAULT '0', `external_module_name` varchar(64) DEFAULT NULL, `shipping_method` int(2) NOT NULL DEFAULT '0', `position` int(10) unsigned NOT NULL default '0', `max_width` int(10) DEFAULT 0, `max_height` int(10) DEFAULT 0, `max_depth` int(10) DEFAULT 0, `max_weight` int(10) DEFAULT 0, `grade` int(10) DEFAULT 0, PRIMARY KEY (`id_carrier`), KEY `deleted` (`deleted`,`active`), KEY `id_tax_rules_group` (`id_tax_rules_group`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+CREATE TABLE IF NOT EXISTS `PREFIX_specific_price_rule` ( `id_specific_price_rule` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `id_shop` int(11) unsigned NOT NULL DEFAULT '1', `id_currency` int(10) unsigned NOT NULL, `id_country` int(10) unsigned NOT NULL, `id_group` int(10) unsigned NOT NULL, `from_quantity` mediumint(8) unsigned NOT NULL, `price` DECIMAL(20,6), `reduction` decimal(20,6) NOT NULL, `reduction_type` enum('amount','percentage') NOT NULL, `from` datetime NOT NULL, `to` datetime NOT NULL, PRIMARY KEY (`id_specific_price_rule`), KEY `id_product` (`id_shop`,`id_currency`,`id_country`,`id_group`,`from_quantity`,`from`,`to`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8
+
+UPDATE `PREFIX_configuration` SET value = '6' WHERE name = 'PS_SEARCH_WEIGHT_PNAME'
+
+UPDATE `PREFIX_hook_module` SET position = 1 WHERE id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayPayment') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'cheque') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayPaymentReturn') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'cheque') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayHome') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'homeslider') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionAuthentication') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statsdata') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionShopDataDuplication') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'homeslider') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayTop') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blocklanguages') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCustomerAccountAdd') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statsdata') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayCustomerAccount') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'favoriteproducts') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayAdminStatsModules') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statsvisits') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayAdminStatsGraphEngine') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'graphvisifire') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayAdminStatsGridEngine') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'gridhtml') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayLeftColumnProduct') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blocksharefb') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionSearch') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'statssearch') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCategoryAdd') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCategoryUpdate') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionCategoryDelete') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'actionAdminMetaSave') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockcategories') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayMyAccountBlock') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'favoriteproducts') OR id_hook = (SELECT id_hook FROM `PREFIX_hook` WHERE name = 'displayFooter') AND id_module = (SELECT id_module FROM `PREFIX_module` WHERE name = 'blockreinsurance')
+
+ALTER TABLE `PREFIX_employee` ADD `bo_color` varchar(32) default NULL AFTER `stats_date_to`
+
+INSERT INTO `PREFIX_cms_category_lang` VALUES(1, 3, 'Inicio', '', 'home', NULL, NULL, NULL)
+
+INSERT INTO `PREFIX_cms_category` VALUES(1, 0, 0, 1, NOW(), NOW(),0)
+
+UPDATE `PREFIX_cms_category` SET `position` = 0
+
+ALTER TABLE `PREFIX_customer` ADD `note` text AFTER `secure_key`
+
+ALTER TABLE `PREFIX_contact` ADD `customer_service` tinyint(1) NOT NULL DEFAULT 0 AFTER `email`
+
+INSERT INTO `PREFIX_specific_price` (`id_product`, `id_shop`, `id_currency`, `id_country`, `id_group`, `priority`, `price`, `from_quantity`, `reduction`, `reduction_type`, `from`, `to`) ( SELECT dq.`id_product`, 1, 1, 0, 1, 0, 0.00, dq.`quantity`, IF(dq.`id_discount_type` = 2, dq.`value`, dq.`value` / 100), IF (dq.`id_discount_type` = 2, 'amount', 'percentage'), '0000-00-00 00:00:00', '0000-00-00 00:00:00' FROM `PREFIX_discount_quantity` dq INNER JOIN `PREFIX_product` p ON (p.`id_product` = dq.`id_product`) )
+
+DROP TABLE `PREFIX_discount_quantity`
+
+INSERT INTO `PREFIX_specific_price` (`id_product`, `id_shop`, `id_currency`, `id_country`, `id_group`, `priority`, `price`, `from_quantity`, `reduction`, `reduction_type`, `from`, `to`) ( SELECT p.`id_product`, 1, 0, 0, 0, 0, 0.00, 1, IF(p.`reduction_price` > 0, p.`reduction_price`, p.`reduction_percent` / 100), IF(p.`reduction_price` > 0, 'amount', 'percentage'), IF (p.`reduction_from` = p.`reduction_to`, '0000-00-00 00:00:00', p.`reduction_from`), IF (p.`reduction_from` = p.`reduction_to`, '0000-00-00 00:00:00', p.`reduction_to`) FROM `PREFIX_product` p WHERE p.`reduction_price` OR p.`reduction_percent` )
+
+ALTER TABLE `PREFIX_product` DROP `reduction_price`, DROP `reduction_percent`, DROP `reduction_from`, DROP `reduction_to`
+
+INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES ('PS_SPECIFIC_PRICE_PRIORITIES', 'id_shop;id_currency;id_country;id_group', NOW(), NOW()), ('PS_TAX_DISPLAY', 0, NOW(), NOW()), ('PS_SMARTY_FORCE_COMPILE', 1, NOW(), NOW()), ('PS_DISTANCE_UNIT', 'km', NOW(), NOW()), ('PS_STORES_DISPLAY_CMS', 0, NOW(), NOW()), ('PS_STORES_DISPLAY_FOOTER', 0, NOW(), NOW()), ('PS_STORES_SIMPLIFIED', 0, NOW(), NOW()), ('PS_STATSDATA_CUSTOMER_PAGESVIEWS', 1, NOW(), NOW()), ('PS_STATSDATA_PAGESVIEWS', 1, NOW(), NOW()), ('PS_STATSDATA_PLUGINS', 1, NOW(), NOW())
+
+INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES ('PS_CONDITIONS_CMS_ID', IFNULL((SELECT `id_cms` FROM `PREFIX_cms` WHERE `id_cms` = 3), 0), NOW(), NOW())
+
+CREATE TEMPORARY TABLE `PREFIX_configuration_tmp` ( `value` text )
+
+SET @defaultOOS = (SELECT value FROM `PREFIX_configuration` WHERE name = 'PS_ORDER_OUT_OF_STOCK')
+
+UPDATE `PREFIX_product` p SET `cache_default_attribute` = 0 WHERE `id_product` NOT IN (SELECT `id_product` FROM `PREFIX_product_attribute`)
+
+INSERT INTO `PREFIX_hook` (`name`, `title`, `description`, `position`) VALUES ('processCarrier', 'Carrier Process', NULL, 0)
+
+INSERT INTO `PREFIX_stock_mvt_reason_lang` (`id_stock_mvt_reason`, `id_lang`, `name`) VALUES (1, 1, 'Order'), (1, 2, 'Commande'), (2, 1, 'Missing Stock Movement'), (2, 2, 'Mouvement de stock manquant'), (3, 1, 'Restocking'), (3, 2, 'Réassort')
+
+INSERT INTO `PREFIX_meta_lang` (`id_lang`, `id_meta`, `title`, `url_rewrite`) VALUES (1, (SELECT `id_meta` FROM `PREFIX_meta` WHERE `page` = 'authentication'), 'Authentication', 'authentication'), (2, (SELECT `id_meta` FROM `PREFIX_meta` WHERE `page` = 'authentication'), 'Authentification', 'authentification'), (3, (SELECT `id_meta` FROM `PREFIX_meta` WHERE `page` = 'authentication'), 'Autenticación', 'autenticacion')
+
+LOCK TABLES `admin_assert` WRITE
+
+UNLOCK TABLES
+
+DROP TABLE IF EXISTS `admin_role`
+
+SELECT * FROM MyTable WHERE 1 = 2;
+
+SELECT
+
+SELECT Test FROM Test WHERE ( MyColumn = 1 )) AND ((( SomeOtherColumn = 2); \ No newline at end of file