4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright (c) 1988-2000 by Sun Microsystems, Inc.
26 * All Rights Reserved.
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include "db_headers.h"
36 /* Returns db_query containing the index values as obtained from 'attrlist.' */
37 db_query::db_query(db_scheme
* scheme
, int size
, nis_attr
* attrlist
)
40 num_components
= size
;
41 components
= new db_qcomp
[size
];
43 if (components
== NULL
) {
46 "db_query::db_query: cannot allocate space for components",
50 for (i
= 0; i
< size
; i
++) {
51 if (!scheme
->find_index(attrlist
[i
].zattr_ndx
,
52 &(components
[i
].which_index
))) {
53 syslog(LOG_ERR
, "db_query::db_query: bad index (%s)",
54 attrlist
[i
].zattr_ndx
);
58 components
[i
].index_value
= new
59 item(attrlist
[i
].zattr_val
.zattr_val_val
,
60 attrlist
[i
].zattr_val
.zattr_val_len
);
61 if (components
[i
].index_value
== NULL
) {
64 "db_query::db_query:cannot allocate space for index",
71 * Returns a newly db_query containing the index values as
72 * obtained from the given object. The object itself,
73 * along with information on the scheme given, will determine
74 * which values are extracted from the object and placed into the query.
75 * Returns an empty query if 'obj' is not a valid entry.
76 * Note that space is allocated for the query and the index values
77 * (i.e. do not share pointers with strings in 'obj'.)
79 db_query::db_query(db_scheme
*scheme
, entry_object_p obj
)
81 num_components
= scheme
->numkeys(); // scheme's view of key count
82 db_key_desc
*keyinfo
= scheme
->keyloc();
84 int objsize
= obj
->en_cols
.en_cols_len
; // total num columns in obj */
85 struct entry_col
* objcols
= obj
->en_cols
.en_cols_val
;
87 /* components of query to be returned */
88 components
= new db_qcomp
[num_components
];
91 if (components
== NULL
) {
93 "db_query::db_query: cannot allocate space for components",
97 /* fill in each component of query */
98 for (i
= 0; i
< num_components
; i
++) {
99 components
[i
].which_index
= i
; // index i
100 wherein_obj
= keyinfo
[i
].column_number
; // column in entry obj
101 if (wherein_obj
>= objsize
) {
103 "db_query::column %d cannot occur in object with %d columns (start counting at 0)\n",
104 wherein_obj
, objsize
);
105 clear_components(i
); // clean up
109 components
[i
].index_value
= new
110 item(objcols
[wherein_obj
].ec_value
.ec_value_val
,
111 objcols
[wherein_obj
].ec_value
.ec_value_len
);
112 if (components
[i
].index_value
== NULL
) {
115 "db_query::db_query:cannot allocate space for index",
119 /* do something about null keys? */
124 db_query::clear_components(int how_many
)
128 for (i
= 0; i
< how_many
; i
++)
129 if (components
[i
].index_value
)
130 delete components
[i
].index_value
;
138 db_query::~db_query()
140 clear_components(num_components
);
143 /* Print all components of this query to stdout. */
148 for (i
= 0; i
< num_components
; i
++) {
149 printf("%d: ", components
[i
].which_index
);
150 components
[i
].index_value
->print();