473,408 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

if exists in php with UDB Linux

I need to see if some rows exist, but do not need to read them. The best
I could come up with is:

$sql = "SELECT 1 FROM $schema.auction_owners
WHERE auction_id=$ai
AND item_id=$item_id
FETCH FIRST 1 ROW ONLY
FOR READ ONLY
";
dosql($sql, "S AO4", -1, "", $n2, $res2);
if(odbc_fetch_array($res)) {
....
}
Feb 27 '07 #1
8 3386
On Feb 27, 10:16 am, Bob Stearns <rstearns1...@charter.netwrote:
I need to see if some rows exist, but do not need to read them. The best
I could come up with is:

$sql = "SELECT 1 FROM $schema.auction_owners
WHERE auction_id=$ai
AND item_id=$item_id
FETCH FIRST 1 ROW ONLY
FOR READ ONLY
";
dosql($sql, "S AO4", -1, "", $n2, $res2);
if(odbc_fetch_array($res)) {
...

}- Hide quoted text -

- Show quoted text -
Your method certainly works. If you want to do something SQL-related
after you find if the rows exist or not, you may want to consider
using BEGIN ATOMIC:

BEGIN ATOMIC
IF ((SELECT 1 FROM X WHERE ... FETCH FIRST 1 ROW ONLY) = 1) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;

You could also combine your method with BEGIN ATOMIC, i.e.,

BEGIN ATOMIC
IF (NOT EXISTS(SELECT 1 FROM X WHERE ...)) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;
--Jeff

Feb 27 '07 #2
jefftyzzer wrote:
On Feb 27, 10:16 am, Bob Stearns <rstearns1...@charter.netwrote:
>>I need to see if some rows exist, but do not need to read them. The best
I could come up with is:

$sql = "SELECT 1 FROM $schema.auction_owners
WHERE auction_id=$ai
AND item_id=$item_id
FETCH FIRST 1 ROW ONLY
FOR READ ONLY
";
dosql($sql, "S AO4", -1, "", $n2, $res2);
if(odbc_fetch_array($res)) {
...

}- Hide quoted text -

- Show quoted text -


Your method certainly works. If you want to do something SQL-related
after you find if the rows exist or not, you may want to consider
using BEGIN ATOMIC:

BEGIN ATOMIC
IF ((SELECT 1 FROM X WHERE ... FETCH FIRST 1 ROW ONLY) = 1) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;

You could also combine your method with BEGIN ATOMIC, i.e.,

BEGIN ATOMIC
IF (NOT EXISTS(SELECT 1 FROM X WHERE ...)) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;
--Jeff
Thanks. I'm doing different things at the PHP level depending on the result.
Feb 27 '07 #3
Ray
On Feb 27, 12:48 pm, Bob Stearns <rstearns1...@charter.netwrote:
jefftyzzer wrote:
On Feb 27, 10:16 am, Bob Stearns <rstearns1...@charter.netwrote:
>I need to see if some rows exist, but do not need to read them. The best
I could come up with is:
>$sql = "SELECT 1 FROM $schema.auction_owners
WHERE auction_id=$ai
AND item_id=$item_id
FETCH FIRST 1 ROW ONLY
FOR READ ONLY
";
dosql($sql, "S AO4", -1, "", $n2, $res2);
if(odbc_fetch_array($res)) {
...
>}- Hide quoted text -
>- Show quoted text -
Your method certainly works. If you want to do something SQL-related
after you find if the rows exist or not, you may want to consider
using BEGIN ATOMIC:
BEGIN ATOMIC
IF ((SELECT 1 FROM X WHERE ... FETCH FIRST 1 ROW ONLY) = 1) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;
You could also combine your method with BEGIN ATOMIC, i.e.,
BEGIN ATOMIC
IF (NOT EXISTS(SELECT 1 FROM X WHERE ...)) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;
--Jeff

Thanks. I'm doing different things at the PHP level depending on the result.
Why not use SELECT COUNT (*) ?

Feb 28 '07 #4
On Feb 28, 7:23 am, "Ray" <raymmailbox-n...@yahoo.comwrote:
On Feb 27, 12:48 pm, Bob Stearns <rstearns1...@charter.netwrote:


jefftyzzer wrote:
On Feb 27, 10:16 am, Bob Stearns <rstearns1...@charter.netwrote:
>>I need to see if some rows exist, but do not need to read them. The best
>>I could come up with is:
>>$sql = "SELECT 1 FROM $schema.auction_owners
> WHERE auction_id=$ai
> AND item_id=$item_id
> FETCH FIRST 1 ROW ONLY
> FOR READ ONLY
> ";
>>dosql($sql, "S AO4", -1, "", $n2, $res2);
>>if(odbc_fetch_array($res)) {
>>...
>>}- Hide quoted text -
>>- Show quoted text -
Your method certainly works. If you want to do something SQL-related
after you find if the rows exist or not, you may want to consider
using BEGIN ATOMIC:
BEGIN ATOMIC
IF ((SELECT 1 FROM X WHERE ... FETCH FIRST 1 ROW ONLY) = 1) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;
You could also combine your method with BEGIN ATOMIC, i.e.,
BEGIN ATOMIC
IF (NOT EXISTS(SELECT 1 FROM X WHERE ...)) THEN
do something, e.g. SIGNAL, INSERT, etc. (but no
DDL)...
END IF;--
END;
--Jeff
Thanks. I'm doing different things at the PHP level depending on the result.

