atk4/atk4 — Issue #29: calling dsql where() with OR condition fails
Author: twjnorth
Created: 2011-11-03 06:23:21+00:00
State: open

dsql.php lists the following options for where clauses

1. where('id',2); // equals
2. where('id','>',2); // explicit condition
3. where(array('id',2),('id',3)); // or
4. where('id',array(2,3)); // in
5. where($dsql,4); // subquery
6. where('id',$dsql); // in subquery
7. where('id=ord'); // full statement. avoid

But trying to create a SQL with an OR condition (no. 3 above) like this

$st=$this->api->db->dsql()->table('vscrum_wall w')
->field('w.id')
->field('w.points_left')
->where(array('w.involved',$member),('w.member_id',$member))
->where('w.sprint_id',$sprint)
->where('w.team_id',$p->api->auth->get('team_id'))
->order('w.backlog_ref')
->debug()
->do_getAll();

produces the following error

Parse error: syntax error, unexpected ',' in C:\wamp\www\paperless_test1\page\scrumwall.php on line 67

The same error occurs if the array line is specified as

->where(array(('w.id',$member),('w.involved',$member)))

or if the array is defined first

$orcondition[]=array(('w.id',$member),('w.involved',$member));

$st=$this->api->db->dsql()->table('vscrum_wall w')
->field('w.id')
->field('w.points_left')
->where($orcondition)
->where('w.sprint_id',$sprint)
->where('w.team_id',$p->api->auth->get('team_id'))
->order('w.backlog_ref')
->debug()
->do_getAll();

and if changed this way so the query works

$st=$this->api->db->dsql()->table('vscrum_wall w')
->field('w.id')
->field('w.points_left')
->where(array('w.involved',$member),array('w.member_id',$member))
->where('w.sprint_id',$sprint)
->where('w.team_id',$p->api->auth->get('team_id'))
->order('w.backlog_ref')
->debug()
->do_getAll();

it results in the following incorrect SQL

select w.id, w.points_left from vscrum_wall w
where (w.involved) and (1) and (w.sprint_id = '21')
and (w.team_id = '2') order by w.backlog_ref

So unable to get an OR condition working in dsql in v.4.1.1.