Updates a post meta value if it exists or inserts if it does not.
@param postId The post id.
@param metaKey The key.
@param metaValue The value.
@throws SQLException on database error.
172449
public void updatePostMetaValue(final long postId, final String metaKey, final String metaValue) throws SQLException {

      Meta currMeta = selectPostMetaValue(postId, metaKey);
      if(currMeta == null) {
         Connection conn = null;
         PreparedStatement stmt = null;
         Timer.Context ctx = metrics.setPostMetaTimer.time();
         try {
            conn = connectionSupplier.getConnection();
            stmt = conn.prepareStatement(insertPostMetaSQL);
            stmt.setLong(1, postId);
            stmt.setString(2, metaKey);
            stmt.setString(3, metaValue);
            stmt.executeUpdate();
         } finally {
            ctx.stop();
            SQLUtil.closeQuietly(conn, stmt);
         }
      } else {
         Connection conn = null;
         PreparedStatement stmt = null;
         Timer.Context ctx = metrics.setPostMetaTimer.time();
         try {
            conn = connectionSupplier.getConnection();
            stmt = conn.prepareStatement(updatePostMetaValueSQL);
            stmt.setString(1, metaValue);
            stmt.setString(2, metaKey);
            stmt.setLong(3, postId);
            stmt.executeUpdate();
         } finally {
            ctx.stop();
            SQLUtil.closeQuietly(conn, stmt);
         }
      }
   }
796713
private static void validate(@NotNull EntityMetadata entityMetadata) {
        if (StringUtils.isEmpty(entityMetadata.getTableName())) {
            throw new MetadataException(String.format("Invalid table name: \"%s\"", entityMetadata.getTableName()));
        }

        if (entityMetadata.getPartitionKeySize() < 1) {
            throw new MetadataException(String.format("Entity \"%s\"must contains primary key", entityMetadata.getTableName()));
        }
    }
635207
public function set( $post_id, $key, $value, $add = false, $unique = false ) {
		if ( $post_id <= 0 ) {
			return false;
		}

		if ( ! $add ) {
			return update_post_meta( $post_id, $this->get_meta_key( $key ), $value );
		}

		if ( $unique ) {
			$values = $this->get( $key, $post_id, false, [] );
			if ( in_array( $value, $values ) ) {
				return false;
			}
		}

		return add_post_meta( $post_id, $this->get_meta_key( $key ), $value );
	}
1207818
public function set($post_id, string $key, array $values)
    {
        $post_id = (int) ($post_id ?? get_the_ID());

        if (!$post_id || !$key) {
            return; // Not possible.
        }
        $this->unset($post_id, $key);

        $key = $this->key($key);
        foreach ($values as $_value) {
            add_post_meta($post_id, $key, $_value);
        } // unset($_value); // Housekeeping.
    }
176744
@Override
	public int update(DataColumns dataColumns) throws SQLException {

		UpdateBuilder<DataColumns, TableColumnKey> ub = updateBuilder();
		ub.updateColumnValue(DataColumns.COLUMN_NAME, dataColumns.getName());
		ub.updateColumnValue(DataColumns.COLUMN_TITLE, dataColumns.getTitle());
		ub.updateColumnValue(DataColumns.COLUMN_DESCRIPTION,
				dataColumns.getDescription());
		ub.updateColumnValue(DataColumns.COLUMN_MIME_TYPE,
				dataColumns.getMimeType());
		ub.updateColumnValue(DataColumns.COLUMN_CONSTRAINT_NAME,
				dataColumns.getConstraintName());

		ub.where()
				.eq(DataColumns.COLUMN_TABLE_NAME, dataColumns.getTableName())
				.and()
				.eq(DataColumns.COLUMN_COLUMN_NAME, dataColumns.getColumnName());

		PreparedUpdate<DataColumns> update = ub.prepare();
		int updated = update(update);

		return updated;
	}
506339
public function update_meta( $meta_key = '', $values = '', $prev_values = '' ) {
		return \update_post_meta( $this->id(), $meta_key, $values, $prev_values );
	}