Why not use SELECT COUNT (*) ?- Hide quoted text -

- Show quoted text -
Please see the section titled "Tuning existential predicates" in the
following TinyURL link for an opinion on COUNT(*): http://tinyurl.com/2t3gac

--Jeff

Feb 28 '07 #5
Ray
On Feb 28, 12:40 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
Please see the section titled "Tuning existential predicates" in the
following TinyURL link for an opinion on COUNT(*):http://tinyurl.com/2t3gac
I agree that irrelevant existential tests are a waste of time but I
don't see where that's the case when the whole reason for the query is
simply to establish existence to control program flow at a later time.
That said, I'm sure I'm overlooking something obvious to the more
experienced so what am I missing?

Mar 1 '07 #6
On Mar 1, 7:23 am, "Ray" <raymmailbox-n...@yahoo.comwrote:
On Feb 28, 12:40 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
Please see the section titled "Tuning existential predicates" in the
following TinyURL link for an opinion on COUNT(*):http://tinyurl.com/2t3gac

I agree that irrelevant existential tests are a waste of time but I
don't see where that's the case when the whole reason for the query is
simply to establish existence to control program flow at a later time.
That said, I'm sure I'm overlooking something obvious to the more
experienced so what am I missing?
Hi, Ray.

I'm not saying you're missing anything. I think Serge's argument (the
author of the opinion I included) is that there's no sense counting up
a bunch of things only to throw this number away.

The better thing about EXISTS is that the minute a single row tests
true, the search stops, so there's the potential for a much faster
test.

Anyway, I think we're splitting hairs here. As in all things,
individual results will vary. Do what works :-)

Regards,

--Jeff

Mar 1 '07 #7
Ray
On Mar 1, 12:58 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
I'm not saying you're missing anything. I think Serge's argument (the
author of the opinion I included) is that there's no sense counting up
a bunch of things only to throw this number away.
Thanks, Jeff. In fact I WAS missing a couple of things. First was the
explicit optimization of the select, which I now understand.
The better thing about EXISTS is that the minute a single row tests
true, the search stops, so there's the potential for a much faster
test.
Does that mean that DB2 will actually short circuit the select in the
infocenter example for exists?

EXISTS (SELECT * FROM TEMPL WHERE SALARY < 10000)

Mar 1 '07 #8
On 1 Mar 2007 12:52:04 -0800, "Ray" <ra**************@yahoo.com>
wrote:
>On Mar 1, 12:58 pm, "jefftyzzer" <jefftyz...@sbcglobal.netwrote:
>I'm not saying you're missing anything. I think Serge's argument (the
author of the opinion I included) is that there's no sense counting up
a bunch of things only to throw this number away.

Thanks, Jeff. In fact I WAS missing a couple of things. First was the
explicit optimization of the select, which I now understand.
>The better thing about EXISTS is that the minute a single row tests
true, the search stops, so there's the potential for a much faster
test.

Does that mean that DB2 will actually short circuit the select in the
infocenter example for exists?

EXISTS (SELECT * FROM TEMPL WHERE SALARY < 10000)
I think it should. EXISTS (SELECT * is the classic example of
short-circuiting.

B.
Mar 1 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: John Roth | last post by:
I'm adding a thread for comments on Gerrit Holl's pre-pep, which can be found here: http://tinyurl.com/2578q Frankly, I like the idea. It's about time that all of the file and directory stuff...
3
by: newcomer | last post by:
Is there a way to check if a file exists in Javascript? This is what I'm trying to do: if(thisfile.htm exists) do this else do that
4
by: Pierre Quentel | last post by:
os.path.exists(path) returns True if "path" exists But on Windows it also returns True for "path" followed by any number of dots : Python 2.4 (#60, Nov 30 2004, 11:49:19) on win32 Type...
22
by: Robert Bralic | last post by:
CAN anybody tell me any address where I can download some small(1000-2000) lines C++ proghram source. Or send me ,a small(1000-2000) lines C++ program source that I can compille with gpp under...
15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
14
by: John Salerno | last post by:
What is the best way to check if a file already exists in the current directory? I saw os.path.isfile(), but I'm not sure if that does more than what I need. I just want to check if a file of a...
4
by: Karim | last post by:
Hi, I need to write some code to figure out if a file exists before I overwrite it. I came up with this code, but not sure its the best.. bool isImgCached; TFilePtr pCachedFile =...
6
by: Ming | last post by:
I want to know if some particular PEAR package (for example, DB, XML_RPC) exists. How can I do that in PHP? Thanks,
10
by: ganeshp | last post by:
Below given is the code to check if a file exists. This code works on Windows but on Linux it fails even when the file exists. Please let me know if you have a solution or a work around for this....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.