...
with TMySQLDataset(MySQLServer1.Dataset) dobegin// This will create and return a default closed no name dataset
ShareConnection := False;
TableName := 'accounts';
end;
// If you reference it again you will get the same dataset
MySQLServer1.Dataset.Active := True;
...
...
MySQLServer1.Dataset('MyAccounts','accounts',True);
// This will create a dataset called MyAccounts opening it on mysql table "accounts" in the current database
MySQLServer1.Dataset('MyOrders','orders',True,'MyAccounts','OrderAccountID=AccountID');
// This will create a 2nd dataset called "MyOrders" opening it on mysql table "orders" in the current database // It will automatically select all orders where the order's OrderAccountID is equal to the AccountID of the current record in the MyAccounts dataset. If MyAccounts has no records, then MyOrders won't have any records either.
MySQLServer1.DatasetFrom('select * from orderdetails where ProductID=10','MyOrderDetails',False,'MyOrders','DetailOrderID=OrderID').TableName := 'orderdetails';
// This will automatically create a fully updateble dataset using a SQL statement, open it and master-detail it to the MyOrders dataset where MyOrderDetails' DetailOrderID=OrderID of the MyOrders table. // Further more all inserts or appends done on any detail dataset will automatically get their linked column/field populated with the value of the linked column in the master dataset. So you really don't have to do much.
with TMySQLDataset(MySQLServer1.Dataset('MyOrderDetails')) dobegin
Open;
Append;
FieldByName('ProductDesc').AsString := 'MyComponents';
Post;
end;
// We just create a three tier master-detailing dataset relationship, have 3 fully updateble datasets on hand and we did in 3 lines of code // And it took another 3 lines of code to append a new record to the last dataset and have it inserted a new record in the mysql table, populate it's linked field with the masters's current value, without you worrying about a thing. // We can keep them all like this for further usage or get the memory back as easy as this
MySQLServer1.FreeDataset('MyAccounts');
MySQLServer1.FreeDataset('MyOrders');
MySQLServer1.FreeDataset('MyOrderDetails');
...
...
// Watch this
MyNo := MySQLServer1.DatasetFrom('@set No=23; select (Max(AccountID)+No) as MyCount from accounts').FieldByName('MyCount').AsInteger;
MySQLServer1.FreeDataset;
// The dataset has no name, so freedataset will automatically destroy the dataset without a name.
...
These methods work great, because you can create a TMySQLServer in a variant Session variable of for example an ISAPI dll and have this session's data totally persist throughout the session's usage, completely in sync with the session's context ;) Best thing since sliced bread!