Skip to content

Commit

Permalink
Fix joins
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldpdl committed Oct 14, 2011
1 parent dc9dee0 commit fd66610
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Expand Up @@ -20,7 +20,7 @@ public static function execute($data) {

$result = array();

$sql_query = 'select distinct c.*, (select count(*) from :table_zones z where z.zone_country_id = c.countries_id) as total_zones from :table_countries c join :table_zones z on (c.countries_id = z.zone_country_id) where (c.countries_name ilike :countries_name or c.countries_iso_code_2 ilike :countries_iso_code_2 or c.countries_iso_code_3 ilike :countries_iso_code_3 or z.zone_name ilike :zone_name or z.zone_code ilike :zone_code) order by c.countries_name';
$sql_query = 'select distinct c.*, (select count(*) from :table_zones z where z.zone_country_id = c.countries_id) as total_zones from :table_countries c left join :table_zones z on (c.countries_id = z.zone_country_id) where (c.countries_name ilike :countries_name or c.countries_iso_code_2 ilike :countries_iso_code_2 or c.countries_iso_code_3 ilike :countries_iso_code_3 or z.zone_name ilike :zone_name or z.zone_code ilike :zone_code) order by c.countries_name';

if ( $data['batch_pageset'] !== -1 ) {
$sql_query .= ' limit :batch_max_results offset :batch_pageset';
Expand All @@ -42,7 +42,7 @@ public static function execute($data) {

$result['entries'] = $Qcountries->fetchAll();

$Qtotal = $OSCOM_PDO->prepare('select count(distinct c.countries_id) from :table_countries c join :table_zones z on (c.countries_id = z.zone_country_id) where (c.countries_name ilike :countries_name or c.countries_iso_code_2 ilike :countries_iso_code_2 or c.countries_iso_code_3 ilike :countries_iso_code_3 or z.zone_name ilike :zone_name or z.zone_code ilike :zone_code)');
$Qtotal = $OSCOM_PDO->prepare('select count(distinct c.countries_id) from :table_countries c left join :table_zones z on (c.countries_id = z.zone_country_id) where (c.countries_name ilike :countries_name or c.countries_iso_code_2 ilike :countries_iso_code_2 or c.countries_iso_code_3 ilike :countries_iso_code_3 or z.zone_name ilike :zone_name or z.zone_code ilike :zone_code)');
$Qtotal->bindValue(':countries_name', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':countries_iso_code_2', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':countries_iso_code_3', '%' . $data['keywords'] . '%');
Expand Down
Expand Up @@ -20,7 +20,7 @@ public static function execute($data) {

$result = array();

$sql_query = 'select distinct l.*, (select count(*) from :table_languages_definitions ld where ld.languages_id = l.languages_id) as total_definitions from :table_languages l join :table_languages_definitions ld on (ld.languages_id = l.languages_id) where (l.name ilike :name or l.code ilike :code or ld.definition_key ilike :definition_key or ld.definition_value ilike :definition_value) order by l.name';
$sql_query = 'select distinct l.*, (select count(*) from :table_languages_definitions ld where ld.languages_id = l.languages_id) as total_definitions from :table_languages l left join :table_languages_definitions ld on (ld.languages_id = l.languages_id) where (l.name ilike :name or l.code ilike :code or ld.definition_key ilike :definition_key or ld.definition_value ilike :definition_value) order by l.name';

if ( $data['batch_pageset'] !== -1 ) {
$sql_query .= ' limit :batch_max_results offset :batch_pageset';
Expand All @@ -41,7 +41,7 @@ public static function execute($data) {

$result['entries'] = $Qlanguages->fetchAll();

$Qtotal = $OSCOM_PDO->prepare('select count(distinct l.languages_id) from :table_languages l join :table_languages_definitions ld on (ld.languages_id = l.languages_id) where (l.name ilike :name or l.code ilike :code or ld.definition_key ilike :definition_key or ld.definition_value ilike :definition_value)');
$Qtotal = $OSCOM_PDO->prepare('select count(distinct l.languages_id) from :table_languages l left join :table_languages_definitions ld on (ld.languages_id = l.languages_id) where (l.name ilike :name or l.code ilike :code or ld.definition_key ilike :definition_key or ld.definition_value ilike :definition_value)');
$Qtotal->bindValue(':name', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':code', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':definition_key', '%' . $data['keywords'] . '%');
Expand Down
Expand Up @@ -20,7 +20,7 @@ public static function execute($data) {

$result = array();

$sql_query = 'select distinct tc.*, (select count(*) from :table_tax_rates tr where tr.tax_class_id = tc.tax_class_id) as total_tax_rates from :table_tax_class tc join :table_tax_rates tr on (tc.tax_class_id = tr.tax_class_id) where (tc.tax_class_title ilike :tax_class_title or tr.tax_description ilike :tax_description) order by tc.tax_class_title';
$sql_query = 'select distinct tc.*, (select count(*) from :table_tax_rates tr where tr.tax_class_id = tc.tax_class_id) as total_tax_rates from :table_tax_class tc left join :table_tax_rates tr on (tc.tax_class_id = tr.tax_class_id) where (tc.tax_class_title ilike :tax_class_title or tr.tax_description ilike :tax_description) order by tc.tax_class_title';

if ( $data['batch_pageset'] !== -1 ) {
$sql_query .= ' limit :batch_max_results offset :batch_pageset';
Expand All @@ -39,7 +39,7 @@ public static function execute($data) {

$result['entries'] = $Qclasses->fetchAll();

$Qtotal = $OSCOM_PDO->prepare('select count(distinct tc.tax_class_id) from :table_tax_class tc join :table_tax_rates tr on (tc.tax_class_id = tr.tax_class_id) where (tc.tax_class_title ilike :tax_class_title or tr.tax_description ilike :tax_description)');
$Qtotal = $OSCOM_PDO->prepare('select count(distinct tc.tax_class_id) from :table_tax_class tc left join :table_tax_rates tr on (tc.tax_class_id = tr.tax_class_id) where (tc.tax_class_title ilike :tax_class_title or tr.tax_description ilike :tax_description)');
$Qtotal->bindValue(':tax_class_title', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':tax_description', '%' . $data['keywords'] . '%');
$Qtotal->execute();
Expand Down
Expand Up @@ -20,7 +20,7 @@ public static function execute($data) {

$result = array();

$sql_query = 'select distinct gz.*, (select count(*) from :table_zones_to_geo_zones z2gz where z2gz.geo_zone_id = gz.geo_zone_id) as total_entries from :table_geo_zones gz join :table_zones_to_geo_zones z2gz on (gz.geo_zone_id = z2gz.geo_zone_id), :table_countries c, :table_zones z where z2gz.zone_country_id = c.countries_id and z2gz.zone_id = z.zone_id and (gz.geo_zone_name ilike :geo_zone_name or gz.geo_zone_description ilike :geo_zone_description or c.countries_name ilike :countries_name or z.zone_name ilike :zone_name) order by gz.geo_zone_name';
$sql_query = 'select distinct gz.*, (select count(*) from :table_zones_to_geo_zones z2gz where z2gz.geo_zone_id = gz.geo_zone_id) as total_entries from :table_geo_zones gz left join :table_zones_to_geo_zones z2gz on (gz.geo_zone_id = z2gz.geo_zone_id), :table_countries c, :table_zones z where z2gz.zone_country_id = c.countries_id and z2gz.zone_id = z.zone_id and (gz.geo_zone_name ilike :geo_zone_name or gz.geo_zone_description ilike :geo_zone_description or c.countries_name ilike :countries_name or z.zone_name ilike :zone_name) order by gz.geo_zone_name';

if ( $data['batch_pageset'] !== -1 ) {
$sql_query .= ' limit :batch_max_results offset :batch_pageset';
Expand All @@ -41,7 +41,7 @@ public static function execute($data) {

$result['entries'] = $Qgroups->fetchAll();

$Qtotal = $OSCOM_PDO->prepare('select count(distinct gz.geo_zone_id) from :table_geo_zones gz join :table_zones_to_geo_zones z2gz on (gz.geo_zone_id = z2gz.geo_zone_id), :table_countries c, :table_zones z where z2gz.zone_country_id = c.countries_id and z2gz.zone_id = z.zone_id and (gz.geo_zone_name ilike :geo_zone_name or gz.geo_zone_description ilike :geo_zone_description or c.countries_name ilike :countries_name or z.zone_name ilike :zone_name)');
$Qtotal = $OSCOM_PDO->prepare('select count(distinct gz.geo_zone_id) from :table_geo_zones gz left join :table_zones_to_geo_zones z2gz on (gz.geo_zone_id = z2gz.geo_zone_id), :table_countries c, :table_zones z where z2gz.zone_country_id = c.countries_id and z2gz.zone_id = z.zone_id and (gz.geo_zone_name ilike :geo_zone_name or gz.geo_zone_description ilike :geo_zone_description or c.countries_name ilike :countries_name or z.zone_name ilike :zone_name)');
$Qtotal->bindValue(':geo_zone_name', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':geo_zone_description', '%' . $data['keywords'] . '%');
$Qtotal->bindValue(':countries_name', '%' . $data['keywords'] . '%');
Expand Down

0 comments on commit fd66610

Please sign in to comment.