Can't select USER.
Posted in 2000
Topics: Installation, Setup & Upgrades, SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
I presume you want the user id for feedback to the user, or for recording
flat log file entries?
The database can store USER (see second example below). The USER variable
is (should be) available to SQL calls.
Have a look in /usr/include/limits.h for LOGNAME_MAX
These functions are searching for the user's login name (unique), not the
user's id (uid) which is a number (possibly shared). - Has Informix added a
4gl global or an SQL variable UID?
#######################
FUNCTION get_user()
DEFINE uid LIKE sysusers.username # Probably CHAR( 8 ) -
but could change
# DEFINE uid CHAR( 40 ) # 40 characters
should be more than adequate
LET uid = fgl_getenv( "LOGNAME" )
IF length( uid ) = 0 THEN
LET uid = fgl_getenv( "USER" )
END IF
RETURN uid
END FUNCTION
# You can try just returning straight from the environment - I think I
prefer the version above
# FUNCTION get_user()
# RETURN fgl_getenv( "LOGNAME" )
# END FUNCTION
#######################
LOGNAME should check the user's actual login name, USER their current name
(check that guys)
Alternatively ... (heavy - but not OS dependant)
#######################
DEFINE uid LIKE sysusers.username # Probably CHAR( 8 )
# note - outside of
function, - at head of module -
# therefore held
permanently in scope of whole module
# ...
FUNCTION get_user()
{ # un-comment for more portable version
DEFINE tmp_col_siz SMALLINT
txt CHAR( 160 ) # Over
kill on space - CHAR ( 80 ) probably sufficient
}
IF length( uid ) > 0 THEN # we already have it
RETURN uid
END IF
CREATE TEMP TABLE tmp_get_user
user_id CHAR ( 40 ) NOT null # big enough to
hold any future resize
)
{ # un-comment for more portable version than hard coding user_id
size above .... but
SELECT syscolumns.collength INTO tmp_col_siz
FROM syscolumns, systables
WHERE systables.tabname = "sysusers"
AND syscolumns.tabid = systables.tabid
AND colname = "username"
LET txt =
"CREATE TEMP TABLE tmp_get_user ( ",
"tmp_get_user.user_id CHAR ( ", tmp_col_siz, " )
NOT null",
")"
PREPARE pget_user FROM txt
EXECUTE pget_user
FREE pget_user
}
INSERT INTO tmp_get_user VALUES ( USER )
SELECT tmp_get_user.user_id INTO uid
DROP TABLE tmp_get_user
RETURN uid
END FUNCTION
# ...
#######################
"Kevin Golding" <kgolding@webcom.com.au> wrote in message
news:39AEAD64.E6D37190@webcom.com.au...
> I am trying to select the USER into a 4gl program, as in (example taken
> from Informix 4GL reference manual) ....
> function get_user()
> define uid like sysusers.username
> select USER into uid from systables
> where tabname = "systables"
> return uid
> end function
>
> But the select statement falls over with the error ...
> 4GL run-time error number -9971
> Cannot determine the return types of a query or return types are
> inconsistent.
>
> The code used to run on ver. 4.13.UD3 of the 4GL RDS, but now that we
> have upgraded to 7.30.UC1, it no longer runs.
> Has anybody else experienced the same problem?
> Does anybody have a workaround?
>
> I am running 4GL RDS 7.30.UC1 with Dynamic Server 2000 9.20 on RedHat
> 6.2
>
> Thanks
> Kevin
>
I am trying to select the USER into a 4gl program, as in (example taken from Informix 4GL reference manual) .... function get_user() define uid like sysusers.username select USER into uid from systables where tabname = "systables" return uid end function But the select statement falls over with the error ... 4GL run-time error number -9971 Cannot determine the return types of a query or return types are inconsistent. The code used to run on ver. 4.13.UD3 of the 4GL RDS, but now that we have upgraded to 7.30.UC1, it no longer runs. Has anybody else experienced the same problem? Does anybody have a workaround? I am running 4GL RDS 7.30.UC1 with Dynamic Server 2000 9.20 on RedHat 6.2 Thanks Kevin