MYSQL.query_and_store (query_string)
This method of the MYSQL class emits a query to the database, and collects the results into an instance of MYSQL_RES. This function will throw an error if the query fails.
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");.
This example is taken from Section 2.2, “Tutorial 2: create_pets.g”
... /* Test the MYSQL.query_and_store method. */ query = mysql.query_and_store ("select name, birth from pets"); pretty_princ("\nQUERY The .query_and_store method applied ", "to the 'name' and 'birth' fields in mypetclass ", "\nreturns this MYSQL_RES istance:\n", query, "\n"); query_data = query.Data(); pretty_princ("Its data, recovered using ", "the .Data() method, is:\n", query_data, "\n"); ...
The output for this section of the code is as follows:
QUERY The .query_and_store method applied to the 'name' and 'birth' fields in mypetclass returns this MYSQL_RES istance: {MYSQL_RES (current_field . 0) (eof . 1) (field_count . 2) (fields . [{MYSQL_FIELD (decimals . 0) (def) (flags . 1) (length . 20) (max_length . 8) (name . name) (table . pets) (type . 253)} {MYSQL_FIELD (decimals . 0) (def) (flags . 0) (length . 10) (max_length . 10) (name . birth) (table . pets) (type . 10)}])} Its data, recovered using the .Data() method, is: [[Claws 1994-03-17] [Buffy 1989-05-13] [Fang 1990-08-27] [Bowser 1995-08-31] [Chirpy 1998-09-11] [Whistler 1997-12-09] [Slim 1996-04-29] [Petunia 1925-12-25]]
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.