0

'as'句を使用してネイティブクエリを使用してクラス属性を設定したい:

public function findIntersects($id,$pontos){

$em = $this->getEntityManager();

 $sql = "SELECT p.imovel,p.id,ST_Area(ST_Intersection(p.location,'POLYGON((".$pontos."))')) as area_int, ST_Area(p.location) as area from propriedades p where ST_Intersects(p.location,'POLYGON((".$pontos."))') and id !=:id";

$rsm = new ResultSetMapping;
$rsm->addEntityResult('Incra\PropriedadesBundle\Entity\Propriedades', 'o');
$rsm->addFieldResult('o', 'id', 'id');
$rsm->addFieldResult('o', 'imovel', 'imovel');
$rsm->addFieldResult('o', 'area_int', 'area_int');
$rsm->addFieldResult('o', 'area', 'area');

 $qns = $this->_em->createNativeQuery($sql, $rsm);
$qns->setParameter("id", $id);
$qns->setParameter("pontos", $pontos);


  return $qns->getResult();


}

私はクラスにこの属性を持っていますが、ormのアノテーションを持っていません

そして私はエラーを受け取ります:

注意:未定義のインデックス:/var/www/incra/vendor/doctrine/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php行205のarea_int

私のクラス: http: //pastebin.com/jd3gcr93

4

2 に答える 2

0

area_intデータ列としてマークを付けていません(クラスの120行目)。area_intフィールドの結果にリストしたので( $rsm->addFieldResult('o', 'area_int', 'area_int');)Doctrineは列をエンティティにマップしようとしますが、見つかりません。クラスを変更してみてください

/**@ORM\Column(name="area_int", type="int")*/
private $area_int;

また、セキュリティ/パフォーマンス/gooコードスタイルなどのためだけに。$pontosクエリ文字列に直接挿入しています。これにより、コードがSQLインジェクションの対象になります。後で、パラメータとして追加$pontosします。この2つのアプローチは冗長であるため、そのうちの1つを削除することをお勧めします。私は間違いなくパラメータアプローチを使用しようとするので、クエリは次のようになります

SELECT p.imovel,p.id,ST_Area(ST_Intersection(p.location,'POLYGON((:pontos))')) as area_int, 
       ST_Area(p.location) as area from propriedades p 
where ST_Intersects(p.location,'POLYGON((:pontos))') and id !=:id

うまくいかない場合は削除$qns->setParameter("pontos", $pontos);してもかまいませんが、SQLインジェクションを防ぐために、可能な限り多くの健全性チェックと検証を実行する必要があります。

于 2012-09-20T19:13:04.227 に答える
0

executeQueryを使用して、dqlなしでネイティブを使用しました

于 2013-03-20T18:38:26.280 に答える