213249
int update(Config config, Connection conn, String sql, Object... paras) throws SQLException {
		PreparedStatement pst = conn.prepareStatement(sql);
		config.dialect.fillStatement(pst, paras);
		int result = pst.executeUpdate();
		DbKit.close(pst);
		return result;
	}
1237687
public function incrementMeta(NodeRef $nodeRef, $metaID, $value = 1)
    {
        $metaID = ltrim($metaID, '#');

        $this->NodeEvents->fireNodeEvents(__FUNCTION__, '', $nodeRef, $metaID);

        $db = $this->getConnectionForWrite($nodeRef);
        $id = $this->getRecordIDFromNodeRef($nodeRef);

        // determine the meta storage
        $metaDef = $nodeRef->getElement()->getSchema()->getMetaDef($metaID);
        $datatype = $metaDef->getDatatype();
        $table = $db->quoteIdentifier($this->NodeDBMeta->getMetaTable($nodeRef, $datatype));
        $tableid = $this->NodeDBMeta->getPrimaryKey($nodeRef);
        $datatypeCol = $this->NodeDBMeta->getMetaDatatypeColumn($datatype);

        $value = intval($value);
        $newValue = false;
        $oldValue = false;
        $originalMeta = null;

        $maxValue = $this->getMaxIntForDatatype($datatype);
        $minValue = $this->getMinIntForDatatype($datatype);

        try {
            $affectedRows = $db->write("UPDATE {$table} SET {$datatypeCol}Value = LAST_INSERT_ID({$datatypeCol}Value+{$value}) WHERE {$tableid} = {$db->quote($id)} AND Name = {$db->quote($metaID)}", DatabaseInterface::AFFECTED_ROWS);
            if ($affectedRows == 1) {
                $newValue = intval($db->readField("SELECT LAST_INSERT_ID()"));
                $oldValue = $newValue - $value;
            }
        } catch (SQLException $e) {
            if ($e->getCode() != 22003 || strpos($e->getMessage(), 'Numeric value out of range') === false) {
                throw $e;
            }

            // must ask the DB for its current value
            $oldValue = intval($db->readField("SELECT {$datatypeCol}Value FROM {$table} WHERE {$tableid} = {$db->quote($id)} AND Name = {$db->quote($metaID)}"));
            $newValue = $oldValue + $value;

            // ensure the new values don't overflow (note that $value can be positive or negative and isn't necessarily 1)
            if ($newValue > $maxValue) {
                $newValue = $maxValue;
            } elseif ($newValue < $minValue) {
                $newValue = $minValue;
            }

            if ($newValue === $oldValue) {
                $affectedRows = 1;
            } else {
                $affectedRows = $db->write("UPDATE {$table} SET {$datatypeCol}Value = {$newValue} WHERE {$tableid} = {$db->quote($id)} AND Name = {$db->quote($metaID)}", DatabaseInterface::AFFECTED_ROWS);
            }
        } catch (Exception $e) {
            throw $e;
        }

        // new value didn't get set because the meta record hasn't been created yet.
        if ($newValue === false) {
            $newValue = $value;
            // ensure the new values don't overflow (note that $value can be positive or negative and isn't necessarily 1)
            if ($newValue > $maxValue) {
                $newValue = $maxValue;
            } elseif ($newValue < $minValue) {
                $newValue = $minValue;
            }
        }

        if ($affectedRows == 0) {
            $affectedRows = $db->write("INSERT INTO {$table} ({$tableid}, Name, {$datatypeCol}Value) Values ({$db->quote($id)}, {$db->quote($metaID)}, {$newValue}) ON DUPLICATE KEY UPDATE {$datatypeCol}Value = LAST_INSERT_ID({$datatypeCol}Value+{$value})", DatabaseInterface::AFFECTED_ROWS);

            // new record inserted
            if ($affectedRows == 1) {
                $metaEvent = 'add';
                $newMeta = new Meta($metaID, $newValue);
                $newMeta->setMetaStorageDatatype($metaDef->Datatype);
                $originalMeta = null;

            // duplicate key update encountered
            } else if ($affectedRows == 2) {
                $metaEvent = 'update';

                $newValue = intval($db->readField("SELECT LAST_INSERT_ID()"));
                $oldValue = $newValue - $value;

                $newMeta = new Meta($metaID, $newValue);
                $newMeta->setMetaStorageDatatype($metaDef->Datatype);

                $originalMeta = new Meta($metaID, $oldValue);
                $originalMeta->setMetaStorageDatatype($metaDef->Datatype);

            } else {
                throw new NodeException('Unable to increment meta ID ['.$metaID.'] on record ['.$nodeRef.']');
            }
        } else {
            $metaEvent = 'update';

            $newMeta = new Meta($metaID, $newValue);
            $newMeta->setMetaStorageDatatype($metaDef->Datatype);

            $originalMeta = new Meta($metaID, $oldValue);
            $originalMeta->setMetaStorageDatatype($metaDef->Datatype);
        }

        $this->NodeEvents->fireMetaEvents('meta', $metaEvent, $nodeRef, $newMeta, $originalMeta);
    }
