예제 #1
0
 /**
  * Build the query based on the private sql and the parameters
  *
  * @since 20100216
  * @since 20100428	(v1.0.1) (greg) use sql() instead of sql
  * @date 20100630 (v1.0.2) (greg) use array_compact to avoid null values
  * @version 1.0.2
  * @author	greg
  * @param $parameters (optional)array, the parameters to inject into the query
  * @return string, the sql query string
  */
 public function build($parameters = null)
 {
     $sql = '';
     try {
         $this->preBuild();
         $sql = $this->sql() . $this->extraBuild($parameters);
         if (!empty($parameters)) {
             if (is_scalar($parameters)) {
                 $parameters = array($parameters);
             }
             if (is_array($parameters)) {
                 if ($this->autoProtect) {
                     $parameters = $this->protectArray($parameters, $this->autoQuote);
                 }
                 $sql = PU_sprintfn($sql, PU_array_compact($parameters));
             }
             //TODO is parameters is neither scalar nor array what should we do?
         }
     } catch (Exception $e) {
         throw new PHPDS_databaseException('Error building sql for <tt>' . get_class() . '</tt>', 0, $e);
     }
     return $sql;
 }
예제 #2
0
 public function testarraycompact()
 {
     //PU_array_compact(array $a)
     $this->assertEquals(array(), PU_array_compact(array()));
     $this->assertEquals(array('a' => 1), PU_array_compact(array('a' => 1)));
     $this->assertEquals(array('a' => 1), PU_array_compact(array('a' => 1, 'b' => null)));
     $this->assertEquals(array('a' => 1, 'c' => 'test'), PU_array_compact(array('a' => 1, 'b' => null, 'c' => 'test')));
 }