Revision 401
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
18 | 18 |
package edu.ucsb.nceas.metacat; |
19 | 19 |
|
20 | 20 |
import java.io.*; |
21 |
import java.util.Vector; |
|
21 | 22 |
import java.net.URL; |
22 | 23 |
import java.net.MalformedURLException; |
23 | 24 |
import java.sql.*; |
... | ... | |
123 | 124 |
String docname = null; |
124 | 125 |
String doctype = null; |
125 | 126 |
String doctitle = null; |
127 |
String createDate = null; |
|
128 |
String updateDate = null; |
|
129 |
String fieldname = null; |
|
130 |
String fielddata = null; |
|
126 | 131 |
StringBuffer document = null; |
127 | 132 |
|
128 | 133 |
try { |
... | ... | |
141 | 146 |
docname = rs.getString(2); |
142 | 147 |
doctype = rs.getString(3); |
143 | 148 |
doctitle = rs.getString(4); |
144 |
|
|
149 |
createDate = rs.getString(5); |
|
150 |
updateDate = rs.getString(6); |
|
151 |
|
|
145 | 152 |
document = new StringBuffer(); |
153 |
|
|
146 | 154 |
document.append("<docid>").append(docid).append("</docid>"); |
147 | 155 |
if (docname != null) { |
148 | 156 |
document.append("<docname>" + docname + "</docname>"); |
... | ... | |
153 | 161 |
if (doctitle != null) { |
154 | 162 |
document.append("<doctitle>" + doctitle + "</doctitle>"); |
155 | 163 |
} |
164 |
if(createDate != null) { |
|
165 |
document.append("<createdate>" + createDate + "</createdate>"); |
|
166 |
} |
|
167 |
if(updateDate != null) { |
|
168 |
document.append("<updatedate>" + updateDate + "</updatedate>"); |
|
169 |
} |
|
156 | 170 |
|
157 | 171 |
// Store the document id and the root node id |
158 | 172 |
docListResult.put(docid,(String)document.toString()); |
... | ... | |
160 | 174 |
// Advance to the next record in the cursor |
161 | 175 |
tableHasRows = rs.next(); |
162 | 176 |
} |
177 |
|
|
178 |
if(qspec.containsExtendedSQL()) |
|
179 |
{ |
|
180 |
Vector extendedFields = new Vector(qspec.getReturnFieldList()); |
|
181 |
Vector results = new Vector(); |
|
182 |
pstmt = conn.prepareStatement(qspec.printExtendedSQL()); |
|
183 |
pstmt.execute(); |
|
184 |
rs = pstmt.getResultSet(); |
|
185 |
tableHasRows = rs.next(); |
|
186 |
while(tableHasRows) |
|
187 |
{ |
|
188 |
docid = rs.getString(1); |
|
189 |
fieldname = rs.getString(2); |
|
190 |
fielddata = rs.getString(3); |
|
191 |
|
|
192 |
document = new StringBuffer(); |
|
193 |
|
|
194 |
document.append("<"); |
|
195 |
document.append(fieldname.toLowerCase()); |
|
196 |
document.append(">"); |
|
197 |
document.append(fielddata); |
|
198 |
document.append("</"); |
|
199 |
document.append(fieldname.toLowerCase()); |
|
200 |
document.append(">"); |
|
201 |
|
|
202 |
tableHasRows = rs.next(); |
|
203 |
if(docListResult.containsKey(docid)) |
|
204 |
{ |
|
205 |
String removedelement = (String)docListResult.remove(docid); |
|
206 |
docListResult.put(docid, removedelement + document.toString()); |
|
207 |
} |
|
208 |
else |
|
209 |
{ |
|
210 |
docListResult.put(docid, document.toString()); |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
163 | 214 |
pstmt.close(); |
164 | 215 |
} catch (SQLException e) { |
165 | 216 |
System.err.println("Error getting id: " + e.getMessage()); |
... | ... | |
221 | 272 |
doctype = "ANY"; |
222 | 273 |
} |
223 | 274 |
|
275 |
if(params.containsKey("returnfield")) |
|
276 |
{ |
|
277 |
String[] returnfield = ((String[])params.get("returnfield")); |
|
278 |
for(int i=0; i<returnfield.length; i++) |
|
279 |
{ |
|
280 |
query.append("<returnfield>").append(returnfield[i]); |
|
281 |
query.append("</returnfield>"); |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
224 | 285 |
//if you don't limit the query by doctype, then it just creates |
225 | 286 |
//an empty returndoctype tag. |
226 | 287 |
if (!doctype.equals("any") && |
... | ... | |
301 | 362 |
!nextkey.toString().equals("action") && |
302 | 363 |
!nextkey.toString().equals("qformat") && |
303 | 364 |
!nextkey.toString().equals("anyfield") && |
365 |
!nextkey.toString().equals("returnfield") && |
|
304 | 366 |
!nextkey.toString().equals("operator") ) |
305 | 367 |
{ |
306 | 368 |
//allow for more than value per field name |
... | ... | |
379 | 441 |
|
380 | 442 |
/** |
381 | 443 |
* '$Log$ |
444 |
* 'Revision 1.14 2000/08/17 16:02:34 berkley |
|
445 |
* 'Made changes to createSQuery to allow for multiple parameters of the same name. Also changed the param list to include only "Hashtable params" without a "String doctype" since the doctype is already contained in the params. |
|
446 |
* ' |
|
382 | 447 |
* 'Revision 1.13 2000/08/14 21:26:12 berkley |
383 | 448 |
* 'Added createSQuery() to handle structured queries of an arbitrary number of parameters. Also modified createQuery() to handle a null query in a graceful manner. |
384 | 449 |
* ' |
Also available in: Unified diff
added support for the returnfield parameter
-added the dynamic parameters to the returned hash table of documents