MYSQL.class_from_table

MYSQL.class_from_table — creates a Gamma class from a table.

Syntax

MYSQL.class_from_table (symclassname, superclass, tablename)

Arguments

symclassname

A symbol, representing the name of the class to create.

superclass

The superclass for the newly created class, or nil.

tablename

The name of the MySQL table, as a string, to use as the template for this class.

Returns

On success, the new class. Otherwise, nil.

Description

This method of the MYSQL class creates a new Gamma class whose instance variables correspond to the column names in the table tablename. If the class named symclassname already exists, or the table tablename does not exist in the MySQL database, then this function returns nil.

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.class_from_table method. */
  mysql.class_from_table (#mypetclass, nil, "pets");
  pretty_princ ("\nCLASS  The .class_from_table method ",
		"returns the mypetclass:\n", mypetclass, "\n");

...

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

CLASS  The .class_from_table method returns the mypetclass:
(defclass mypetclass nil 
[(__columns . #0=[id name owner species sex birth death]) 
 (__primary_key . id) (__table . #1=pets)]
[birth death id name owner sex species])