/** * Test the __toString method of the SQLHelper. */ public function testToString() { $toolbox = R::$toolbox; $adapter = $toolbox->getDatabaseAdapter(); $sqlHelper = new RedBean_SQLHelper($adapter); $sqlHelper->begin()->select('*')->from('table')->where('name = ?')->put('name'); $str = (string) $sqlHelper; asrt(strpos($str, 'query') !== false, true); asrt(strpos($str, 'select * from table where name = ?') !== false, true); asrt(strpos($str, '=> Array') !== false, true); asrt(strpos($str, 'params') !== false, true); }
/** * Test debugging with custom logger. * * @return void */ public function testDebugCustomLogger() { testpack('Test debug mode with custom logger'); $pdoDriver = new RedBean_Driver_PDO(R::getDatabaseAdapter()->getDatabase()->getPDO()); $customLogger = new CustomLogger(); $pdoDriver->setDebugMode(TRUE, $customLogger); $pdoDriver->Execute('SELECT 123'); asrt(count($customLogger->getLogMessage()), 1); $pdoDriver->setDebugMode(TRUE, NULL); asrt($pdoDriver->getLogger() instanceof RedBean_Logger_Default, TRUE); testpack('Test bean->getProperties method'); $bean = R::dispense('bean'); $bean->property = 'hello'; $props = $bean->getProperties(); asrt(isset($props['property']), TRUE); asrt($props['property'], 'hello'); testpack('Test snake_case vs CamelCase with Query Builder'); list($sql, $params) = R::$f->begin()->camelCase()->getQuery(); asrt(trim($sql), 'camel case'); list($sql, $params) = R::$f->begin()->personASTeacher()->getQuery(); asrt(trim($sql), 'person as teacher'); list($sql, $params) = R::$f->begin()->JOIN()->getQuery(); asrt(trim($sql), 'join'); RedBean_SQLHelper::useCamelCase(FALSE); list($sql, $params) = R::$f->begin()->camelCase()->getQuery(); asrt(trim($sql), 'camelCase'); }
/** * Generates question mark slots for an array of values. * * @param array $array * * @return string */ public static function genSlots($array) { return self::$f->genSlots($array); }
/** * Nests another query builder query in the current query. * * @param RedBean_SQLHelper * * @return RedBean_SQLHelper */ public function nest(RedBean_SQLHelper $sqlHelper) { list($sql, $params) = $sqlHelper->getQuery(); $this->sql .= $sql; $this->params += $params; return $this; }
/** * Adds WHERE clause conditions to ownList retrieval. * For instance to get the pages that belong to a book you would * issue the following command: $book->ownPage * However, to order these pages by number use: * * $book->with(' ORDER BY `number` ASC ')->ownPage * * the additional SQL snippet will be merged into the final * query. * * @param string|RedBean_SQLHelper $sql SQL to be added to retrieval query. * @param array $bindings array with parameters to bind to SQL snippet * * @return RedBean_OODBBean */ public function with($sql, $bindings = array()) { if ($sql instanceof RedBean_SQLHelper) { list($this->withSql, $this->withParams) = $sql->getQuery(); } else { $this->withSql = $sql; $this->withParams = $bindings; } return $this; }
/** * Generates question mark slots for an array of values. * * @param array $array * * @return string */ public function genSlots($array) { return $this->f->genSlots($array); }