Page 1 of 1

An event to cancel a SQL statement before it is run?

Posted: Thu 08 Jan 2015 09:00
by docH
I'm using the MYDac components with great success in a Delphi application pointing at a MySQL database. I have a TMyConnection, TMyQuery and a TMyCommand on a data access form that I use at loads of different points to reach the db.

I want to be able to give my users a 'demo' mode of operation where they can read from the database but not make any changes to it. I thought about going through evey form I have and conditionally skipping over any TMyQuery or TMyCommand lines that might write to the db but was worried I would miss some.

Is there an event or some other mechanism that I could use centrally on the TMyQuery and TMyCommand components on the data access page that makes them only read only or in some other way simply ignores any write or modification requests? (Without generating errors when attempting to execute modifying sql of course)

If so, can anyone give me a code snippet to illustrate how to use it.

Re: An event to cancel a SQL statement before it is run?

Posted: Thu 08 Jan 2015 12:17
by ViktorV
To deny modification or inserting records in a dataset, you can set the TMyQuery.ReadOnly property to True. More details are available by the link: http://www.devart.com/mydac/docs/devart ... adonly.htm
You can use the TMyCommand.BeforeExecute and TMyCommand.AfterExecute event handlers for processing SQL queries and retrieving the needed information.

Re: An event to cancel a SQL statement before it is run?

Posted: Thu 08 Jan 2015 12:42
by docH
Thank you. Will that work without generating errors?
ie if I have a TMyQuery containing an update query and I set ReadOnly to true and open the query will it just ignore the sql or will it generate an error because it's read only?

Re: An event to cancel a SQL statement before it is run?

Posted: Thu 08 Jan 2015 14:11
by ViktorV
If the TMyQuery.ReadOnly property is set to True, then on an attempt to modify a record, its update query won't be used.

Re: An event to cancel a SQL statement before it is run?

Posted: Thu 08 Jan 2015 19:41
by docH
OK, thank you for the advice.

Re: An event to cancel a SQL statement before it is run?

Posted: Fri 09 Jan 2015 07:50
by ViktorV
Thank you for your interest to our product. Feel free to contact us if you have any further questions about MyDAC.