SourceFiles.org - Use the Source, Luke
Home | Register | News | Forums | Guide | MyLinks | Bookmark

Related Sites

Latest News
  General News
  Reviews
  Press Releases
  Software
  Hardware
  Security
  Tutorials
  Off Topic


Back to files

Call a lua procedure with:
SELECT client,MONTH(date),SUM(Value) FROM table PROCEDURE lua ( "myscript.lua", parameter_1, parameter_2, .. )

Example procedure:
SELECT client,MONTH(act_date),SUM(Value) FROM table PROCEDURE lua ( "/usr/src/mysql/sql/months.lua", "TEST" ); The procedure take data from the query: "SELECT client,MONTH(date),SUM(Value)"
and change the result set in:

| client | January | ...................... | December |
| cli001 |   100   | ...................... |   200    |
| cli002 |   110   | ...................... |   212    |

Variables defined by MySQL
The MySQL part defines this variables available to the LUA procedure PARAMETERS - parameters passed from the SQL statement FIELDS - field definition for the result set ROWS - contents of the result set

Global variables defined inside MySQL, always defined PARAMETERS[n] = n-th parameter

Defined before the call to "change_columns" and used after "change_columns" to define the new result set.
FIELDS.num = number of fields in the result set FIELDS[n].name = name of the n-th field of the result set FIELDS[n].type = type of the n-th field of the result set. Can be:

                 "STRING","INTEGER" or "REAL".
                 Other setting are interpreted such as "STRING".

FIELDS[n].length =for "STRING" type fields is the max length of the n-th field; for "REAL" type fields is the number of the digit in the decimal part.

Defined before the call to "end_of_records" and used after "end_of_records" to define the result set new contents. ROWS.num = number of rows in the result set ROWS[x][y] = value of the field at position x,y

LUA functions calling order
When MySQL calls a LUA script it calls the following functions in this order:

init ()
When the procedure is initialized
FIELDS and ROWS structures are not defined.

change_columns ()
FIELDS structure is defined with the data from the SELECT statement. The function can change FIELDS to define the result set structure. ROWS structure is undefined.

end_of_records ()
ROWS structure is defined and contains the data from the SELECT statement. The function can change ROWS to define the data of the new result set.


Other Sites

Discussion Groups
  Beginners
  Distributions
  Networking / Security
  Software
  PDAs

About | FAQ | Privacy | Awards | Contact
Comments to the webmaster are welcome.
Copyright 2006 Sourcefiles.org All rights reserved.