Changeset 2807

Show
Ignore:
Timestamp:
11/13/08 19:57:47 (8 weeks ago)
Author:
rickc
Message:

Get RDBMS-specific code out of the file. This functions isn't currently used in Habari. Of the backends we are currently supporting, MySQL supports the function as written, Postgress appears to use EXEC instead of call and so needs a transformation written in it's sql_t() function, and SQLite doesn't support stored procedures at all, though it does support a form of dynamically loaded functions.

Fixes ticket #45.

Location:
trunk/htdocs/system
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/classes/databaseconnection.php

    r2731 r2807  
    293293     * @experimental 
    294294     * @todo  EVERYTHING... :) 
     295     * Implemented in child classes. Most RDBMS use ANSI-92 syntax,  
     296     * ( CALL procname ( param1, param2, ... ),  
     297     * so they return the call to here. Those that don't, handle the call individually 
    295298     */ 
    296299    public function execute_procedure( $procedure, $args = array() ) 
     
    304307        } 
    305308 
    306         /* 
    307          * Since RDBMS handle the calling of procedures 
    308          * differently, we need a simple abstraction 
    309          * mechanism here to build the appropriate SQL 
    310          * commands to call the procedure... 
    311          */ 
    312         $driver = $pdo->getAttribute( PDO::ATTR_DRIVER_NAME ); 
    313         switch ( $driver ) { 
    314             case 'mysql': 
    315             case 'pgsql': 
    316             case 'db2': 
    317                 /* 
    318                  * These databases use ANSI-92 syntax for procedure calling: 
    319                  * CALL procname ( param1, param2, ... ); 
    320                  */ 
    321                 $query = 'CALL ' . $procedure . '( '; 
    322                 if ( count( $args ) > 0 ) { 
    323                     $query.= str_repeat( '?,', count( $args ) ); // Add the placeholders 
    324                     $query = substr( $query, 0, strlen( $query ) - 1 ); // Strip the last comma 
    325                 } 
    326                 $query.= ' )'; 
    327                 break; 
    328             case 'oracle': 
    329                 die( sprinf(_t('not yet supported on %s'), $driver) ); 
    330                 break; 
    331         } 
     309        $query = 'CALL ' . $procedure . '( '; 
     310        if ( count( $args ) > 0 ) { 
     311            $query.= str_repeat( '?,', count( $args ) ); // Add the placeholders 
     312            $query = substr( $query, 0, strlen( $query ) - 1 ); // Strip the last comma 
     313        } 
     314        $query.= ' )'; 
     315        $query = $this->sql_t( $query, $args ); 
    332316 
    333317        if ( $pdo_statement = $pdo->prepare( $query ) ) { 
     
    719703            } 
    720704        } 
    721  
    722705        // Put the upgrade functions into an array using the 0-padded revision + '_1' as the key 
    723706        $upgrade_functions = get_class_methods($this); 
  • trunk/htdocs/system/schema/mysql/connection.php

    r2592 r2807  
    249249 
    250250    /** 
     251     * Execute a stored procedure 
     252     * 
     253     * @param   procedure   name of the stored procedure 
     254     * @param   args        arguments for the procedure 
     255     * @return  mixed       whatever the procedure returns... 
     256     */ 
     257    public function execute_procedure( $procedure, $args = array() ) 
     258    { 
     259        return parent::execute_procedure( $procedure, $args ); 
     260    } 
     261 
     262    /** 
    251263     * Run all of the upgrades since the last database revision. 
    252264     * 
  • trunk/htdocs/system/schema/pgsql/connection.php

    r2592 r2807  
    330330 
    331331    /** 
     332     * Execute a stored procedure 
     333     * 
     334     * @param   procedure   name of the stored procedure 
     335     * @param   args        arguments for the procedure 
     336     * @return  mixed       whatever the procedure returns... 
     337     */ 
     338    public function execute_procedure( $procedure, $args = array() ) 
     339    { 
     340        return parent::execute_procedure( $procedure, $args ); 
     341    } 
     342 
     343    /** 
    332344     * Run all of the upgrades since the last database revision. 
    333345     * 
  • trunk/htdocs/system/schema/sqlite/connection.php

    r2592 r2807  
    144144 
    145145    /** 
     146     * Execute a stored procedure 
     147     * 
     148     * @param   procedure   name of the stored procedure 
     149     * @param   args        arguments for the procedure 
     150     * @return  mixed       whatever the procedure returns... 
     151     * Not supported with SQLite 
     152     */ 
     153    public function execute_procedure( $procedure, $args = array() ) 
     154    { 
     155        die( _t( 'not yet supported on SQLite' ) ); 
     156    } 
     157 
     158    /** 
    146159     * Run all of the upgrades since the last database revision. 
    147160     *