369568
public void update(Object po) throws Exception {
		SqlParamsPairs sqlAndParams = ModelSqlUtils.getUpdateFromObject(po);
		
		getProxy().update(sqlAndParams.getSql(), sqlAndParams.getParams());
	}
1145367
public void setNodeMetaData(Object key, Object value) {
        if (key==null) throw new GroovyBugError("Tried to set meta data with null key on "+this+".");
        if (metaDataMap == null) {
            metaDataMap = new ListHashMap();
        }
        Object old = metaDataMap.put(key,value);
        if (old!=null) throw new GroovyBugError("Tried to overwrite existing meta data "+this+".");
    }
849584
private void readMetadata() throws SQLException {
    if (valid) {
      return;
    }

    String[] metaInfos = queryMetaInfos(isFunction);
    String paramList = metaInfos[0];
    String functionReturn = metaInfos[1];

    parseParamList(isFunction, paramList);

    // parse type of the return value (for functions)
    if (isFunction) {
      parseFunctionReturnParam(functionReturn);
    }

  }
390962
public boolean updatePostContent(long postId, final String content) throws SQLException {
      Connection conn = null;
      PreparedStatement stmt = null;
      Timer.Context ctx = metrics.updatePostTimer.time();
      try {
         conn = connectionSupplier.getConnection();
         stmt = conn.prepareStatement(updatePostContentSQL);
         stmt.setString(1, content);
         stmt.setLong(2, postId);
         return stmt.executeUpdate() > 0;
      } finally {
         ctx.stop();
         SQLUtil.closeQuietly(conn, stmt);
      }
   }
771795
private void writeMetadata() throws SQLException {
        LOGGER.info("Writing metadata...");
        PreparedStatement pStmtMetadata = this.conn.prepareStatement(DbConstants.INSERT_METADATA_STATEMENT);

        // Bounds
        pStmtMetadata.setString(1, DbConstants.METADATA_BOUNDS);
        BoundingBox bb = this.configuration.getBboxConfiguration();
        if (bb == null) {
            // Calculate bounding box from poi coordinates
            Statement stmt = this.conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT MIN(minLat), MIN(minLon), MAX(maxLat), MAX(maxLon) FROM poi_index;");
            rs.next();
            bb = new BoundingBox(rs.getDouble(1), rs.getDouble(2), rs.getDouble(3), rs.getDouble(4));
        }
        pStmtMetadata.setString(2, bb.minLatitude + "," + bb.minLongitude + "," + bb.maxLatitude + "," + bb.maxLongitude);
        pStmtMetadata.addBatch();

        // Comment
        pStmtMetadata.setString(1, DbConstants.METADATA_COMMENT);
        if (this.configuration.getComment() != null) {
            pStmtMetadata.setString(2, this.configuration.getComment());
        } else {
            pStmtMetadata.setNull(2, Types.NULL);
        }
        pStmtMetadata.addBatch();

        // Date
        pStmtMetadata.setString(1, DbConstants.METADATA_DATE);
        pStmtMetadata.setLong(2, System.currentTimeMillis());
        pStmtMetadata.addBatch();

        // Language
        pStmtMetadata.setString(1, DbConstants.METADATA_LANGUAGE);
        if (!this.configuration.isAllTags() && this.configuration.getPreferredLanguage() != null) {
            pStmtMetadata.setString(2, this.configuration.getPreferredLanguage());
        } else {
            pStmtMetadata.setNull(2, Types.NULL);
        }
        pStmtMetadata.addBatch();

        // Version
        pStmtMetadata.setString(1, DbConstants.METADATA_VERSION);
        pStmtMetadata.setInt(2, this.configuration.getFileSpecificationVersion());
        pStmtMetadata.addBatch();

        // Ways
        pStmtMetadata.setString(1, DbConstants.METADATA_WAYS);
        pStmtMetadata.setString(2, Boolean.toString(this.configuration.isWays()));
        pStmtMetadata.addBatch();

        // Writer
        pStmtMetadata.setString(1, DbConstants.METADATA_WRITER);
        pStmtMetadata.setString(2, this.configuration.getWriterVersion());
        pStmtMetadata.addBatch();

        pStmtMetadata.executeBatch();
        this.conn.commit();
    }
64781
@Override
	public int update(GeometryColumnsSfSql geometryColumns) throws SQLException {

		UpdateBuilder<GeometryColumnsSfSql, TableColumnKey> ub = updateBuilder();
		ub.updateColumnValue(GeometryColumnsSfSql.COLUMN_GEOMETRY_TYPE,
				geometryColumns.getGeometryTypeCode());
		ub.updateColumnValue(GeometryColumnsSfSql.COLUMN_COORD_DIMENSION,
				geometryColumns.getCoordDimension());
		ub.updateColumnValue(GeometryColumnsSfSql.COLUMN_SRID,
				geometryColumns.getSrid());

		ub.where()
				.eq(GeometryColumnsSfSql.COLUMN_F_TABLE_NAME,
						geometryColumns.getFTableName())
				.and()
				.eq(GeometryColumnsSfSql.COLUMN_F_GEOMETRY_COLUMN,
						geometryColumns.getFGeometryColumn());

		PreparedUpdate<GeometryColumnsSfSql> update = ub.prepare();
		int updated = update(update);

		return updated;
	}
1299587
public void setMetadata(String key, Object value) {
        if (value != null) {
            getMetadata().put(key, value);
        }
    }
281149
public function update(
        $table = null,
        SqlInterface $database = null,
        $primary = null
    ) {
        //if no table
        if (is_null($table)) {
            //if no default table either
            if (!$this->table) {
                //throw error
                throw SqlException::forTableNotSet();
            }

            $table = $this->table;
        }

        //if no database
        if (is_null($database)) {
            //and no default database
            if (!$this->database) {
                throw SqlException::forDatabaseNotSet();
            }

            $database = $this->database;
        }

        //get the meta data, the valid column values and whether is primary is set
        $meta = $this->getMeta($table, $database);
        $data = $this->getValidColumns(array_keys($meta[self::COLUMNS]));

        //update original data
        $this->original = $this->data;

        //from here it means that this table has primary
        //columns and all primary values are set

        if (is_null($primary)) {
            $primary = $meta[self::PRIMARY];
        }

        if (is_string($primary)) {
            $primary = [$primary];
        }

        $filter = [];
        //for each primary key
        foreach ($primary as $column) {
            //add the condition to the filter
            $filter[] = [$column.'=%s', $data[$column]];
        }

        //we update it
        $database->updateRows($table, $data, $filter);

        return $this;
    }
751734
public function postupdateNotExist($post_id)
    {
        if ($this->countPostUpdates($post_id) == 0)
        {
            DB::table('posts')
                ->where('id', '=', $post_id)
                ->update(['postupdate' => 0])
            ;
        }
    }