yii2: (oracle 11g)The create action is saving the values incorrectly
What steps will reproduce the problem?
Using Oracle Database 11g.
I created a CRUD for the table:
tb_domain (sq_domain, no_domain, nr_matricula).
The create action is saving the values incorrectly.
The update and delete action is correct.
What is the expected result?
The values must be registered correctly.
What do you get instead?
After executing the creation action, the no_domain column has the value of the nr_domain.
Additional info
script
CREATE SEQUENCE "SQ_DOMINIO";
CREATE TABLE "TB_DOMINIO"
( "SQ_DOMINIO" NUMBER(6,0),
"NO_DOMINIO" VARCHAR2(40 BYTE),
"NR_MATRICULA" NUMBER(6,0)
);
create or replace TRIGGER "TG_TB_DOMINIO" before insert
on TB_DOMINIO for each row
declare
integrity_error exception;
errno integer;
errmsg char(200);
dummy integer;
found boolean;
begin
if :new.SQ_DOMINIO IS NULL then
select SQ_DOMINIO.NEXTVAL INTO :new.SQ_DOMINIO from dual;
end if;
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
action
/**
* Creates a new Dominio model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Dominio();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->SQ_DOMINIO]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
model
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "TB_DOMINIO".
*
* @property integer $SQ_DOMINIO
* @property string $NO_DOMINIO
* @property integer $NR_MATRICULA
*
* @property TBITEMDOMINIO[] $tBITEMDOMINIOs
* @property TBQUESTAO[] $tBQUESTAOs
*/
class Dominio extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'TB_DOMINIO';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
// [['SQ_DOMINIO'], 'required'],
// [['SQ_DOMINIO'], 'unique'],
[['NR_MATRICULA'], 'integer'],
[['NO_DOMINIO'], 'string', 'max' => 40],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'SQ_DOMINIO' => 'Sq Dominio',
'NO_DOMINIO' => 'No Dominio',
'NR_MATRICULA' => 'Nr Matricula',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTBITEMDOMINIOs()
{
return $this->hasMany(TBITEMDOMINIO::className(), ['SQ_DOMINIO' => 'SQ_DOMINIO']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTBQUESTAOs()
{
return $this->hasMany(TBQUESTAO::className(), ['SQ_DOMINIO' => 'SQ_DOMINIO']);
}
}
form
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Dominio */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="dominio-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'NO_DOMINIO')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'NR_MATRICULA')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Q | A |
---|---|
Yii version | 2.0.10 |
PHP version | 5.5.9 |
Operating system | Ubuntu Trusty 64bits |
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (8 by maintainers)
It worked!
I researched a way to execute the command generated by yii in my GUI software, and I found this:
http://stackoverflow.com/questions/12105669/returning-parameters-in-oracle-sql-insert-statements
Then I went up to the code file
db/oci/Schema.php
insert()
method and added the command inside pl/sql:That way it worked!
Please, when possible, check if this is the case (I believe it to be).