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

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
docH
Posts: 59
Joined: Sun 22 Dec 2013 15:18

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

Post by docH » Thu 08 Jan 2015 09:00

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.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

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

Post by ViktorV » Thu 08 Jan 2015 12:17

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.

docH
Posts: 59
Joined: Sun 22 Dec 2013 15:18

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

Post by docH » Thu 08 Jan 2015 12:42

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?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

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

Post by ViktorV » Thu 08 Jan 2015 14:11

If the TMyQuery.ReadOnly property is set to True, then on an attempt to modify a record, its update query won't be used.

docH
Posts: 59
Joined: Sun 22 Dec 2013 15:18

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

Post by docH » Thu 08 Jan 2015 19:41

OK, thank you for the advice.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

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

Post by ViktorV » Fri 09 Jan 2015 07:50

Thank you for your interest to our product. Feel free to contact us if you have any further questions about MyDAC.

Post Reply