Re: Is this the sanctioned way to ascertain a table's existence?
From: Ramon F Herrera <ramon_at_conexus.net>
Date: Fri, 16 Oct 2009 17:03:52 -0700 (PDT)
Message-ID: <cc7c77a0-b4e1-4ce4-9af0-9ffb0b02e2e5_at_g31g2000yqc.googlegroups.com>
On Oct 16, 7:48 pm, Shakespeare <what..._at_xs4all.nl> wrote:
> Ramon F Herrera schreef:
>
>
>
> > All my database accesses are done through Pro*C/C++.
>
> > Sometimes my code needs to verify whether a table exists. Years ago, I
> > was about to post that particular questions here. I then realized
> > that the following statements achieve the desired results:
>
> > EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE
> > table_name = :table_name;
>
> > if (howMany == 1)
> > doThis();
> > else
> > doThat();
>
> > Is that "the" proper way?
>
> > -Ramon
>
> I always get a bit worried if an application has to check whether a
> table exists.... should they not be there just by design?
>
> Shakespeare
Date: Fri, 16 Oct 2009 17:03:52 -0700 (PDT)
Message-ID: <cc7c77a0-b4e1-4ce4-9af0-9ffb0b02e2e5_at_g31g2000yqc.googlegroups.com>
On Oct 16, 7:48 pm, Shakespeare <what..._at_xs4all.nl> wrote:
> Ramon F Herrera schreef:
>
>
>
> > All my database accesses are done through Pro*C/C++.
>
> > Sometimes my code needs to verify whether a table exists. Years ago, I
> > was about to post that particular questions here. I then realized
> > that the following statements achieve the desired results:
>
> > EXEC SQL SELECT COUNT(1) INTO :howMany FROM user_tables WHERE
> > table_name = :table_name;
>
> > if (howMany == 1)
> > doThis();
> > else
> > doThat();
>
> > Is that "the" proper way?
>
> > -Ramon
>
> I always get a bit worried if an application has to check whether a
> table exists.... should they not be there just by design?
>
> Shakespeare
Good point. The thing about my design is that I have "a table of tables". The code in question is for my internal use, and I type it from the Unix prompt. Let's say I have a bunch of company clients and the command in question tells me when was the last time such company made a payment or something.
For policy and other reasons I treat every company as a separate entity with their own tables. Some companies demand not to share table space with other companies.
Therefore the interaction would look like this:
% last_payment google
The program -after checking that a table named "google" does not exist- will retort:
"Are you kidding me, Ramon? `google' is not your client"
-RFH Received on Fri Oct 16 2009 - 19:03:52 CDT