Tuesday, December 4, 2012

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; But execute is trying to use function name as the $sql

Hello all,  thank you in advance for any help you may be able to provide.

I'm using cakePHP 2.2.1

The following code works perfectly:
   
  class OptionsController extends AppController {
var $uses = array('Option', 'ShooterEvent', 'ShooterOption');

public function calc($id) {
  $paid_entries = $this->ShooterEvent->getPaidEntries($event_id);
  $paid_options = $this->ShooterOption->find('all');
   
  $something =  'Default answer';

  $this->set(compact('paid_entries', 'something', 'paid_options'));
}


 The following change will die horribly:

  // Made to class above
  $something =  'Default answer';
 $something = $this->ShooterOption->getSomething(1);

// Made to the ShooterOption class
class ShooterOption extends AppModel {
  function getSomething($option_id) {
    return 1;
  }
}



The error is: Error: 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 'getSomething' at line 1

The debug trace shows:

Stack Trace

  • CORE\Cake\Model\Datasource\DboSource.php line 461PDOStatement->execute(array)
            try {              $query = $this->_connection->prepare($sql, $prepareOptions);              $query->setFetchMode(PDO::FETCH_LAZY);              if (!$query->execute($params)) {                  $this->_results = $query;
    array(  	(int) 0 => (int) 1  )
  • CORE\Cake\Model\Datasource\DboSource.php line 427DboSource->_execute(string, array)
            $options += array('log' => $this->fullDebug);            $t = microtime(true);          $this->_result = $this->_execute($sql, $params);  
    'getSomething'  array(  	(int) 0 => (int) 1  )
  • CORE\Cake\Model\Datasource\DboSource.php line 671DboSource->execute(string, array, array)
            if ($cache && ($cached = $this->getQueryCache($sql, $params)) !== false) {              return $cached;          }          if ($result = $this->execute($sql, array(), $params)) {              $out = array();
    'getSomething'  array()  array(  	(int) 0 => (int) 1  )
  • CORE\Cake\Model\Datasource\DboSource.php line 613DboSource->fetchAll(string, array, array)
                    } else {                      $cache = true;                  }                  return $this->fetchAll($args[0], $args[1], array('cache' => $cache));              }
    'getSomething'  array(  	(int) 0 => (int) 1  )  array(  	'cache' => object(AppModel) {}  )
  • CORE\Cake\Model\Model.php line 784DboSource->query(string, array, AppModel)
            if ($result !== array('unhandled')) {              return $result;          }          $return = $this->getDataSource()->query($method, $params, $this);          return $return;
    'getSomething'  array(  	(int) 0 => (int) 1  )  object(AppModel) {  	useDbConfig => 'default'  	useTable => 'shooter_options'  	id => false  	data => array([maximum depth reached])  	schemaName => 'shoots'  	table => 'shooter_options'  	primaryKey => 'id'  	validate => array([maximum depth reached])  	validationErrors => array([maximum depth reached])  	validationDomain => null  	name => 'ShooterOption'  	alias => 'ShooterOption'  	tableToModel => array(  		[maximum depth reached]  	)  	cacheQueries => false  	belongsTo => array([maximum depth reached])  	hasOne => array([maximum depth reached])  	hasMany => array([maximum depth reached])  	hasAndBelongsToMany => array([maximum depth reached])  	actsAs => null  	Behaviors => object(BehaviorCollection) {}  	whitelist => array([maximum depth reached])  	cacheSources => true  	findQueryType => null  	recursive => (int) 1  	order => null  	virtualFields => array([maximum depth reached])  	__backAssociation => array([maximum depth reached])  	__backInnerAssociation => array([maximum depth reached])  	__backOriginalAssociation => array([maximum depth reached])  	__backContainableAssociation => array([maximum depth reached])  	findMethods => array(  		[maximum depth reached]  	)  	tablePrefix => ''  }
  • APP\Controller\OptionsController.php line 199Model->__call(string, array)
        $paid_options = $this->ShooterOption->find('all');                $something =  'Default answer';        $something = $this->ShooterOption->getSomething(1);          
    'getSomething'  array(  	(int) 0 => (int) 1  )
  • APP\Controller\OptionsController.php line 199AppModel->getSomething(integer)
        $paid_options = $this->ShooterOption->find('all');                $something =  'Default answer';        $something = $this->ShooterOption->getSomething(1);          
    (int) 1


It's trying to execute the sql statement "getSomething."  It's as if it can't find the function in the Model?  Any ideas would be greatly appreciated.

Thanks

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: