When do a PREPARE QUERY fails in PRO C?

旧街凉风 提交于 2019-12-12 04:26:00

问题


When do a PREPARE QUERY fails in PRO C?

EXEC SQL AT :db_id PREPARE QUERY FROM :sql_query;

bool sql_status = (sqlca.sqlcode == OERR_ORACLE_SUCCESS);

if (sql_status)
{
}
else
{
}

I don't have this problem until recently, The code was working fine the PREPARE QUERY is working fine (going into if loop_, but all of a sudden it failed, and is not working after that (going into else loop).

Nothing has changed and it's the same binary.

Does anybody face a similar problem in the past?


回答1:


I've written a LOT of pro*c in the past, and over time realized that you don't want to be checking the return code of the PREPARE statement as it never returns any value. Here is what I mean:

The PREPARE sqlca.sqlcode value is the return code of the statement that ran immediately BEFORE the PREPARE statement. In other words, if you check the output of the PREPARE statement and the statement that executed right before the PREPARE statement fails, then the return code of the prepare is failed. If the previous statement succeeded, then the PREPARE appears to have succeeded.

In other words, the prepare sqlca.sqlcode value is basically nothing (it doesn't ever fail on its own). So if the PREPARE is now failing, check the statement that executed right before the PREPARE statement and ensure you're checking the sqlca.sqlcode value of that one. My bet is that the previous statement is failing, and the error returned relates to that statement. Make sense?

-Jim



来源:https://stackoverflow.com/questions/40043605/when-do-a-prepare-query-fails-in-pro-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!