Changeset 1959


Ignore:
Timestamp:
06/14/10 14:56:46 (3 years ago)
Author:
shibuya246
Message:

[Branch 1.4] sql for multiste

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.4/libs/extensions/ezSQL/mysql/ez_sql_mysql.php

    r1955 r1959  
    169169        */ 
    170170 
    171         function query($query = '') 
     171        function query($query = '', $add_siteid_to_query = TRUE) 
    172172        { 
    173173 
     
    216216            } 
    217217 
    218             if (MULTI_SITE == 'true') { $query = $this->whereMultiSite($query); } 
     218            if (MULTI_SITE == 'true' && $add_siteid_to_query) { $query = $this->whereMultiSite($query); } 
    219219 
    220220            // Perform the query via std mysql_query function.. 
     
    391391            if (stripos($query, ' FROM ')  !== false) { 
    392392                $array = explode('FROM ',$query); 
    393                  
    394                 if (!isset($array[1])) { var_dump($array);  } 
    395                 $array2 = explode(' ', $array[1]); 
    396                 $table = $array2[0]; 
    397  
    398                 $array3 = explode('_', $table); 
    399                 $tablename = $array3[1]; 
    400  
    401                 $tablename = str_replace(',', '', $tablename); 
    402  
    403                 if (array_key_exists($tablename, $siteidtables)) { 
    404                     if (stripos($query, $table)) {  
    405                         if (stripos($query, 'WHERE') !== false) { 
    406                             $array = explode('WHERE ', $query); 
    407                             $query = $array[0] . ' WHERE ' . $siteidtables[$tablename] . '_siteid = ' . SITEID . " AND " . $array[1]; 
    408                         } else {         
    409                             $array = $array = explode('FROM ' . $table ,$query); 
    410                             $query = $array[0] . ' FROM ' . $table . ' WHERE ' . $siteidtables[$tablename] . '_siteid = ' . SITEID . $array[1]; 
     393 
     394                if ($array[0] != 'SHOW COLUMNS') { 
     395 
     396                    if (!isset($array[1])) { var_dump($array);  } 
     397                    $array2 = explode(' ', $array[1]); 
     398                    $table = $array2[0]; 
     399 
     400                    $array3 = explode('_', $table); 
     401                    $tablename = $array3[1]; 
     402 
     403                    $tablename = str_replace(',', '', $tablename); 
     404 
     405                    if (array_key_exists($tablename, $siteidtables)) { 
     406                        if (stripos($query, $table)) { 
     407                            if (stripos($query, 'WHERE') !== false) { 
     408                                $array = explode('WHERE ', $query); 
     409                                $query = $array[0] . ' WHERE ' . $siteidtables[$tablename] . '_siteid = ' . SITEID . " AND " . $array[1]; 
     410                            } else { 
     411                                $array = $array = explode('FROM ' . $table ,$query); 
     412                                $query = $array[0] . ' FROM ' . $table . ' WHERE ' . $siteidtables[$tablename] . '_siteid = ' . SITEID . $array[1]; 
     413                            } 
     414 
     415                            $after =  "<span style='color:red; font-weight:bold;'>AFTER</span>: " . $query . "<br/><br/>"; 
     416    //print $after; 
    411417                        } 
    412  
    413                         $after =  "<span style='color:red; font-weight:bold;'>AFTER</span>: " . $query . "<br/><br/>"; 
    414 //print $after; 
    415418                    } 
    416                 }                
     419                } 
    417420            }  
    418421 
     
    439442             
    440443            if (stripos($query, 'INSERT INTO ')  !== false) { 
    441   // print "<br/>this is INSERT " . $before; 
    442                 $pattern = '/^INSERT INTO(.*?)\(/'; 
     444   // print "<br/>this is INSERT " . $before; 
     445                $pattern = '/^INSERT INTO(.*?)\SET/'; 
    443446                preg_match($pattern, $query, $matches); 
    444                  
    445                 if ($matches) { $tablename = trim($matches[1]); } 
    446                 //print $tablename; 
     447                if ($matches) { $tablename = trim($matches[1]); } else { 
     448                    $pattern = '/^INSERT INTO(.*?)\(/'; 
     449                    preg_match($pattern, $query, $matches); 
     450                    if ($matches) { $tablename = trim($matches[1]);     } 
     451                } 
     452 
     453//              print $tablename; 
    447454                $tablename = str_ireplace(DB_PREFIX, '', $tablename); 
    448455 
     
    522529 
    523530            //if ($after == 'no') { print $before; } 
    524 //          print $after; 
     531            //print $after; 
    525532            return $query; 
    526533        } 
Note: See TracChangeset for help on using the changeset viewer.