Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 is currently offline  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
Previous Topic: Simple SQL question
Next Topic: SQlite file locking - problems to handle
Goto Forum:
  


Current Time: Thu Apr 25 03:23:34 CEST 2024

Total time taken to generate the page: 0.03200 seconds