R
Rob
I'm not sure if this is the right newsgroup for this question, but I
wasn't sure where else to post it. I'm having some trouble with SQL in
C.
I'm trying to catch sql state codes in my program. For example the
code "02000" means "no tuples found". I made an array SQLSTATE[6], but
I can't get these codes to go into the array. I'm not sure if I'm
missing something, or there's something I'm forgetting to #include,
because whenever I check SQLSTATE, it's empty. I have something like
this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE SECTION;
char movie_title[64];
short movie_year;
char SQLSTATE[6];
EXEC SQL END DECLARE SECTION;
int main() {
/* connect to database */
EXEC SQL DECLARE c1 CURSOR FOR
SELECT title, year
FROM Movies
WHERE Movies.actor = 'Tom Hanks';
EXEC SQL OPEN c1;
while(1) {
EXEC SQL FETCH c1 INTO :movie_title, :movie_year
if (strcmp(SQLSTATE, "02000") == 0) {
printf("No movies found for that actor.");
} else {
printf("title: %s, year: %d", movie_title, movie_year);
}
}
}
I thought SQLSTATE would automatically get the state codes, but that's
not happening. Not sure what I'm missing. Thanks for any help!
Rob
wasn't sure where else to post it. I'm having some trouble with SQL in
C.
I'm trying to catch sql state codes in my program. For example the
code "02000" means "no tuples found". I made an array SQLSTATE[6], but
I can't get these codes to go into the array. I'm not sure if I'm
missing something, or there's something I'm forgetting to #include,
because whenever I check SQLSTATE, it's empty. I have something like
this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
EXEC SQL INCLUDE sqlca;
EXEC SQL BEGIN DECLARE SECTION;
char movie_title[64];
short movie_year;
char SQLSTATE[6];
EXEC SQL END DECLARE SECTION;
int main() {
/* connect to database */
EXEC SQL DECLARE c1 CURSOR FOR
SELECT title, year
FROM Movies
WHERE Movies.actor = 'Tom Hanks';
EXEC SQL OPEN c1;
while(1) {
EXEC SQL FETCH c1 INTO :movie_title, :movie_year
if (strcmp(SQLSTATE, "02000") == 0) {
printf("No movies found for that actor.");
} else {
printf("title: %s, year: %d", movie_title, movie_year);
}
}
}
I thought SQLSTATE would automatically get the state codes, but that's
not happening. Not sure what I'm missing. Thanks for any help!
Rob