Welcome Guest, Not a member yet? Register   Sign In
set_update_batch how to plus 1
#9

(03-03-2019, 08:36 AM)php_rocs Wrote: @souicp,

Ok, I see what the challenge is.  Normally it would be just view + 1 but because we are doing a batch update and everything is escaped then that is causing the issue. Have you tried ...

'view' => 'view + 1'   (This might be seen as a string)
or
'view' => 'view'+ 1    (This might work)
or
'view' => view + 1     (This might throw an error)

It should be one of the answers above.

it's bug
i fix it 

PHP Code:
    public function update_batch($table$set NULL$index NULL$key NULL$escape NULL$batch_size 100)
    {
        
// Combine any cached components with the current statements
        
$this->_merge_cache();

        if (
$index === NULL)
        {
            return (
$this->db_debug) ? $this->display_error('db_must_use_index') : FALSE;
        }

        if (
$set === NULL)
        {
            if (empty(
$this->qb_set_ub))
            {
                return (
$this->db_debug) ? $this->display_error('db_must_use_set') : FALSE;
            }
        }
        else
        {
            if (empty(
$set))
            {
                return (
$this->db_debug) ? $this->display_error('update_batch() called with no data') : FALSE;
            }

            
$this->set_update_batch($set$index$key$escape);
        }

        if (
strlen($table) === 0)
        {
            if ( ! isset(
$this->qb_from[0]))
            {
                return (
$this->db_debug) ? $this->display_error('db_must_set_table') : FALSE;
            }

            
$table $this->qb_from[0];
        }

        
// Batch this baby
        
$affected_rows 0;
        for (
$i 0$total count($this->qb_set_ub); $i $total$i += $batch_size)
        {
            if (
$this->query($this->_update_batch($this->protect_identifiers($tableTRUENULLFALSE), array_slice($this->qb_set_ub$i$batch_size), $index)))
            {
                
$affected_rows += $this->affected_rows();
            }

            
$this->qb_where = array();
        }

        
$this->_reset_write();
        return 
$affected_rows;
    } 


PHP Code:
    public function set_update_batch($key$index ''$keys null $escape NULL)
    {
        
$key $this->_object_to_array_batch($key);

        if ( ! 
is_array($key))
        {
            
// @todo error
        
}

        
is_bool($escape) OR $escape $this->_protect_identifiers;

        foreach (
$key as $k => $v)
        {
            
$index_set FALSE;
            
$clean = array();
            foreach (
$v as $k2 => $v2)
            {
                if (
$k2 === $index)
                {
                    
$index_set TRUE;
                }

                
$clean[$k2] = array(
                    
'field'  => $this->protect_identifiers($k2FALSE, ($keys == $k2 $escape NULL)),
                    
'value'  => (($escape === FALSE && $keys == $k2) ? $v2 $this->escape($v2))
                );
            }

            if (
$index_set === FALSE)
            {
                return 
$this->display_error('db_batch_missing_index');
            }

            
$this->qb_set_ub[] = $clean;
        }

        return 
$this;
    } 
Reply


Messages In This Thread
set_update_batch how to plus 1 - by souicp - 02-26-2019, 11:56 PM
RE: set_update_batch how to plus 1 - by php_rocs - 02-27-2019, 08:32 AM
RE: set_update_batch how to plus 1 - by souicp - 02-28-2019, 12:35 AM
RE: set_update_batch how to plus 1 - by php_rocs - 02-28-2019, 06:34 AM
RE: set_update_batch how to plus 1 - by souicp - 02-28-2019, 11:07 PM
RE: set_update_batch how to plus 1 - by php_rocs - 03-01-2019, 07:34 AM
RE: set_update_batch how to plus 1 - by souicp - 03-02-2019, 08:12 PM
RE: set_update_batch how to plus 1 - by php_rocs - 03-03-2019, 08:36 AM
RE: set_update_batch how to plus 1 - by souicp - 03-05-2019, 02:32 AM
RE: set_update_batch how to plus 1 - by bistungki - 12-21-2019, 11:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB