For example consider the table we created earlier:
# table Person +----------+-----------+------------------+-------------+ | LastName | FirstName | Address | DateOfBirth | +----------+-----------+------------------+-------------+ | Smith | John | 5 Friendly Place | 1980-01-01 | +----------+-----------+------------------+-------------+
The SQL command to change every address in the table to '6 London Road' is:
UPDATE Person SET Address = '6 London Road'
To update the data using a web.database cursor we would do the following:
cursor.update(table='Person',columns=['Address'],values=['6 London Road'])
The table now looks like this:
+----------+-----------+---------------+-------------+ | LastName | FirstName | Address | DateOfBirth | +----------+-----------+---------------+-------------+ | Smith | John | 6 London Road | 1980-01-01 | +----------+-----------+---------------+-------------+
The update() method of a web.database cursor looks like this:
table, columns, values, __sqlValues [, where] [, execute]) |
?
parameters in the _sqlValues sequence. If there are more values specified in values than _sqlValues the remaining values are used to substitute for ?
parameters in where.
?
parameters for substitution then values contains the values to be substituted. Otherwise values must be an empty sequence.
cursor.where()
. If where is a string it is converted to the correct format.
False
the method returns the SQL string to perform the desired operations. If True
the SQL is executed. If not specified takes the value specified in the cursor which by default is True