MYSQL.delete

MYSQL.delete — deletes a row from a table.

Syntax

MYSQL.delete (row)

Arguments

row

An instance of a class corresponding to a table.

Returns

On success, nil, or an error on failure.

Description

This method of the MYSQL class attempts to delete a row from the table corresponding to the class of the row argument. If the primary key of the row is set, then the deletion is relative to that primary key. If the primary key is not set then this function constructs a delete command to the database specifying as much information as possible based on the values of the instance variables in the row.

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.delete method. */
  remove_row = query[0];
  deleted = mysql.delete(remove_row);
  pretty_princ ("\nDELETE  After deleting this row:\n", remove_row, "\n");
  pretty_princ ("The .delete method returns:\n", deleted, "\n");
  query = mysql.query_to_class (mypetclass, "select * from pets where sex = 'f'");
  pretty_princ ("And a query_to_class on females ",
		"in mypetclass now returns:\n", query, "\n");
  pretty_princ ("The name of the first pet is now: ", query[0].name, "\n");
    
...

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

DELETE  After deleting this row:
{mypetclass (birth . 1993-02-04) (death) (id . 1) (name . Fluffy)
	    (owner . Harold) (sex . f) (species . cat)}
The .delete method returns:
nil
And a query_to_class on females in mypetclass now returns:
[{mypetclass (birth . 1998-09-11) (death) (id . 6) (name . Chirpy)
	     (owner . Gwen) (sex . f) (species . bird)} 
 {mypetclass (birth . 1925-12-25) (death . 0000-00-00) (id . 9)
	     (name . Petunia) (owner . Warner Bros.) (sex . f)
	     (species . pig)}]
The name of the first pet is now: Chirpy