Skip to content

Commit

Permalink
Merge pull request #3312 from Sweetdevil144/develop
Browse files Browse the repository at this point in the history
Combine multiple `PEcAn.db` calls in a single query
  • Loading branch information
infotroph authored Jul 10, 2024
2 parents 4dfee93 + d287192 commit 1fd72ab
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions modules/data.atmosphere/R/read.register.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ read.register <- function(register.xml, con) {
} else if ((!is.null(register$format$id) & is.null(register$format$name))
|
(!is.null(register$format$id) & is.null(register$format$mimetype))) {
register$format$name <- PEcAn.DB::db.query(
paste("SELECT name from formats where id = ", register$format$id), con)[[1]]
register$format$mimetype <- PEcAn.DB::db.query(
paste("SELECT mime_type from formats where id = ", register$format$id), con)[[1]]
# Retrieve format name and mimetype from the database
query.format.info <- PEcAn.DB::db.query(
paste(
"SELECT name, type_string AS mimetype",
"FROM formats JOIN mimetypes ON formats.mimetype_id = mimetypes.id",
"WHERE formats.id = ", register$format$id),
con
)

register$format$name <- query.format.info$name
register$format$mimetype <- query.format.info$mimetype

} else if (is.null(register$format$id) & !is.null(register$format$name) & !is.null(register$format$mimetype)) {
register$format$id <- PEcAn.DB::db.query(
paste0("SELECT id from formats where name = '", register$format$name,
"' and mime_type = '", register$format$mimetype, "'"), con)[[1]]
paste0(
"SELECT formats.id FROM formats JOIN mimetypes ON formats.mimetype_id = mimetypes.id ",
"WHERE name = '", register$format$name,
"' AND type_string = '", register$format$mimetype, "'"), con)[[1]]
}
}
return(invisible(register))
Expand Down

0 comments on commit 1fd72ab

Please sign in to comment.