Page 1 of 1

execSql certified execution

Posted: 14.03.2009, 09:18
by daniele
Hi, i've a problem. How to verifying result of execSql procedure of TZQuery ?

If execSql failed no result of execution o error show. Another tecnique is necessary ?

Posted: 14.03.2009, 11:34
by seawolf
It depends on what are your purposes.

I mean .. if your query is ok, you can verify with RowAffected how many row are changed .. So if rowafected = 0 your query does not match any record.

But if the query contains error (i.e. parameters not correct) I think it is correct that Zeos raise an exception

Posted: 16.03.2009, 08:35
by daniele
Ok, thank's. About this, i must intercept exception of execSql procedure. How do this on insert and update query ?

The object TZUpdate is best method for execution update or execSql of TZquery have the same efficiency... ?

Posted: 17.03.2009, 12:36
by gto
You can always use the ExecuteDirect method from TZConnection, which will not raize any errors, but have a boolean return, which will be false if anything goes wrong.

Posted: 19.04.2009, 07:14
by daniele
Sorry but this is not sufficient. Assume that sql is formally correct but a parameter is 'P' and not '24:00:00' and field time1 and time2 is TIME types. In this case the sql is execute without any error:

update prodotti set time1='p', time2='24:00:00'

time1 and time2 is updates too but this is an error the parameter time1 in input is formally incorrent. Ok I need intercept this exception. Help

Posted: 19.04.2009, 20:53
by mdaems
daniele,

Problem is we don't know anything about what you are trying to do. An on what database.
Some comments
- When you try to update a TZQuery resultset by using the query's append or edit methods most severe datatype erros should be catched when you enter the data. I don't believe a dataset accepts a 'P' in a datetime column. This is the only place where zeoslb cares (a bit) about the data you enter in a database. We do this by parsing your select statement and decide what datatypes all columns have. When you afterwards update the resultset some checking will be done.
- When you provide an insert/updat/delete statement it's YOUR responsibility as a programmer to check if the provided sql/parameters are logically correct. So if you enter a string as a datetime value and your database server doesn't complain with an error, there's no reason zeoslib should complain. We don't parse your sql for an update statement. In this case I believe you best use Connection.ExecuteDirect as gto proposes. There ZQuery.execSQL may have a little more overhead.
- TZUpdateSQL is not a component you use independent from a TZQuery. t's a helper component when you want to edit a resultset that originates from a complex sql statement involving joins. It's a completely different use case.

Mark

Posted: 20.04.2009, 08:19
by daniele
Thanks Mark, I understand. Try to check the correctness of the run sql before and still use the Connection.ExecuteDirect. Regards.