Update an object in the database
@param array $exclude Attributes not to update
@param \PDO $db Database connection to use, default to master resource
@return boolean
160034
public function update ($exclude = array (), &$db = FALSE)
	{
		
		// Get database master for write

		if ($db === FALSE)
		{
			$db	=& $this->getDbMaster ();
		}
		
		// Changelog
		
		$old = FALSE;
		
		if ($this->changelog ('update'))
		{
			$old = static::_Read ($this->get (static::$pk), $db);
		}
		
		// Exclude the primary key
		
		$exclude[]	= static::$pk;
		
		// Set value variable

		$values		= NULL;
		
		// Loop through attributes
		
		foreach (static::$attributes as $name => $attribute)
		{
			
			// If we're excluding the attribute then move on

			if (in_array ($name, $exclude))
			{
				continue;
			}
			
			// If the attribute has derefresh enabled the refresh value to default for the update
			
			if (isset ($attribute['deupdate']) && $attribute['deupdate'])
			{
				$this->reset ($name);
			}
			
			// Else if the attribute is not set or is creation only
			
			else if (!$this->attributeIsset ($name) || 
				(isset ($attribute['creation']) && $attribute['creation']))
			{
				
				// Exclude it and move on
				
				$exclude[]	= $name;
				continue;
				
			}
			
			// Add the value
			
			$values	.= ',`' . $name . '` = ' . $this->transformValue ($name, $attribute, $exclude);
			
		}
		
		// Trim the first character (,) from the values
		
		$values		= substr ($values, 1);
		
		// Prepare query
		
		$query = $db->prepare ('
		UPDATE `' . static::$dbTable . '`
		SET ' . $values . '
		WHERE ' . static::$pk . ' = :pk
		');
		
		// Bind attributes
		
		$this->bindAttributes ($query, $exclude);
		
		// Bind pk
		
		$query->bindValue (':pk', $this->iget (static::$pk));
		
		// Execute
		
		if (!$this->executeCreateUpdateQuery ($query))
		{
			return FALSE;
		}
		
		// Changelog
		
		if ($old)
		{
			$log	=& $this->getResource ('changelog');
			$log->hookTransactions ($db);
			$log::_Log ('update', $old, $this);
		}

		// return TRUE

		return TRUE;
		
	}
461634
private function databaseCanBeOverwritten($database)
    {
        $canBeOverwritten = true;

        if (!$this->userDecidedOverwriteDB()) {
            $canBeOverwritten = !$this->getUtilitiesInstance()->checkDbExists($database);
        }

        return $canBeOverwritten;
    }
1315916
protected function setDB (\Native5\Core\Database\DB $db) {
        if (empty($db))
            throw new \InvalidArgumentException("Emoty DB object received");

        $this->db = $db;
    }
916262
protected function updateTinyMCEInContent(Database $db)
    {
        $this->write('  + Updating medias in tinyMce attributes');

        $this->checkExecute($db->execute(
            $this->getJSFunctions() . '

            db.content.find({}).snapshot().forEach(function(content) {
                var updated = false;

                for (var attributeName in content.attributes) {
                    if (content.attributes.hasOwnProperty(attributeName) && "wysiwyg" == content.attributes[attributeName].type) {
                        var pattern = /\[media=([^\]\{]+)\]([^\]]+)\[\/media\]|\[media=\{"format":"([^"]+)"\}\]([^\]]+)\[\/media\]/g;
                        var matches = pattern.execAll(content.attributes[attributeName].value);

                        for (var i = 0; i < matches.length; i++) {
                            var mediaId = getMediaIdFromMatch(matches[i]);
                            var format = getMediaFormatFromMatch(matches[i]);
                            content.attributes[attributeName].value = updateAttribute(content.attributes[attributeName].value, mediaId, format, getMediaAlt(mediaId, content.language));
                            updated = true;
                        }
                    }
                }

                if (updated) {
                    db.content.update({_id: content._id}, content);
                }
            });
        '));
    }
658769
private function reserveNext(array $next, Connection $db)
    {
        $lockID = $this->getLockID();

        // First update the table
        try {
            $date = new \DateTime('now');
            $date->setTimestamp($date->getTimestamp() + $this->timeout);

            if (!$db->update($this->table, [
                $this->lockColumn => $lockID,
                $this->lockTimeoutColumn => $date->format('Y-m-d H:i:s')
            ], $next)
            ) {
                return false;
            }
        } catch (\Exception $e) {
            return false;
        }

        return $this->matchingLock($lockID, $next, $db);
    }
733536
public static function getDbFieldNames(array $exclude = [])
    {
        $fieldNames = [];
        foreach (array_keys(static::$dbProperties) as $propertyName) {
            $fieldNames[] = static::getDbFieldName($propertyName);
        }

        return $exclude ? array_diff($fieldNames, $exclude) : $fieldNames;
    }
22963
public function move($key, $db) {
        return $this->send(['move', $key, $db], function ($response) {
            return (bool) $response;
        });
    }
501740
public static function updateBySql($sql)
    {
        if (is_array($sql)) {
            $bind = $sql;
            unset($bind[0]);
            $sql = $sql[0];
        } else {
            $bind = [];
        }

        $model = new static;

        $table = $model->getSource($bind);
        return $model->getConnection($bind)->updateBySql('UPDATE' . " [$table] SET " . $sql, $bind);
    }
935994
public function update(array $attributes)
    {
        $this->query->type = QueryType::$UPDATE;
        $this->query->updateAttributes = $attributes;
        return QueryExecutor::prepare($this->db, $this->query)->execute();
    }
870193
public static function _setValue ($pk, $name, $value, &$db = FALSE)
	{
		
		// Get database master for write

		if ($db === FALSE)
		{
			$db	=& self::_getDbMaster ();
		}
		
		if (!($db instanceof \PDO))
		{
			throw new Exception ('Invalid or no database resource set');
		}
		
		// Prepare query
		
		$query = $db->prepare ('
		UPDATE `' . static::$dbTable . '`
		SET ' . $name . ' = :val 
		WHERE ' . static::$pk . ' = :pk
		');
		
		// Bind values
		
		$query->bindValue (':val',	$value);
		$query->bindValue (':pk',	$pk);
		
		// Execute

		return $query->execute ();
		
	}
1373627
public function backupData(array $excluded=[]): string
	{
		// Get a list of all the objects
		$sql = 'SELECT DISTINCT "name"
				FROM "sqlite_master"
				WHERE "type"=\'table\'';

		if( ! empty($excluded))
		{
			$sql .= " AND \"name\" NOT IN('".implode("','", $excluded)."')";
		}

		$res = $this->getDriver()->query($sql);
		$result = $res->fetchAll(PDO::FETCH_ASSOC);

		unset($res);

		$outputSql = '';

		// Get the data for each object
		foreach($result as $r)
		{
			$sql = 'SELECT * FROM "'.$r['name'].'"';
			$res = $this->getDriver()->query($sql);
			$objRes = $res->fetchAll(PDO::FETCH_ASSOC);

			unset($res);

			// If the row is empty, continue;
			if (empty($objRes))
			{
				continue;
			}

			// Nab the column names by getting the keys of the first row
			$columns = array_keys(current($objRes));

			$insertRows = [];

			// Create the insert statements
			foreach($objRes as $row)
			{
				$row = array_values($row);

				// Quote values as needed by type
				for($i=0, $icount=count($row); $i<$icount; $i++)
				{
					$row[$i] = (is_numeric($row[$i])) ? $row[$i] : $this->getDriver()->quote($row[$i]);
				}

				$rowString = 'INSERT INTO "'.$r['name'].'" ("'.implode('","', $columns).'") VALUES ('.implode(',', $row).');';

				unset($row);

				$insertRows[] = $rowString;
			}

			unset($objRes);

			$outputSql .= "\n\n".implode("\n", $insertRows);
		}

		return $outputSql;
	}
1364536
public function Create ($exclude = array ())
	{
		
		// Get the next value if there is none
		
		if (!$this->iget ('value'))
		{
			
			$this->iset ('value', 1 + (int)$this->getValue (array (
				'select'	=> 'MAX(value)',
				'where'		=> array (
					array ('module_id', $this->iget ('module_id'))
				)
			)));
			
		}
		
		// Call parent
		
		return parent::Create ($exclude);
		
	}
1370537
protected function update( $sql, $params = null ) {
		$stmt = $this->dbh->prepare( $sql );
		try {
			$this->transactionStart();
			$stmt->execute( $params );
			$this->transactionCommit();
			return true;

		} catch ( PDOException $e ) {
			$this->transactionRollback();
			$this->logger->error( 'Update failed.', [
				'method' => __METHOD__,
				'exception' => $e,
				'sql' => $sql,
				'params' => $params,
			] );
			return false;
		}
	}
204291
protected function _select_db($database)
	{
		if ($this->_config['connection']['database'] !== static::$_current_databases[$this->_connection_id])
		{
			if ($this->_connection->select_db($database) !== true)
			{
				// Unable to select database
				throw new \Database_Exception($this->_connection->error, $this->_connection->errno);
			}
		}

		static::$_current_databases[$this->_connection_id] = $database;
	}
286933
public function updates($data)
    {
        $data = &$this->loadFilterData($data);
        if ( $data == false ) {
            return false;
        }
        $conditions = $this->sqlBuilder->buildCondition();
        return $this->db->update($this->table, $data, $conditions);
    }
944547
public function db_select($database = '')
	{
		if ($database === '')
		{
			$database = $this->database;
		}

		if (mysql_select_db($database, $this->conn_id))
		{
			$this->database = $database;
			return TRUE;
		}

		return FALSE;
	}
578436
public function createOrUpdate ($update, $exclude = array (), &$db = FALSE)
	{
		
		// Get columns and values
		
		$create		= $this->createColumnsAndValues ($exclude);
		
		// Generate update values
		
		$updateVals	= NULL;
		
		foreach ($update as $column => $value)
		{
			
			// Add column
			
			$updateVals	.= ', `' . $column . '` = ';
			
			// If the updated value is an array treat first item
			// as literal query insert and the second a params to bind
			
			$updateVals	.= is_array ($value)? $value[0] : $value;
			
		}
		
		// Trim the first character (,) from the update
		
		$updateVals	= substr ($updateVals, 2);
		
		// Get database master for write
		
		if ($db === FALSE)
		{
			$db	=& $this->getDbMaster ();
		}
		
		// Prepare query
		
		$query	= $db->prepare ('
		INSERT INTO `' . static::$dbTable . '` (' . $create['columns'] . ')
		VALUES ( ' . $create['values'] . ') 
		ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(' . static::$pk . '), ' . $updateVals . '
		');
		
		// Bind attributes
		
		$this->bindAttributes ($query, $exclude);
		
		// Bind update parameters
		
		foreach ($update as $value)
		{
			if (is_array ($value) && isset ($value[1]) && is_array ($value[1]))
			{
				foreach ($value[1] as $column => $newVal)
				{
					$query->bindValue ($column, $newVal);
				}
			}
		}
		
		// Execute
		
		if (!$this->executeCreateUpdateQuery ($query))
		{
			return FALSE;
		}
		
		// Set the pk

		if (!$this->attributeHasValue (static::$pk) || !$this->iget (static::$pk))
		{
			$this->iset (static::$pk, $db->lastInsertID ());
		}
		
		// return TRUE

		return TRUE;
		
	}