I'm having trouble catching SQL state codes in my program. I need to
catch the code "02000" (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, even after a
successfl fetch. 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! Since
Tom Hanks is in my database, the above code works. But if I change
'Tom Hanks' to a non-exisent actor, say 'Tommy Hanks', then it
SQLSTATE should be 02000 and my program should print "No movies found
for that actor.", but that doesn't happen since SQLSTATE is empty.
What am I doing wrong? Thanks.

Rob