Persephone MDB2 empty String columns and Null
Document

MDB2 empty String columns and Null

by Group Public on Monday September 22 2008 @ 10:13:07 (1/1 Points)

Tips ↪User Guide ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It

When loading an entity from the DB, you may get this error message 'Attempt to set null on non-nullable field' (DBS_SetFieldExcpetion::TYPE_NULL) if the DB column produces null and your entity is not marked with ALLOW_NULL.

If your DB does actually allow null, you should probably flag your entity to also ALLOW_NULL, or provide an appropriate converstion function.

If you DB column is declared something like this however:

`Name` VARCHAR( 50 ) NOT NULL,

and you nonetheless get the error, it may be due to your MDB2 factory settings.

By default MDB2 uses a compatibility mode that empty strings are converted to Null values. (You'll have to ask the MDB2 team why this it the default behaviour.)

To turn off this behaviour, but retain other compatibility options, you can construct your MDB2 object with that option turned off.

@$mdb_fail = MDB2::factory( 
  array( 'phptype' => 'mysqli', ... ),
  array(  'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ) /*options*/
  );
© 2008-2010 edA-qa mort-ora-y
Using Persephone and TestPlan
Tag: