Home » U++ Library support » U++ SQL » Demo Package of FieldOperator usage
Demo Package of FieldOperator usage [message #31679] |
Sat, 19 March 2011 19:24 |
alendar
Messages: 47 Registered: January 2010 Location: Idaho, USA
|
Member |
|
|
I saw someone ask about a Fields object (many years ago) and I couldn't find any examples in the forums of how such an object would be used. I found the FieldOperator object, but I couldn't get it to work, and the only example was I found was in the schema generation macros and those are difficult to decipher.
So, here's a package that shows how to use the FieldOperator class and the Fields typedef of a callback for the SqlInsert(Fields f) or SqlUpdate(Fields f) constructor.
The value in doing this is that you only have to build the field mappings once. I've gotten into trouble with having to duplicate the field mappings between Update and Insert statements. As the number of fields grow, so does the complexity.
The main piece is here:
// Callback for populating fields for either insert or update.
void FieldOperatorDemo::FieldLayout(FieldOperator& fo) {
fo
(TESTNAME , grid.Get(TESTNAME))
(NOTE , grid.Get(NOTE))
(RELID , grid.Get(RELID))
(CONNID , grid.Get(CONNID))
(DESIREDOUTCOME , grid.Get(DESIREDOUTCOME))
(ACTUALOUTCOME , grid.Get(ACTUALOUTCOME))
(X , grid.Get(X))
(Y , grid.Get(Y))
(COMPTYPID , grid.Get(COMPTYPID))
(TESTTYPID , grid.Get(TESTTYPID))
(TASKID , grid.Get(TASKID))
(OUTPUTVALUE , grid.Get(OUTPUTVALUE))
(PROCESSORDER , grid.Get(PROCESSORDER))
;
}
// Callback for GridCtrl's WhenAcceptedRow. Called after EndEdit is called when a row is exited.
void FieldOperatorDemo::SaveOurNewOrEditedRow()
{
int row = grid.GetCursor();
SqlStatement statement;
if (grid.IsNewRow()) {
grid.Set(PROCESSORDER, SOMENUMBER); // Just an example, can calculate a new order value
statement = SqlStatement(SqlInsert(TESTS)(THISBACK(FieldLayout)));
} else {
statement = SqlStatement(SqlUpdate(TESTS)(THISBACK(FieldLayout)).Where(TESTID == grid.Get(TESTID)));
}
Sql sql(session);
sql.Execute(statement);
It doesn't have to be a grid (GridCtrl), but that's where I was using.
cd7651feeb698f6ac6cec1f6deda5e5b
|
|
|
Goto Forum:
Current Time: Sat Apr 26 15:00:36 CEST 2025
Total time taken to generate the page: 0.01722 seconds
|