• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
No recognize null values with db->limit() VS db->get that

#1
[eluser]Unknown[/eluser]
Hi people! I found a question that I think that's a bug Wink

1r= $qry = $this->db->get($this->n_table, $num, $offset);
if I set $num and $offset whit value null, the function hive me a correct response
2n= $this->db->limit($num, $offset);
but I if use this function, the function doesn't recognize the values as null and think that the values is 0.

So, the 1r recognize the null values and return me the correct result of the query and 2n no recognize the null values and return me a empty Array.


Anybody can tell me why?


Tnx x all! Tongue

#2
[eluser]aquary[/eluser]
Check what was the query you got from both of them ($this->db->last_query()). Since NULL is a kind of...0, maybe CI's limit() undestand it that way and use 0, 0.

#3
[eluser]web-johnny[/eluser]
OK the first thing that it comes to my mind is why to have a $this->db->limit(null) ?
You can avoid this problem easily . So it make sense to me that when you add a parameter to limit just transform it to integer. The only right thing about this is the second parameter because there are some cases that perhaps we need to have a parameter for the second segment of the function. But then again there is not any problem with this as you will have the following results:

Code:
//This means I don't need any data
$this->db->limit(null);
//It will be LIMIT 0 , so no data will be returned as expected

Code:
//This means I don't need the second parameter
$this->db->limit(20,null);
//It will be LIMIT 20,0 so the data will begin for the row 0 that this is correct too

So in my opinion is not a bug as the function limit comments has a very specific structure:

Code:
/**
  * Sets the LIMIT value
  *
  * @param integer the limit value
  * @param integer the offset value
  * @return object
  */
public function limit($value, $offset = '')
{
  $this->ar_limit = (int) $value;

  if ($offset != '')
  {
   $this->ar_offset = (int) $offset;
  }

  return $this;
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.