@trabis
Where can I find the code for criteria and other database API type stuff?
I am trying to work your idea out but it is new to me so I am sorting out the correct method to do so. As it looks now I believe I need to build a new class.
If I put everything into this new class then you can call a single sql query with:
$sql = new XoopSQL();
$result = $sql->from('table')->column(*)->order('T_id')->select();
This will set the table to "table" the columns to "*", order to "T_ID.
If called in this manner I will clear the contents of the variables after the select is over.
So then this would work fine:
$sql = new XoopSQL();
$result = $sql->from('table')->column('*')->order('T_id')->select();
$result = $sql->from('table')->where('id: 2')->delete();
I can also look for a boolean value in the command to NOT clear the variables so then you could call this last query in this fashon. (Lets add one more deletion)
$sql = new XoopSQL();
$result = $sql->from('table')->column('*')->order('T_id')->select(false);
$result = $sql->where('id: 2')->delete(false);
$result = $sql->where('id: 3')->delete();
If I were to try your suggestion for multiple queries I could then have a couple commands that could stack queries as well as perform transactions easily:
stack queries:
$sql = new XoopSQL();
$sqlStack[] = $sql->from('table')->column('*')->order('T_id')->cmd('select', false);
$sqlStack[] = $sql->where('id: 2')->cmd('delete', false);
$sqlStack[] = $sql->where('id: 3')->cmd('delete');
$result = $testDB->doStack($sqlStack);
transaction
$sql = new XoopSQL();
$sqlStack[] = $sql->from('table')->column('*')->order('T_id')->cmd('select', false);
$sqlStack[] = $sql->where('id: 2')->cmd('delete', false);
$sqlStack[] = $sql->where('id: 3')->cmd('delete');
$result = $testDB->doTransaction($sqlStack);
The SQL class would be included as part of the database structure and I would extend the SQL class in the database specific file. So the sql class file would perform most of what the database class file does now.
This is the structure I am working on right now.
Note that calling a single query will execute the command and return a response.
Select statements will actually not be allowed in these stack or transaction commands. If you want to use a select in a transaction you will have to do each step like this:
$sql = new XoopSQL();
$result = $sql->beginTransaction();
$result = $sql->from('table')->column('*')->order('T_id')->select(false);
$result = $sql->where('id: 2')->delete(false);
$result = $sql->where('id: 3')->delete();
$result = $sql->commit();
But I will be using prepared statements in every case.
I am still tinkering with it but this is the structure that appears to work and I will be coding it up over the next couple days and try to have it ready for testing with 2.5.5 within the next 7 days.
(I have to figure out the preload stuff before I can get it working with 2.6.0. I still am not sure what the heck a preload is...)