CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]

I’m working on an ODBC schema. I’ve created the model successfully and now I’ve ran into this error when trying the controller from gii. I have successfully ran the shown query from PDO on the command line. Any tips are appreciated!




12:05:39.590806  	error  	system.db.CDbCommand  	


Error in preparing SQL: SELECT COUNT(*) FROM 'abccode' 't'

in /usr/local/apache2/www/protected/views/abccode/index.php (17)

in /usr/local/apache2/www/protected/controllers/AbccodeController.php (133)

in /usr/local/apache2/www/index.php (13)


12:05:39.591568 	trace 	system.CModule 	


Loading "coreMessages" application component

in /usr/local/apache2/www/protected/views/abccode/index.php (17)

in /usr/local/apache2/www/protected/controllers/AbccodeController.php (133)

in /usr/local/apache2/www/index.php (13)


12:05:39.594029 	error 	system.db.CDbCommand 	


Error in querying SQL: SELECT COUNT(*) FROM 'abccode' 't'

in /usr/local/apache2/www/protected/views/abccode/index.php (17)

in /usr/local/apache2/www/protected/controllers/AbccodeController.php (133)

in /usr/local/apache2/www/index.php (13)


12:05:39.594507 	error 	exception.CDbException 	


exception 'CDbException' with message 'CDbCommand failed to execute the SQL

statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]:

General error: 0 [OpenLink][ODBC][Progress Server]** Unable to understand

after -- "DECLARE". (247) (SQLPrepare[0] at

/build/buildd/php5-5.3.3/ext/pdo_odbc/odbc_driver.c:206)' in

/usr/local/apache2/framework/db/CDbCommand.php:471

Stack trace:

#0 /usr/local/apache2/framework/db/CDbCommand.php(391):

CDbCommand->queryInternal('fetchColumn', 0, Array)

#1 /usr/local/apache2/framework/db/ar/CActiveRecord.php(1453):

CDbCommand->queryScalar()

#2 /usr/local/apache2/framework/web/CActiveDataProvider.php(162):

CActiveRecord->count(Object(CDbCriteria))

#3 /usr/local/apache2/framework/web/CDataProvider.php(184):

CActiveDataProvider->calculateTotalItemCount()

#4 /usr/local/apache2/framework/web/CActiveDataProvider.php(120):

CDataProvider->getTotalItemCount()

#5 /usr/local/apache2/framework/web/CDataProvider.php(128):

CActiveDataProvider->fetchData()

#6 /usr/local/apache2/framework/zii/widgets/CBaseListView.php(105):

CDataProvider->getData()

#7 /usr/local/apache2/framework/zii/widgets/CListView.php(156):

CBaseListView->init()

#8 /usr/local/apache2/framework/web/CBaseController.php(140):

CListView->init()

#9 /usr/local/apache2/framework/web/CBaseController.php(165):

CBaseController->createWidget('zii.widgets.CLi...', Array)

#10 /usr/local/apache2/www/protected/views/abccode/index.php(17):

CBaseController->widget('zii.widgets.CLi...', Array)

#11 /usr/local/apache2/framework/web/CBaseController.php(119):

require('/usr/local/apac...')

#12 /usr/local/apache2/framework/web/CBaseController.php(88):

CBaseController->renderInternal('/usr/local/apac...', Array, true)

#13 /usr/local/apache2/framework/web/CController.php(833):

CBaseController->renderFile('/usr/local/apac...', Array, true)

#14 /usr/local/apache2/framework/web/CController.php(746):

CController->renderPartial('index', Array, true)

#15

/usr/local/apache2/www/protected/controllers/AbccodeController.php(133):

CController->render('index', Array)

#16 /usr/local/apache2/framework/web/actions/CInlineAction.php(57):

AbccodeController->actionIndex()

#17 /usr/local/apache2/framework/web/CController.php(300):

CInlineAction->run()

#18 /usr/local/apache2/framework/web/filters/CFilterChain.php(133):

CController->runAction(Object(CInlineAction))

#19 /usr/local/apache2/framework/web/filters/CFilter.php(41):

CFilterChain->run()

#20 /usr/local/apache2/framework/web/CController.php(1088):

CFilter->filter(Object(CFilterChain))

#21 /usr/local/apache2/framework/web/filters/CInlineFilter.php(59):

CController->filterAccessControl(Object(CFilterChain))

#22 /usr/local/apache2/framework/web/filters/CFilterChain.php(130):

CInlineFilter->filter(Object(CFilterChain))

#23 /usr/local/apache2/framework/web/CController.php(283):

CFilterChain->run()

#24 /usr/local/apache2/framework/web/CController.php(257):

CController->runActionWithFilters(Object(CInlineAction), Array)

#25 /usr/local/apache2/framework/web/CWebApplication.php(328):

CController->run('')

#26 /usr/local/apache2/framework/web/CWebApplication.php(121):

CWebApplication->runController('abccode')

#27 /usr/local/apache2/framework/base/CApplication.php(155):

CWebApplication->processRequest()

#28 /usr/local/apache2/www/index.php(13): CApplication->run()

#29 {main} REQUEST_URI=/index.php/abccode


12:05:39.594753 	trace 	system.CModule 	


Loading "errorHandler" application component



Please post the actual code you’re using to create the query - though perhaps some may be able to figure this out from the error, the code is necessary to be comprehensive.

I’m sure what it was running at this point. I generated the model, then generated CRUD. After you generate CRUD there is a link to “try it out” or something like that. I ran that link and that is the error that happens. I assume the error is from this code shown in the error log… Error in querying SQL: SELECT COUNT(*) FROM ‘abccode’ ‘t’.