If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > pro*c bind variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-04, 11:37
clockworks clockworks is offline
Registered User
 
Join Date: Apr 2004
Location: Austin, TX
Posts: 6
pro*c bind variables

i'm required to optimize some previously written pro*c code. i'm new to pro*c, but very fluent in c. this segment kinda confuses me:

Code:
int my_int = 0;
EXEC SQL DECLARE my_cursor FOR
SELECT *
FROM my_table
WHERE my_col = :my_int;

if (blah)
	my_int = 1;

EXEC SQL OPEN my_cursor;
EXEC SQL FETCH my_cursor into :blahblah;
notice that my_int is conditionally assigned <after> it is used in the my_cursor declaration. if blah is true, will it affect results of the fetch?

thanks for the help.
Reply With Quote
  #2 (permalink)  
Old 05-04-04, 18:43
avleyva avleyva is offline
Registered User
 
Join Date: Mar 2004
Posts: 8
Wink

No, you can put any value into the variables and every time you use the FETCH statement it will be changed to the database field value, ie:

int i;

i = 10; /* i value is 10 */

cursor declaration...
cursor open...

for (;
{
if (SQLCODE)
break;

fetch cursor into :i; /* it changes i to the field dabase value */
printf("%d", i); /* print the value of the database field */

i = 11; /* now i = 11 */
printf("%d", i); /* print 11 */
}

close cursor...
free cursor...

I hope this help you.
Reply With Quote
  #3 (permalink)  
Old 05-06-04, 11:07
clockworks clockworks is offline
Registered User
 
Join Date: Apr 2004
Location: Austin, TX
Posts: 6
i am afriad you completely misunderstood my question.

please review the code i posted. notice at the time of the "declare cursor" statement, my_int is 0. but at the time of the "open" and "fetch" statements, my_int could be 1. will this affect the results of the fetch?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On