execSql certified execution

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
daniele
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 13.03.2009, 10:01

execSql certified execution

Post 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 ?
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post 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
daniele
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 13.03.2009, 10:01

Post 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... ?
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post 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.
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
daniele
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 13.03.2009, 10:01

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
daniele
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 13.03.2009, 10:01

Post by daniele »

Thanks Mark, I understand. Try to check the correctness of the run sql before and still use the Connection.ExecuteDirect. Regards.
Post Reply