🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #426

Re: Is this safe?

#426
From: Dan K
Date: Fri, 07 Mar 2008 23:44
68 lines
3158 bytes
Thanks for the reply.  This is a one time "flip", so I was hoping to make it
simple.  The stored procedure is a good way to go, even if I drop it after
I'm done.  Better safe than sorry!

Thanks,

Dan

"Wayne Niddery (TeamB)" <wniddery@chaffaci.on.ca> wrote in message
news:47d1cc21$1@newsgroups.borland.com...
> "Dan K" <koodanospam@icsusa.com> wrote in message
> news:47d18e36$1@newsgroups.borland.com...
> >
> > I need to write some SQL to flip the values in a table or two.  Here's
an
> > example of what I want to do.  It works, but I'm not sure if it's safe.
> > All
> > of our users are using Interbase 7.1.  In my example, I'm flipping tax2
> > with
> > tax1 and using tax3 as a placeholder.  I know that tax 3 is null, so
that
> > part is safe.  Will the order of operation always be the same?
> >
> > update taxes set
> >  tax_tax3desc = tax_tax1desc,
> >  tax_tax1desc = tax_tax2desc,
> >  tax_tax2desc = tax_tax3desc,
> >  tax_tax3desc = null
> > where storenumber_Id = 3
> >
> > Strange looking, but it seems to work.
>
>
> It's *probably* safe, however SQL is not a procedural language and I'm not
> aware of anything in either the SQL standard or in InterBase that
guarantees
> a statement will executed as such. Therefore there is at least some risk
in
> depending on such behaviour.
>
> A much better idea would be to use a stored procedure for operations such
as
> this, and that has the added benefit of not needing a dummy field in the
> record definition to accomodate such operations. The exact process above
can
> be done in a proc as follows (not tested of course):
>
> create procedure SwapTaxes (
>   storeid integer
> )
> as
> declare variable tax1desc varchar(30); // whatever correct definition is
> declare variable tax2desc varchar(30); // whatever correct definition is
> begin
>   select tax_tax1desc, tax_tax2desc from taxes
>   where storenumber_Id = :storeid
>   into tax1desc, tax2desc;
>
>   update taxes set
>     tax_tax1desc = :tax2desc,
>     tax_tax2desc = :tax1desc
>   where storenumber_Id = :storeid;
> end;
>
> -- 
> Wayne Niddery - TeamB (www.teamb.com)
> Winwright, Inc. (www.winwright.ca)
>
Technical Details
Message-ID: <47d1d328@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <47d18e36$1@newsgroups.borland.com> <47d1cc21$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,fbab0f944ae6f5eb
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Dan K" <koodanospam@icsusa.com>
Newsgroups: borland.public.interbase.sql
References: <47d18e36$1@newsgroups.borland.com> <47d1cc21$1@newsgroups.borland.com>
Subject: Re: Is this safe?
Date: Fri, 7 Mar 2008 17:44:47 -0600
Lines: 70
Organization: ICS
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1914
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1914
NNTP-Posting-Host: 207.195.200.17
Message-ID: <47d1d328@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1204933416 207.195.200.17 (7 Mar 2008 15:43:36 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 3005