Yii Framework Forum: Cdbexception Error Using Giix Generators - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cdbexception Error Using Giix Generators Rate Topic: -----

#1 User is offline   Jonny 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 165
  • Joined: 26-December 11

Posted 07 April 2013 - 12:07 AM

Hi,

I recently installed Giix, i've never used it before, I have some small sample data in a few tables. I was just clicking through related information, when I went to create another record in a table through Yii. I got the following error that I wondered if anyone could help me with. I have not touched any of the code myself it is all purely generated from Giix and i've even regenerated what I thought the problem model/controller was and it still fails.

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option FROM `display_option` `t`' at line 1. The SQL statement executed was: SELECT id, option FROM `display_option` `t`


 C:\xampp\htdocs\Giix\protected\extensions\giix-components\GxActiveRecord.php(248): CActiveRecord->findAll(CDbCriteria)
       if (!is_array($attributes))
244                 $attributes = array($attributes);
245             $attributes = array_merge($pks, $attributes);
246         }
247         $criteria->select = $attributes;
248         return parent::findAll($criteria); // error line
249     }
250 
251     /**
252      * Extracts and returns only the primary keys values from each model.
253      * @param GxActiveRecord|array $model A model or an array of models.**/


// And also

 C:\xampp\htdocs\Giix\protected\views\Item\_form.php(68): GxActiveRecord->findAllAttributes(null, true)

        <?php echo $form->dropDownList($model, 'display_options', GxHtml::listDataEx(DisplayOption::model()->findAllAttributes(null, true))); ?> // error line 

Do you need anything more of the stack?

This occurs when I'm looking at my Item/create or Item/update model/action. I'm guessing (and it is only a guess) it must be some kind of error within my DB structure taht causes Yii to get unhappy or some conflict within Giix: I wasn't sure where to post this, if it needs to be moved to extensions then please do so and sorry. I'll post the two DB structures

I have created a new app and used standard Gii and all the create/admin/update functions are available to me within the Model that was throwing the error using Giix.

Item Table
  ### Rest of command
  `display_options` int(3) unsigned NOT NULL,
 ### More commands 
  KEY `fk_display_option` (`display_options`)

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;


display_option table

  `id` int(3) unsigned NOT NULL AUTO_INCREMENT,
  `option` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;



If somebody could help me out that would be great :)

I'm at a bit of a loss as this is just from the Gixx generated code.

Thanks in advance

Jonny
0

#2 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 07 April 2013 - 07:47 PM

Hi Jonny,

It seems that option is a reserved word for MySQL.

Gii isn't failing probably because the column name is being quoted on the generated query or (most probably) it is selecting all columns with *.

It is probably a bug in giix.

To work around it, you can change the line 68 in _form.php to:

<?php echo $form->dropDownList($model, 'display_options', GxHtml::listDataEx(DisplayOption::model()->findAllAttributes('`option`', true))); ?>


What I'm doing here is replacing the automatic use of the representing column (see GxActiveRecord::findAllAttributes code) for the column name. The downside is that if your representing column changes, you'll have to update it on hte view.

Please let me know whether it works.
Thanks for reporting it!
1

#3 User is offline   Jonny 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 165
  • Joined: 26-December 11

Posted 07 April 2013 - 08:52 PM

Hi Rodrigo,

Thanks for looking at this for me. Your work around did work. I actually decided to make the changes to my DB Schema and reupload it and all models/actions seem to work great.

Thanks for taking the time to sort this for me.

Jonathon :D
0

#4 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 08 April 2013 - 01:01 AM

No problem, Jonny! I hope that giix is being useful to you.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users