Changeset 18923 for branches/eam_branch_20080719/ippTools/src/stacktool.c
- Timestamp:
- Aug 5, 2008, 2:07:07 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/ippTools/src/stacktool.c
r18659 r18923 107 107 psMetadata *whereRE = psMetadataAlloc(); // rawExp where 108 108 psMetadata *whereWSF = psMetadataAlloc(); // warpSkyfile where 109 psMetadata *having = psMetadataAlloc(); // having109 psMetadata *having = psMetadataAlloc(); // HAVING clause 110 110 // map -inst -> camera, etc 111 111 PXOPT_COPY_STR(config->args, whereRE, "-select_inst", "camera", "=="); … … 128 128 129 129 PXOPT_COPY_STR(config->args, having, "-select_skycell_id", "skycell_id", "=="); 130 PXOPT_COPY_S32(config->args, having, "-min_num", "num_warp", ">="); 130 131 131 132 PXOPT_LOOKUP_S32(randomLimit, config->args, "-random", false, false); 132 133 133 PXOPT_COPY_S32(config->args, having, "-min_num", "num_warp", ">="); 134 PXOPT_COPY_S32(config->args, having, "-min_new", "(num_warp - num_stack)", ">="); 135 134 PXOPT_LOOKUP_S32(min_new, config->args, "-min_new", false, false); 136 135 PXOPT_LOOKUP_F32(min_frac, config->args, "-min_frac", false, false); 137 136 … … 178 177 psFree(groupby); 179 178 180 if (psListLength(having->list)) { 181 psString havingClause = psDBGenerateWhereConditionSQL(having, NULL); 182 psStringAppend(&select, " HAVING %s", havingClause); 183 psFree(havingClause); 184 } 185 186 // Gotta handle this one explicitly --- want to avoid divisions 187 if (isfinite(min_frac)) { 179 // Restriction on aggregated quantities using HAVING 180 { 181 psString havingClause = NULL; // HAVING string 188 182 if (psListLength(having->list)) { 189 psStringAppend(&select, " AND"); 190 } else { 191 psStringAppend(&select, " HAVING"); 192 } 193 psStringAppend(&select, " num_warp >= %f * num_stack", (double)min_frac); 194 } 195 183 havingClause = psDBGenerateWhereConditionSQL(having, NULL); 184 } 185 186 if (min_new > 0) { 187 if (havingClause) { 188 psStringAppend(&havingClause, " AND"); 189 } 190 psStringAppend(&havingClause, 191 " (num_warp - num_stack >= %d OR (num_warp >= %d AND num_stack IS NULL))", 192 min_new, min_new); 193 } 194 if (isfinite(min_frac)) { 195 if (havingClause) { 196 psStringAppend(&havingClause, " AND"); 197 } 198 // Avoiding division by zero 199 psStringAppend(&havingClause, " (num_warp >= %f * num_stack OR num_stack IS NULL)", 200 (double)min_frac); 201 } 202 if (havingClause) { 203 psStringAppend(&select, " HAVING %s", havingClause); 204 psFree(havingClause); 205 } 206 } 196 207 psFree(having); 208 197 209 198 210 if (!p_psDBRunQuery(config->dbh, select)) { … … 239 251 } 240 252 253 psArray *list = psArrayAllocEmpty(16); // List of runs, to print 241 254 for (long i = 0; i < output->n; i++) { 242 255 psMetadata *row = output->data[i]; // Row from select … … 249 262 psFree(output); 250 263 psFree(insert); 264 psFree(list); 251 265 if (!psDBRollback(config->dbh)) { 252 266 psError(PS_ERR_UNKNOWN, false, "database error"); … … 260 274 psFree(output); 261 275 psFree(insert); 276 psFree(list); 262 277 if (!psDBRollback(config->dbh)) { 263 278 psError(PS_ERR_UNKNOWN, false, "database error"); … … 271 286 psFree(output); 272 287 psFree(insert); 288 psFree(list); 273 289 if (!psDBRollback(config->dbh)) { 274 290 psError(PS_ERR_UNKNOWN, false, "database error"); … … 296 312 psFree(run); 297 313 psFree(insert); 314 psFree(list); 298 315 if (!psDBRollback(config->dbh)) { 299 316 psError(PS_ERR_UNKNOWN, false, "database error"); … … 306 323 run->stack_id = stack_id; 307 324 308 if (!stackRunPrintObject(stdout, run, !simple)) { 309 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 310 psFree(run); 311 psFree(insert); 312 if (!psDBRollback(config->dbh)) { 313 psError(PS_ERR_UNKNOWN, false, "database error"); 314 } 315 return false; 316 } 325 psArrayAdd(list, list->n, run); 317 326 psFree(run); 318 327 … … 331 340 psFree(insert); 332 341 psFree(output); 342 psFree(list); 333 343 if (!psDBRollback(config->dbh)) { 334 344 psError(PS_ERR_UNKNOWN, false, "database error"); … … 338 348 psFree(thisInsert); 339 349 } 350 psFree(output); 340 351 341 352 if (!psDBCommit(config->dbh)) { 342 353 psError(PS_ERR_UNKNOWN, false, "database error"); 343 return false; 344 } 345 346 psFree(output); 354 psFree(list); 355 return false; 356 } 357 358 if (!stackRunPrintObjects(stdout, list, !simple)) { 359 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 360 return false; 361 } 362 363 psFree(list); 347 364 348 365 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
