User:Woozle/DataScript

About
DataScript is what I came up with when I needed to simulate a set of database interactions (reads, writes) without actually making changes to the data.


 * /data-script.php

versus Transactions
In theory, using transactions could work for this, but it has the following disadvantages:
 * I can't find clear documentation on what happens if code crashes during a transaction. I've been told that MySQL will roll back the transaction (which is what I would want), but it's not clear if this behavior is officially supported. It's also not clear if this is part of the SQL spec, or if other db engines might behave differently.
 * Some types of tables may not be compatible with transactions. The documentation is unclear on this too. Although there is documentation on the syntax and on something called isolation level, there does not seem to be any documentation on how transactions work in MySQL.
 * (minor) Making a nice readout of the simulation requires some coding anyway, and is awkward to integrate into db-library code which is not supposed to output anything to the display except on severe errors.

In short, then, DataScript gives me more control over the process.

Explanation
The "script" in DataScript is perhaps a bit of a misnomer, in that it is not actually a scripting language but rather a hierarchy of objects created by code. The class of each object determines its overall function, with some actions being determined by particular data or parameters given to the object.

Classes

 * Script_Element (abstract) -- base of all script classes
 * Script_Script -- possibly obsolete? was for handling sub-scripts
 * Script_RowObj -- base class for handling data rows
 * Script_RowObj_scratch -- placeholder for writable datarow object which can be created later
 * Script_DataRow -- placeholder for array data for other classes to use; doesn't actually do anything
 * Script_SQL_DataRow_Command (abstract) -- classes that do something with a single row of data that has an ID
 * Script_Tbl_Insert -- class for inserting a datarow
 * Script_Row_Update -- class for updating a datarow
 * Script_Row_Update_fromInsert -- updates a newly-created data record
 * Script_Row_Data -- holds scriptable data from a loaded recordset
 * Script_Status -- for debugging: display a message
 * Script_IF_Ok -- conditional: executes a set of scripts if prior operation goes ok
 * Script_SQL_Use_ID -- used for grabbing the ID of a newly-created row from a Script_Tbl_Insert
 * Script_Copy_Named -- Copy named fields from one array to named fields in another