コード例 #1
0
ファイル: RawQuerySet.php プロジェクト: buldezir/dja_orm
 /**
  * @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();
 }