Example #1
0
/* Open
 *  open cursor, resolving schema
 *  for the set of opened columns
 *
 *  NB - there is no corresponding "Close"
 *  use "Release" instead.
 */
rc_t VTableReadCursorOpen ( const VTableCursor *cself )
{
    rc_t rc;
    VTableCursor *self = ( VTableCursor* ) cself;

    if ( self == NULL )
        rc = RC ( rcVDB, rcCursor, rcOpening, rcSelf, rcNull );
    else
    {
        VLinker *ld = self -> tbl -> linker;

        KDlset *libs;
        rc = VLinkerOpen ( ld, & libs );
        if ( rc == 0 )
        {
            rc = VCursorOpenRead ( self, libs );
            if ( rc == 0 )
            {
                int64_t first;
                uint64_t count;

                rc = VCursorIdRange ( & self -> dad, 0, & first, & count );
                if ( rc != 0 )
                {
                    /* permit empty open when run from sradb */
                    if ( GetRCState ( rc ) == rcEmpty && GetRCObject ( rc ) == rcRange &&
                         self -> permit_add_column && VectorLength ( & self -> dad . row ) == 0 )
                    {
                        rc = 0;
                    }
                }
                else if ( count != 0 )
                {
                    /* set initial row id to starting row */
                    self -> dad . start_id =
                    self -> dad . end_id =
                    self -> dad . row_id = first;
                }

                if ( rc != 0 )
                    self -> dad . state = vcFailed;
            }

            KDlsetRelease ( libs );
        }
    }

    return rc;
}
Example #2
0
LIB_EXPORT rc_t CC VCursorOpen ( const VCursor *cself )
{
    rc_t rc;
    VCursor *self = ( VCursor* ) cself;

    if ( self == NULL )
        rc = RC ( rcVDB, rcCursor, rcOpening, rcSelf, rcNull );
    else
    {
        VLinker *ld = self -> tbl -> linker;

        KDlset *libs;
        rc = VLinkerOpen ( ld, & libs );
        if ( rc == 0 )
        {
            rc = VCursorOpenRead ( self, libs );
            if ( rc == 0 )
            {
                if ( ! self -> read_only )
                {
                    VProdResolve pr;
                    pr . schema = self -> schema;
                    pr . ld = ld;
                    pr . libs = libs;
                    pr . stbl = self -> stbl;
                    pr . curs = self;
                    pr . cache = & self -> prod;
                    pr . owned = & self -> owned;
                    pr . chain = chainEncoding;
                    pr . blobbing = false;
                    pr . ignore_column_errors = false;
                    pr . discover_writable_columns = false;

		    if ( !self -> suspend_triggers )
			    rc = VProdResolveAddTriggers ( & pr, self -> stbl );
                }
                if ( rc == 0 )
                {
                    /* TBD - warn if any input columns are unreferenced by schema */

                    int64_t first;
                    uint64_t count;
                    
                    rc = VCursorIdRange ( self, 0, & first, & count );
                    if ( rc != 0 )
                    {
                        if ( GetRCState ( rc ) == rcEmpty )
                        {
                            /* writable cursors are expected to be empty */
                            if ( ! self -> read_only ||
                                 /* permit empty open when run from sradb */
                                 ( GetRCObject ( rc ) == rcRange &&
                                   self -> permit_add_column &&
                                   VectorLength ( & self -> row ) == 0 ) )
                            {
                                rc = 0;
                            }
                        }
                    }
                    else if ( count != 0 )
                    {
                        if ( self -> read_only )
                        {
                            /* set initial row id to starting row */
                            self -> start_id = self -> end_id = self -> row_id = first;
                        }
                        else
                        {
                            /* set initial row id to append */
                            self -> start_id = self -> end_id = self -> row_id = first + count;
                        }
                    }
                }

                if ( rc != 0 )
                    self -> state = vcFailed;
            }

            KDlsetRelease ( libs );
        }
    }

    return rc;
}