A Way To Use Dbtype And Ctypevalidator

Hi all,

Basis:

  • A database without rules, and don’t have all information (dynamic database)

  • A import system with a ‘force’ possibility.

Actually we do something like this:


while($sLine=array_shift($aFile)){

  $aLine=str_getcsv($sLine);

  $oModel = new DynamicModel;

  foreach($aCSVfield as $sFieldName=>$iFieldKey){

    $oModel->$sFieldName=$aLine[$iFieldKey];// I want to control validity

  }

  if($oModel->save()){

    $aGood[]=$sLine:

  }else{

    $aBad[]=$sLine;

  }

}

It’s ok but it can break if there are some bad value (CBDcommand failed).

First option is to use transaction, but then we don’t really use ‘force’ system.

Second option, is to assign attribute ONLY if $aLine[$iFieldKey] are on valid type .

Then something like this:


  foreach($aCSVfield as $sFieldName=>$iFieldKey){

    $dbType=$oModel->metadata->tableSchema->columns[$sFieldName]->dbType;

    if(validateFunction($dbType,$aLine[$iFieldKey])

      $oModel->$sFieldName=$aLine[$iFieldKey];

  }

  $oModel->save()

I think i can use $dbType and CTypeValidator for someFunction but don’t found how to start here.

For example, in $dbType i have:

  • character varying(20)

  • timestamp without time zone

  • integer

etc …

I just want to know if there are some integrated solution in Yii ? Without rules !

Thanks,

Denis