setSQLFilters() public static method

This is a lowlevel method to set the SQL filter array. The format of this array is: array( '' => array( '' => array( '' => '' ) ) ) Example: array( QueryWriter::C_SQLFILTER_READ => array( 'book' => array( 'title' => ' LOWER(book.title) ' ) ) Note that you can use constants instead of magical chars as keys for the uppermost array. This is a lowlevel method. For a more friendly method please take a look at the facade: R::bindFunc().
public static setSQLFilters ( $sqlFilters, $safeMode = false ) : void
return void
示例#1
0
 /**
  * Test whether we can use SQL filters and
  * whether they are being applied properly for
  * different types of SELECT queries in the QueryWriter.
  */
 public function testSQLFilters()
 {
     R::nuke();
     AQueryWriter::setSQLFilters(array(QueryWriter::C_SQLFILTER_READ => array('book' => array('title' => ' LOWER(book.title) ')), QueryWriter::C_SQLFILTER_WRITE => array('book' => array('title' => ' UPPER(?) '))));
     $book = R::dispense('book');
     $book->title = 'story';
     R::store($book);
     asrt(R::getCell('SELECT title FROM book WHERE id = ?', array($book->id)), 'STORY');
     $book = $book->fresh();
     asrt($book->title, 'story');
     $library = R::dispense('library');
     $library->sharedBookList[] = $book;
     R::store($library);
     $library = $library->fresh();
     $books = $library->sharedBookList;
     $book = reset($books);
     asrt($book->title, 'story');
     $otherBook = R::dispense('book');
     $otherBook->sharedBook[] = $book;
     R::store($otherBook);
     $otherBook = $otherBook->fresh();
     $books = $otherBook->sharedBookList;
     $book = reset($books);
     asrt($book->title, 'story');
     $links = $book->ownBookBookList;
     $link = reset($links);
     $link->shelf = 'x13';
     AQueryWriter::setSQLFilters(array(QueryWriter::C_SQLFILTER_READ => array('book' => array('title' => ' LOWER(book.title) '), 'book_book' => array('shelf' => ' LOWER(book_book.shelf) ')), QueryWriter::C_SQLFILTER_WRITE => array('book' => array('title' => ' UPPER(?) '), 'book_book' => array('shelf' => ' UPPER(?) '))));
     R::store($link);
     asrt(R::getCell('SELECT shelf FROM book_book WHERE id = ?', array($link->id)), 'X13');
     $otherBook = $otherBook->fresh();
     unset($book->sharedBookList[$otherBook->id]);
     R::store($book);
     AQueryWriter::setSQLFilters(array());
 }
示例#2
0
 /**
  * Binds an SQL function to a column.
  * This method can be used to setup a decode/encode scheme or
  * perform UUID insertion. This method is especially useful for handling
  * MySQL spatial columns, because they need to be processed first using
  * the asText/GeomFromText functions.
  *
  * @param string $mode     mode to set function for, i.e. read or write
  * @param string $field    field (table.column) to bind SQL function to
  * @param string $function SQL function to bind to field
  *
  * @return void
  */
 public function bindFunc($mode, $field, $function)
 {
     list($type, $property) = explode('.', $field);
     $mode = $mode === 'write' ? QueryWriter::C_SQLFILTER_WRITE : QueryWriter::C_SQLFILTER_READ;
     if (!isset(self::$sqlFilters[$mode])) {
         self::$sqlFilters[$mode] = array();
     }
     if (!isset(self::$sqlFilters[$mode][$type])) {
         self::$sqlFilters[$mode][$type] = array();
     }
     if (is_null($function)) {
         unset(self::$sqlFilters[$mode][$type][$property]);
     } else {
         if ($mode === QueryWriter::C_SQLFILTER_WRITE) {
             self::$sqlFilters[$mode][$type][$property] = $function . '(?)';
         } else {
             self::$sqlFilters[$mode][$type][$property] = $function . "({$field})";
         }
     }
     AQueryWriter::setSQLFilters(self::$sqlFilters, !$this->isFrozen);
 }