[m-rev.] for review: changes to odbc.m

Simon Taylor stayl at cs.mu.OZ.AU
Thu May 9 15:40:21 AEST 2002


On 09-May-2002, David Overton <dmo at cs.mu.OZ.AU> wrote:
> These changes are for Simon to review, please.
> 
> The motivation behind them is that there are some people in the
> Biochemistry department here at Monash who want to be able to perform IO
> in the middle of transactions.  E.g. they have queries which return many
> solutions which should be output to a file as they are returned.  The
> number of solutions is typically too big to store them all in a list and
> then do the output after the transaction finishes.
> 
> Is this a reasonable approach for such situations, or is there a better
> way?

That approach is fine.
 
> Index: odbc.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/extras/odbc/odbc.m,v
> retrieving revision 1.15
> diff -u -r1.15 odbc.m
> --- odbc.m	19 Apr 2002 02:51:57 -0000	1.15
> +++ odbc.m	9 May 2002 02:18:47 -0000
> @@ -76,6 +76,14 @@
>  :- type odbc__transaction(T)	== 	pred(T, odbc__state, odbc__state).
>  :- mode odbc__transaction	::	pred(out, di, uo) is det.
>  
> +		% A closure that allows IO operations.
> +		% See the WARNING at the predicate odbc__unsafe_io_transaction,
> +		% below.
> +:- type odbc__unsafe_io_transaction(T)	==
> +		pred(T, io__state, io__state, odbc__state, odbc__state).
> +:- mode odbc__unsafe_io_transaction ==
> +		(pred(out, di, uo, di, uo) is det).
> +
>  :- type odbc__state.
>  
>  	% odbc__transaction(Source, UserName, Password, Transaction, Result).
> @@ -96,6 +104,15 @@
>  		odbc__transaction(T), odbc__result(T), io__state, io__state).
>  :- mode odbc__transaction(in, in, in, odbc__transaction, out, di, uo) is det.
>  
> +	% Same as odbc__transaction except allow the transaction to operate on
> +	% the io__state.
> +	% WARNING: This is unsafe.
> +:- pred odbc__unsafe_io_transaction(odbc__data_source, odbc__user_name,
> +		odbc__password, odbc__unsafe_io_transaction(T),
> +		odbc__result(T), io__state, io__state).
> +:- mode odbc__unsafe_io_transaction(in, in, in, odbc__unsafe_io_transaction,
> +		out, di, uo) is det.

The warning here is a bit weak.

Maybe something like:
	% odbc__unsafe_io_transaction is useful when a transaction
	% returns more results than can be stored in memory.
	%
	% WARNING: transactions run by odbc__unsafe_io_transaction
	% may violate the atomicity and isolation properties expected
	% of ACID transactions.  Database updates will be rolled back
	% if the transaction is aborted, but I/O actions will not be.

Now that transactions can have access to an io__state, you need
to check that you're not already inside a transaction before
starting a new one (and return an error if you are).

Simon.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list