0

它看起来很乱,它是如何作为参考的?

http://www.doctrine-project.org/documentation/manual/1_1/en/dql-doctrine-query-language%3Abnf

4

2 回答 2

3

实际上,我认为它没有被任何人用作参考;但如果有人想使用一些理解 BNF 的自动工具,它可能会很有用;例如,某种代码生成器。

BNF 的优势在于它是一种描述语言的正式方式——当你是一个程序时,它比英语更容易理解。


以供参考 :



在评论后编辑:这是一个关于 DQL / Object 东西的快速示例:

让我们考虑这部分代码,它使用面向对象的 API 编写查询、执行它并获取结果(水合为数组——调试时仅打印出数据)

$result = Doctrine_Query::create()
    ->select('p.id, p.title, u.login')
            ->from('Ab_Model_Post p')
            ->innerJoin('p.User u')
            ->where('p.codeStatus = ?')
            ->orderBy('p.date desc')
            ->limit(2)
            ->execute(array('OK'), Doctrine::HYDRATE_ARRAY);
var_dump($result);

这是您将获得的输出类型:

array
  0 => 
    array
      'id' => string '7' (length=1)
      'title' => string 'Septième post' (length=14)
      'User' => 
        array
          'id' => string '1' (length=1)
          'login' => string 'user1' (length=5)
  1 => 
    array
      'id' => string '6' (length=1)
      'title' => string 'Sixième post (draft=7)' (length=23)
      'User' => 
        array
          'id' => string '1' (length=1)
          'login' => string 'user1' (length=5)

当然,这是考虑到模式和模型类都可以——对于法语的示例,我很抱歉,我使用了一段时间前设置的模式/模型/数据库来演示法语的 Doctrine。

基本上,数据库用于博客应用程序,在这里,我们:

  • 从帖子和发布它们的用户中获取一些数据
  • 对于有效的帖子
  • 最近的帖子
  • 只有两个帖子


现在,这是一个等价物,使用我所说的“DQL”作为“伪SQL语言”:

$result = Doctrine_Query::create()
    ->query(<<<DQL
select p.id, p.title, u.login
from Ab_Model_Post as p, 
    p.User u
where p.codeStatus = ?
order by p.date desc
limit 2
DQL
    , array('OK'), Doctrine::HYDRATE_ARRAY);
var_dump($result);

这里没有面向对象的 API (好吧,我的意思是写查询):我只写了我正在考虑的伪 SQL——据我所知,这就是 BNF 所描述的。

而且,当然, 的输出与var_dump我之前得到的完全一样。


我希望这能让事情更清楚:-)

于 2010-02-25T17:06:41.860 回答
0

它是 Backus-Naur 形式,一种描述上下文无关语法的方法。请参阅此维基百科文章

于 2010-02-25T17:05:48.527 回答