If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
In general its good to look through all these macros. Chances are that you will need them at one time or other to interact with the database or application objects.
Furthermore, if there is an error while executing the SQL statement with sc_exec_sql, it will automatically rollback. But if you want to check that the changes to the database are as expected, you can use a, b and c above. After the sc_exec_sql, you can perform some selects against the database to see if the result is as planned and then either commit or rollback.
Yes, that is very relevant. I have only had success with my action queries and thus I assumed that if anything went wrong, an exception would be thrown that I could catch in try-catch structure. But that is not the case then.
Another way of dealing with it, is to just use regular PDO (PHP Data Objects) separate from ScriptCase, so you can have better control. I did this for a PHP class, which I made for reading and creating settings in the database. Through the Database Variables that ScriptCase provides, one can get the connection, username and password of the existing ScriptCase database connection and use them for creating a separate PDO connection like this:
Well, if you read the forum thread that jsbinca referred to above (http://www.scriptcase.net/forum/show...action-control), you can see that there is no certain way to know if sc_exec_sql succeeds. That is why a change was suggested that sc_exec_sql should return number of records affected. However, that change has not been done, so you have the following options:
a. Use the sc_select as suggest by jsbinca in the forum thread referenced above.
b. Use a separate PDO connection as I suggested
c. Manually check if your query has succeeded by using a sc_lookup or sc_select after the sc_exec_sql:
iii. sc_lookup or sc_select to see if changes were done in the database
iv. based on the above use sc_commit_trans or sc_rollback_trans to either commit or rollback.
So, if you wish to stay with sc macros (solution b or c), you have to study a bit on them to put your code properly together.
For solution a you have to study the PDO (PHP Data Objects).