In a message dated 12/8/2001 1:17:17 AM Eastern Standard Time,
[EMAIL PROTECTED] writes:


> When calling Ns_TclEnterSet, I'm confused about how to choose between
> NS_TCL_SET_TEMPORARY (0) and NS_TCL_SET_DYNAMIC (1).
>
> When I look at NsTclDbCmd (in dbtcl.c, AOLserver 3.3+ad13), I see that
> it uses NS_TCL_SET_TEMPORARY in Ns_Db0or1Row, but NS_TCL_SET_DYNAMIC
> in Ns_DbSelect.  This seems CORRECT, because Ns_Db0or1Row calls
> Ns_DbSelect and then creates a new ns_set with Ns_SetCopy, while
> Ns_DbSelect simply returns a pointer to the Ns_set that's part of the
> database Handle struct.
>
> What I don't understand is WHY it's done that way.  Why does
> Ns_Db0or1Row create a new ns_set, while Ns_DbSelect doesn't?  Does it
> have something to do with whether or not we're returning actual rows
> to Tcl?
>



You're confused because the names I chose long ago were stupid and confusing
(sorry).  AOLserver 4.0 attempts to clarify the meanings with new constants.
 Here's a snippet from the 4.0 ns.h which describes:


/*
 * The following flags define how Ns_Set's
 * are managed by Tcl:
 *
 * NS_TCL_SET_STATIC:   Underlying Ns_Set managed
 *                      elsewhere, only maintain a
 *                      Tcl reference.
 *
 * NS_TCL_SET_DYNAMIC:  Ownership of Ns_Set is given
 *                      entirely to Tcl, free the set
 *                      when no longer referenced in Tcl.
 *
 * In addition, the NS_TCL_SET_SHARED flag can be set
 * to make the set available to all interps.
 */

#define NS_TCL_SET_STATIC         0
#define NS_TCL_SET_DYNAMIC        1
#define NS_TCL_SET_SHARED         2

/*
 * Backwards compatible (and confusing) names.
 */

#define NS_TCL_SET_PERSISTENT     NS_TCL_SET_SHARED
#define NS_TCL_SET_TEMPORARY      NS_TCL_SET_STATIC



So, just NS_TCL_SET_DYNAMIC means owned/freed by AOLserver Tcl and
NS_TCL_SET_TEMPORARY means just leave a pointer to set maintained elsewhere,
e.g., in the Ns_DbHandle for an open database.

Now, why the Ns_DbHandle maintains the Ns_Set is to be a bit more efficient.
When rows are bound, the keys (column names) are set, leaving values null.
As rows are fetched, the values are updated, leaving keys in place.  The idea
behind Ns_Db1Row was to return a copy so you could hold onto the result while
you do another Ns_Db1Row (Ns_Db0or1Row).  Perhaps that was a bad idea because
folks could have made copies if they wanted - hmm, live and learn.

-Jim

Reply via email to