I'm having some experience with C embedded SQL and what I can see at first sight is 1) DECLARE CURSOR statement - missing colon: EXEC SQL DECLARE C77 CURSOR FOR select datname from pg_user,pg_database where usename= :user and datdba= :usesysid; 2) before OPEN you have to declare and set the where clause variables: user and usesysid are not declared nor set 3) VARCHAR base[50]: is probably not the right type, because VARCHAR always uses a 4 byte header to determine the length, whereas the name type is of 32 byte fixed length. A simple char name[32] should do it.
If the problem persists, you should inspect the sqlca structure after every step of EXEC SQL execution for more information on what's going wrong. By the way, I'm porting an application to PostgreSQL and I have decided to get rid off embedded SQL completely, because I feel much more comfortable with the functions the libpq - C Library package is providing. Especially, you never again have to worry about data types, because the PQgetvalue function retrieves everything as string. Regards, Christoph > > #include<string.h> > EXEC SQL BEGIN DECLARE SECTION; > VARCHAR base[50]; > EXEC SQL END DECLARE SECTION; > EXEC SQL INCLUDE sqlca; > EXEC SQL DECLARE C77 CURSOR FOR select datname from pg_user,pg_database > where usename= :user and datdba=usesysid; > main () > { > EXEC SQL CONNECT TO mybase; > if(sqlca.sqlcode < 0) > { > printf(" error"); > exit(1); > } > // now I want to get results > EXEC SQL OPEN C77; > EXEC SQL FETCH IN C77 INTO :base; // here, it's the problem, I can't to > get the result on the base variable. I think that can be the variable > type. then how should be the data type for ":base" variable? ........ > ....... > ....... > ..... > ... > . > . > . > . > pg_database has the attributes as follow: > > mybase=> \d pg_database > Table "pg_database" > Attribute | Type | Modifier > -----------+---------+---------- > datname | name | --->I can't to get the "datname"......why? > datdba | integer | > encoding | integer | > datpath | text | > ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster