Initial Release 4.5

Function : Database
NSFDbGetUserActivity - Return the database user activity summary information.
----------------------------------------------------------------------------------------------------------

#include <nsfdb.h>

STATUS LNPUBLIC NSFDbGetUserActivity(
DBHANDLE hDB,
DWORD Flags,
DBACTIVITY far *retDbActivity,
DHANDLE far *rethUserInfo,
WORD far *retUserCount);

Description :

This function returns the database user activity summary information. The total of the usage statistics for the prior day, week, and month, and since user activity recording began is returned in the retDbActivity structure. The number of documents a user or server read or wrote during each session, with the most recent activity first is returned in an array of DBACTIVITY_ENTRY structures. The array of DBACTIVITY_ENTRY structures is followed by a parallel array of NULL- terminated user name strings.
Parameters :

Sample Usage :

  /* Get the database activity summary.  The database has already been opened. */
{
  DBACTIVITY DbSummaryActivity;
  DBACTIVITY_ENTRY  *pDbUserActivity, DbUserActivity;
  DHANDLE hDbUserActivity;
  WORD wUserCount;
  char *szUserName;
  LONG lRptPeriod;


   error = NSFDbGetUserActivity (db_handle, 0L, &DbSummaryActivity,
                                &hDbUserActivity, &wUserCount);
  if (error)
  {
     NSFDbClose (db_handle);
     LAPI_RETURN (ERR(error));
  }


  /* Obtain a pointer to the first structure in an array of
    DBACTIVITY_ENTRY structures.  The user names follow the array */


  pDbUserActivity = OSLock (DBACTIVITY_ENTRY, hDbUserActivity);
 for (i = 0; i < wUserCount; i++)

  {
   DbUserActivity = pDbUserActivity[i];
   error = ConvertTIMEDATEToText (NULL, NULL, &(DbUserActivity.Time),
                                szTimedate, MAXALPHATIMEDATE, &wLen);
   if (error)
   {
     OSUnlock (hDbUserActivity);
     OSMemFree (hDbUserActivity);
     NSFDbClose (db_handle);
     LAPI_RETURN (ERR(error));
   }


    szTimedate[wLen] = '\0';
   szUserName = NSFDbGetActivityUserNamePtr (pDbUserActivity, i);
   /* print out DBACTIVITY_ENTRY Info */
   if (DbUserActivity.Reads)
      printf ("%s  %s read %d\n", szTimedate, szUserName,
              DbUserActivity.Reads);
   if (DbUserActivity.Writes)
      printf ("%s  %s wrote %d\n", szTimedate, szUserName,
              DbUserActivity.Writes);


  }

  OSUnlock (hDbUserActivity);
 OSMemFree (hDbUserActivity);
 /* Now print the DBACTIVITY summary info */
 printf ("\n\n");
 printf ("                 Uses         Reads        Writes\n");
 printf("Last Day        %5d         %5d         %5d\n",
         DbSummaryActivity.PrevDayUses,DbSummaryActivity.PrevDayReads,
         DbSummaryActivity.PrevDayWrites);
 printf("Last Week       %5d         %5d         %5d\n",
         DbSummaryActivity.PrevWeekUses,DbSummaryActivity.PrevWeekReads,
         DbSummaryActivity.PrevWeekWrites);
 printf("Last Month      %5d         %5d         %5d\n",
         DbSummaryActivity.PrevMonthUses,DbSummaryActivity.PrevMonthReads,
         DbSummaryActivity.PrevMonthWrites);
 lRptPeriod = TimeDateDifference (&(DbSummaryActivity.Last),
                                  &(DbSummaryActivity.First));
 /* Convert from seconds to days */
 if (lRptPeriod % (60*60*24))
   lRptPeriod = lRptPeriod / (60*60*24) + 1;
 else

    lRptPeriod = lRptPeriod / (60*60*24);

  printf("Last %lu days   %5d         %5d         %5d\n", lRptPeriod,
         DbSummaryActivity.Uses,DbSummaryActivity.Reads,
         DbSummaryActivity.Writes);


/* close the database when done. */

See Also :

DBACTIVITY
----------------------------------------------------------------------------------------------------------