ctImpersonateTask
Used to cause a connection to impersonate another connection.
Declaration
NINT ctImpersonateTask(NINT mode, NINT taskid);
Type
ISAM function called from SQL
Description
The Thread Impersonate feature allows a connection to “impersonate” another existing connection. This is most useful for FairCom DB SQL connections that might wish to do some lower-level ISAM type of activity, such as quickly looking up a record in an uncommitted SQL transaction. The target connection must allow the ability to be impersonated.
Note: This function is not supported by the FairCom Server by default. It requires a custom build of the server available by special request.
mode is one of the following:
FairCom DB SQL supports a stored procedure used to easily enable impersonation of its current connection. The procedure is:
fc_set_impersonation(taskid)
Specify a taskid of zero to disable impersonation of the connection (the default). Specify a taskid of 1 to enable impersonation of the connection by any other connection. Specify a taskid greater than 1 to enable impersonation of the connection only by a connection having that specific task ID.
The ctSNAPSHOT (SnapShot, SnapShot) user snapshot report (opcode = ctPSSuser) will return the taskid for the current connection in the ctgums.slOWNR structure member. You can use other options to get the user snapshot output for other users. To get the taskid of the current user at the SQL level, call the fc_get_taskid() stored procedure.
Note: This feature is intended for calling ISAM related functions from within either another ISAM connection, or from a higher-level SQL connection. It is not a trivial task to call SQL-related features from a lower-level connection, and this usage is not recommended.
Return Values
Symbolic Constant |
Value |
Explanation |
---|---|---|
NO_ERROR |
0 |
Successfully created the sequence |
NSUP_ERR |
454 |
Service not supported. |
IMPD_ERR |
863 |
The request to impersonate the specified connection was denied because the target connection does not allow impersonation |
IMPU_ERR |
864 |
The request to impersonate the specified connection was denied because the target connection does not allow impersonation by the specified connection. |
IMPA_ERR |
865 |
The request to impersonate the specified connection was denied because the target connection is already being impersonated. |
IMPB_ERR |
866 |
The request to impersonate the specified connection was denied because the target connection is executing a database operation or is blocked. |
See FairCom DB Error Codes for a complete listing of valid error values.
Example
REGCTREE("inst1");
if ((rc = INTISAMX(6, /* index buffers */
10, /* files */
4, /* page sectors */
6, /* data file buffers */
usrprf, /* UserProfile*/
uid, /* user id */
upw, /* user password */
svn))) { /* server name */
ctrt_printf("Error: Failed to connect to c-tree Server %s instance #1: %d\n", svn, rc);
goto err_ret;
}
<< get taskid1 >>
REGCTREE("inst2");
if ((rc = INTISAMX(6, /* index buffers */
500, /* files */
4, /* page sectors */
6, /* data file buffers */
usrprf, /* UserProfile*/
uid, /* user id */
upw, /* user password */
svn))) { /* server name */
ctrt_printf("Error: Failed to connect to c-tree Server %s instance #2: %d\n", svn, rc);
goto err_ret;
}
<< get taskid2 >>
SWTCTREE("inst1");
if ((rc = ctImpersonateTask(ctIMPallow, taskid2))) {
printf("Error: Failed to enable impersonation: %d\n", rc);
goto err_ret;
}
printf("Successfully enabled impersonation.\n");
<< open file and add record >>
SWTCTREE("inst2");
if ((rc = ctImpersonateTask(ctIMPbegin, taskid1))) {
printf("Error: Failed to begin impersonation: %d\n", rc);
goto err_ret;
}
printf("Successfully impersonated first connection.\n");
<< open file and read record from taskid1 >>
if ((rc = ctImpersonateTask(ctIMPend, 0))) {
qa_printf("Error: Failed to stop impersonation: %d\n", rc);
}