如何在 Kohana ORM 中使用 BETWEEN 子句

发布于 11-27 21:32 字数 949 浏览 2 评论 0原文

我是科哈纳的新手。我正在使用 ORM 来获取数据。

我想构建一个查询,其中存在 BETWEEN 子句。如下所示

SELECT `rooms`.* FROM `rooms` LEFT JOIN `events` ON (`rooms`.`id` = `events`.`room_id`) 
WHERE `events`.`room_id` IS NULL 
OR (`events`.`eventstart` NOT BETWEEN 1312210800  AND 1312218000) 

,我正在执行以下操作

    $rooms = $room->join('events', 'LEFT')
                  ->on('rooms.id', '=', 'events.room_id')
                  ->where('events.room_id', 'IS', NULL)
                  ->and_where_open()
                  ->or_where('events.eventstart' , 'NOT BETWEEN', $from)
                  ->and_where_close()
                  ->find_all();

,但我收到这样的查询

SELECT `rooms`.* FROM `rooms` LEFT JOIN `events` ON (`rooms`.`id` = `events`.`room_id`)
WHERE `events`.`room_id` IS NULL AND (`events`.`eventstart` NOT BETWEEN 1312210800)

有人能指出如何使用 BETWEEN 子句吗

I am new to kohana. I am using ORM for getting data.

I want to build a query in which BETWEEN clause is there. as following

SELECT `rooms`.* FROM `rooms` LEFT JOIN `events` ON (`rooms`.`id` = `events`.`room_id`) 
WHERE `events`.`room_id` IS NULL 
OR (`events`.`eventstart` NOT BETWEEN 1312210800  AND 1312218000) 

for that i am doing the following

    $rooms = $room->join('events', 'LEFT')
                  ->on('rooms.id', '=', 'events.room_id')
                  ->where('events.room_id', 'IS', NULL)
                  ->and_where_open()
                  ->or_where('events.eventstart' , 'NOT BETWEEN', $from)
                  ->and_where_close()
                  ->find_all();

But i am getting the the query like this

SELECT `rooms`.* FROM `rooms` LEFT JOIN `events` ON (`rooms`.`id` = `events`.`room_id`)
WHERE `events`.`room_id` IS NULL AND (`events`.`eventstart` NOT BETWEEN 1312210800)

Can someone point out how to use BETWEEN clause

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

许仙没带伞2024-12-04 21:32:23

我认为你应该使用 or_where('events.eventstart', 'BETWEEN', array($from, $to));
有关 Kohana Query Builder 的文档可以在这里找到 -> http://kohanaframework.org/3.2/guide/database/query/builder
ORM 使用查询生成器。

I think you should use or_where('events.eventstart', 'BETWEEN', array($from, $to));
Documentation on Kohana Query Builder can be found here -> http://kohanaframework.org/3.2/guide/database/query/builder
ORM uses Query Builder.

零度℉2024-12-04 21:32:23

我发现可靠工作的唯一方法是使用DB::expr()

考虑以下事项:

or_where('events.eventstart', 'NOT BETWEEN', DB::expr('1312210800  AND 1312218000'));

或者您可以将其全部放入变量中:

$range = "{$from} AND {$to}";
or_where('events.eventstart', 'NOT BETWEEN', DB::expr($range));

The only way I've found that works reliably is to use DB::expr().

Consider the following:

or_where('events.eventstart', 'NOT BETWEEN', DB::expr('1312210800  AND 1312218000'));

Or you can stick it all in variables:

$range = "{$from} AND {$to}";
or_where('events.eventstart', 'NOT BETWEEN', DB::expr($range));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文