1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #include <vdb/extern.h>
28 #define TRACK_REFERENCES 0
29
30 #define KONST const
31 #include "prod-priv.h"
32 #include "prod-expr.h"
33 #include "schema-priv.h"
34 #include "schema-expr.h"
35 #include "cursor-priv.h"
36 #include "column-priv.h"
37 #undef KONST
38
39 #include <vdb/cursor.h>
40 #include <klib/symbol.h>
41 #include <klib/log.h>
42 #include <klib/rc.h>
43 #include <sysalloc.h>
44
45 #include <stdlib.h>
46 #include <string.h>
47 #include <assert.h>
48
49
50
51 /*--------------------------------------------------------------------------
52 * VProdResolve
53 */
54
55 /* ResolveColumn
56 * resolves a column using read expression
57 */
VProdResolveColumnRoot(const VProdResolve * self,VProduction ** out,const SColumn * scol)58 rc_t VProdResolveColumnRoot ( const VProdResolve *self,
59 VProduction **out, const SColumn *scol )
60 {
61 rc_t rc = VProdResolveColumnRead ( self, out, scol );
62 if ( rc == 0 && * out <= FAILED_PRODUCTION )
63 return SILENT_RC ( rcVDB, rcCursor, rcOpening, rcColumn, rcUndefined );
64 return rc;
65 }
66
VProdResolveColumn(const VProdResolve * self,VProduction ** out,const SColumn * scol,bool alt)67 rc_t VProdResolveColumn ( const VProdResolve *self,
68 VProduction **out, const SColumn *scol, bool alt )
69 {
70 rc_t rc;
71 VColumn *vcol;
72 VCursor *curs = self -> curs;
73
74 if (alt) {
75 /* TODO: Generate warning message */
76 return RC(rcVDB, rcCursor, rcOpening, rcSchema, rcInvalid);
77 }
78 /* read-only cursor may add columns from schema */
79 vcol = VCursorCacheGet ( VCursorColumns ( curs ), & scol -> cid );
80 if ( vcol == NULL )
81 {
82 rc = VCursorMakeColumn ( curs, & vcol, scol, self -> cx_bind );
83 if ( rc != 0 )
84 return rc;
85
86 #if OPEN_COLUMN_ALTERS_ROW
87 rc = VectorAppend ( VCursorGetRow ( curs ), & vcol -> ord, vcol );
88 if ( rc != 0 )
89 {
90 VColumnWhack ( vcol, NULL );
91 return rc;
92 }
93 #endif
94 rc = VCursorCacheSet ( VCursorColumns ( curs ), & scol -> cid, vcol );
95 if ( rc != 0 )
96 {
97 #if OPEN_COLUMN_ALTERS_ROW
98 void *ignore;
99 VectorSwap ( VCursorGetRow ( curs ), vcol -> ord, NULL, & ignore );
100 vcol -> ord = 0;
101 #endif
102 VColumnWhack ( vcol, NULL );
103 return rc;
104 }
105 }
106
107 /* resolve for read production */
108 return VProdResolveColumnRead ( self, out, scol );
109 }
110
VProdResolvePhysical(const VProdResolve * self,struct VPhysical * phys)111 rc_t VProdResolvePhysical ( const VProdResolve *self, struct VPhysical *phys )
112 {
113 return VProdResolvePhysicalRead ( self, phys );
114 }
115
116 /*--------------------------------------------------------------------------
117 * VColumnProd
118 * message redirect to VColumn
119 */
120
VColumnProdMake(VProduction ** prodp,Vector * owned,VColumn * col,int sub,const char * name)121 rc_t VColumnProdMake ( VProduction **prodp, Vector *owned,
122 VColumn *col, int sub, const char *name )
123 {
124 return RC ( rcVDB, rcColumn, rcReading, rcSchema, rcInvalid );
125 }
126
VColumnProdDestroy(VColumnProd * self)127 void VColumnProdDestroy ( VColumnProd *self )
128 {
129 }
130
131 /* Read
132 */
VColumnProdRead(VColumnProd * self,struct VBlob ** vblob,int64_t id)133 rc_t VColumnProdRead ( VColumnProd *self, struct VBlob **vblob, int64_t id )
134 {
135 return RC ( rcVDB, rcColumn, rcReading, rcSchema, rcInvalid );
136 }
137
138