Not Null Constraints
By default, an
RWDBColumn can hold
NULL values. You can override this default behavior by setting a not null constraint to enforce that a given column always have a value. Use method
RWDBColumn::nullAllowed() and pass in the
bool value
false to set this constraint on a column.
This code creates a schema with two columns, one that allows NULL values and one that does not:
RWDBSchema schema;
RWDBColumn col1, col2;
col1.type(RWDBValue::String).nullAllowed(true);
col1.name("col1").storageLength(100);
col2.type(RWDBValue::String).nullAllowed(false); //1
col2.name("col2").storageLength(100000);
schema.appendColumn(col1);
schema.appendColumn(col2);
myDbase.createTable("myTestTbl", schema);
Line //1 sets the not null constraint on col2.
To return the value of a column’s nullAllowed attribute, call RWDBColumn::nullAllowed() with no argument.