Getting session and database information
The following code from an external application illustrates some of the Session and DatabaseDesc methods. You need a session object to connect to the database. The session object allows you to get information about the database (such as the SQL connect string) and the user that is currently logged on. There are three steps to the process:
- Create the session object.
- Log on to the database.
- Do the tasks you want to do.
For more information, see the Session Object and the DatabaseDesc Object.
The following code prints out the information stored
in the Session's DatabaseDesc object, as well as all the user-related
information. This subroutine makes use of another routine called StdOut,
which prints its arguments to a message box.
Perl
use lib "E:\\Program Files\\HCL\\common\\lib";
use CQPerlExt;
$CQsession = CQSession::Build();
$CQsession->UserLogon("admin", "", "perl2", "");
$dbDesc = $CQsession->GetSessionDatabase();
print "DB name = ", $dbDesc->GetDatabaseName(), "\n";
print "DB set name = ", $dbDesc->GetDatabaseSetName(), "\n";
print "DB connect string = ", $dbDesc->GetDatabaseConnectString(), "\n";
print "User login name = ", $CQsession->GetUserLoginName(), "\n";
print "User full name = ", $CQsession->GetUserFullName(), "\n";
print "User email = ", $CQsession->GetUserEmail(), "\n";
print "User phone = ", $CQsession->GetUserPhone(), "\n";
print "Misc user info = ", $CQsession->GetUserMiscInfo(), "\n";
print "User groups: \n";
$userGroups = $CQsession->GetUserGroups();
if (!@$userGroups) {
#Code to handle if no user groups exist
print "This user does not belong to any groups\n";
}
else {
# print out all groups
foreach $groupname (@$userGroups) {
print "Group $groupname\n";
}
}
CQSession::Unbuild($CQsession);