PARTICULAR WAY OF CREATING LINES - MX

Create a line

// Get line, if line does not exist, the line is created. 
// Main index is used to see if a line with "toto" exists
Nod node=_doJava.getLineNode("toto",true);
// Set value "hello" to field a15nlrp 
node.setField("a15nlrp","hello")
// Save the line
node.updateLineNode(node);

Choosing column to read data from during run time

If you want to read data from different columns, it can be done using the column name.
Example:

int myNumber = (int)(Str.ToDouble(_str1));

//retrieves data from the column named "colX" where X is the current value of _str1
double myDouble=_doJava.getLineNode().getDoubleField("col"+myNumber);

return myDouble;

It's also possible to assign several values:

_doJava.getLineNode().setField("var1",4);
_doJava.getLineNode().setField("toto",4);

Create lines in a table with code

It is sometimes useful to duplicate the lines of a table.
Here is the code to do it:

// We store the present line in a Nod object
Nod nodeClone=_doJava.getLineNode().cloneNode();

// MANDATORY : In the Nod stored in RAM, we delete ID field (that is idmx) that must bu updated
nodeClone.setFieldNull(com.td.treedbms.type.TypeSQL.ID);

// We delete the links to the file (for original table only)
nodeClone.setFieldNull(com.mxbrain.db.TypeMxAbs.lien_mxfile);
nodeClone.setFieldNull(com.mxbrain.db.TypeMxAbs.NoLine);

// We change the value of field "toto"  (not mandatory)
nodeClone.setField("toto", "test");

// We commit the line. If the id already exist, the line is updated, not created!
_doJava.updateOrInsert(nodeClone,false);

Was this article helpful?

Powered by Zendesk