MYSQL.requery

MYSQL.requery — updates a row by querying the database.

Syntax

MYSQL.requery (row)

Arguments

row

An instance of a class corresponding to a table.

Returns

The same row. This function will throw an error on failure.

Description

This method of the MYSQL class issues a query to the MySQL server in an attempt to update the information in the row instance with the current data in the database. Normally the primary key for this row should be known in order for the query to succeed. If the primary key is not known, then this function will emit the most precise query that it can with the data available in the row instance. If the resulting query generates any number of rows other than 1, then the function throws an error.

This method is defined in the Gamma library /usr/cogent/require/MySQLSupport.g. It is made available to a Gamma program with the statement: require("MySQLSupport");.

Example

This example is taken from Section 2.2, “Tutorial 2: create_pets.g”

...

  /* Test the MYSQL.requery method. */
  requery = mysql.requery(query[1]);
  pretty_princ ("\nREQUERY  The .requery method applied to the ",
		"second class in the above query returns:\n", requery, "\n");

...

The output for this section of the code is as follows:

REQUERY  The .requery method applied to the second class in the above query returns:
{mypetclass (birth . 1925-12-25) (death . 0000-00-00) (id . 9)
	    (name . Petunia) (owner . Warner Bros.) (sex . f)
	    (species . pig)}