Beispiel #1
0
 /**
  * @param Metadata $metadata
  * @param $query
  * @param array $bind
  * @param Connection $db
  */
 public function __construct(Metadata $metadata, $query, array $bind = null, Connection $db = null)
 {
     $this->metadata = $metadata;
     if (null !== $db) {
         $this->db = $db;
     } else {
         $this->db = $metadata->getDbConnection();
     }
     $selectAllFields = [];
     $dbCols = $this->metadata->getDbColNames();
     foreach ($dbCols as $colName) {
         $selectAllFields[] = 't.' . $this->qi($colName);
     }
     $query = str_ireplace(['select *', ':t'], ['SELECT ' . implode(', ', $selectAllFields), $this->qi($this->metadata->getDbTableName()) . ' t'], $query);
     // auto replace :field_name placeholders by their quoted db column names
     $query = preg_replace_callback('/:(\\w+)/', function ($matches) use($metadata) {
         if ($metadata->__isset($matches[1])) {
             return $this->qi($metadata->getField($matches[1])->db_column);
         } else {
             return $matches[0];
         }
     }, $query);
     $this->queryStringCache = $query;
     // other :somename placeholders treated as prepared statement bindings
     if (null !== $bind) {
         $this->bind($bind);
     }
     $this->returnObjects();
 }
Beispiel #2
0
 /**
  * @param Metadata $metadata
  * @param QueryBuilder $qb
  * @param Connection $db
  */
 public function __construct(Metadata $metadata, QueryBuilder $qb = null, Connection $db = null)
 {
     $this->metadata = $metadata;
     if (null !== $db) {
         $this->db = $db;
     } else {
         $this->db = $metadata->getDbConnection();
     }
     if (null !== $qb) {
         $this->qb = $qb;
     } else {
         $this->qb = new QueryBuilder($this->db);
         $this->qb->from($this->qi($metadata->getDbTableName()), $this->qi('t'));
     }
     $this->lookuper = \Dja\Db\Model\Lookup\LookupAbstract::getInstance($this->db);
 }