Skip to content

Commit

Permalink
fixing MS SQL ODBC bug #146 until we decide on switch to odbc
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanbeaudette committed Oct 1, 2020
1 parent c1f1a8e commit 3aec638
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/get_component_data_from_NASIS_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ get_component_restrictions_from_NASIS_db <- function(SS = TRUE) {
get_mutext_from_NASIS_db <- function(SS=TRUE, fixLineEndings=TRUE) {

q <- "SELECT mu.muiid, mu.mukind, mu.mutype, mu.muname, mu.nationalmusym,
mut.seqnum, mut.recdate, mut.recauthor, mut.mapunittextkind, mut.textcat, mut.textsubcat, mut.textentry
mut.seqnum, mut.recdate, mut.recauthor, mut.mapunittextkind, mut.textcat, mut.textsubcat, CAST(mut.textentry AS ntext) AS textentry
FROM
mapunit_View_1 AS mu
Expand Down
2 changes: 1 addition & 1 deletion R/get_extended_data_from_NASIS_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ get_extended_data_from_NASIS_db <- function(SS=TRUE, nullFragsAreZero=TRUE, stri
stop('please install the `RODBC` package', call.=FALSE)

# photo links from PedonPC stored as sitetext notes
q.photolink <- "SELECT so.siteiidref AS siteiid, sot.recdate, sot.textcat, sot.textentry AS imagepath
q.photolink <- "SELECT so.siteiidref AS siteiid, sot.recdate, sot.textcat, CAST(sot.textentry AS ntext) AS AS imagepath
FROM
siteobs_View_1 AS so
LEFT OUTER JOIN siteobstext_View_1 AS sot ON so.siteobsiid = sot.siteobsiidref
Expand Down
18 changes: 8 additions & 10 deletions R/get_text_notes_from_NASIS_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ get_text_notes_from_NASIS_db <- function(SS=TRUE, fixLineEndings=TRUE) {
stop('please install the `RODBC` package', call.=FALSE)

# petext
q.petext <- "SELECT recdate, recauthor, pedontextkind, textcat, textsubcat, textentry, peiidref AS peiid, petextiid FROM petext_View_1;"
q.petext <- "SELECT recdate, recauthor, pedontextkind, textcat, textsubcat, CAST(textentry AS ntext) AS textentry, peiidref AS peiid, petextiid FROM petext_View_1;"

# sitetext
q.sitetext <- "SELECT recdate, recauthor, sitetextkind, textcat, textsubcat, textentry, siteiidref AS siteiid, sitetextiid FROM sitetext_View_1;"
q.sitetext <- "SELECT recdate, recauthor, sitetextkind, textcat, textsubcat, CAST(textentry AS ntext) AS textentry, siteiidref AS siteiid, sitetextiid FROM sitetext_View_1;"

# siteobstext
q.siteobstext <- "SELECT recdate, recauthor, siteobstextkind, textcat, textsubcat, textentry, siteiidref AS site_id, siteobstextiid FROM (
q.siteobstext <- "SELECT recdate, recauthor, siteobstextkind, textcat, textsubcat, CAST(textentry AS ntext) AS textentry, siteiidref AS site_id, siteobstextiid FROM (
siteobs_View_1 LEFT OUTER JOIN
siteobstext_View_1 ON siteobs_View_1.siteobsiid = siteobstext_View_1.siteobsiidref);"

# phtext
q.phtext <- "SELECT recdate, recauthor, phorizontextkind, textcat, textsubcat, textentry, phiidref AS phiid, phtextiid FROM phtext_View_1;"
q.phtext <- "SELECT recdate, recauthor, phorizontextkind, textcat, textsubcat, CAST(textentry AS ntext) AS textentry, phiidref AS phiid, phtextiid FROM phtext_View_1;"

# photo links
q.photos <- "SELECT recdate, recauthor, siteobstextkind, textcat, textsubcat, textentry, siteiidref AS site_id, siteobstextiid FROM (siteobs_View_1 LEFT OUTER JOIN siteobstext_View_1 ON siteobs_View_1.siteobsiid = siteobstext_View_1.siteobsiidref) WHERE siteobstext_View_1.textcat LIKE 'Photo%' ORDER BY siteobstext_View_1.siteobstextkind;"
q.photos <- "SELECT recdate, recauthor, siteobstextkind, textcat, textsubcat, CAST(textentry AS ntext) AS textentry, siteiidref AS site_id, siteobstextiid FROM (siteobs_View_1 LEFT OUTER JOIN siteobstext_View_1 ON siteobs_View_1.siteobsiid = siteobstext_View_1.siteobsiidref) WHERE siteobstext_View_1.textcat LIKE 'Photo%' ORDER BY siteobstext_View_1.siteobstextkind;"

# check for RODBC, NASIS credential options, and successful connection
channel <- .openNASISchannel()
Expand All @@ -45,13 +45,11 @@ siteobstext_View_1 ON siteobs_View_1.siteobsiid = siteobstext_View_1.siteobsiidr
# optionally convert \r\n -> \n
if(fixLineEndings){
d.petext$textentry <- gsub(d.petext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
d.sitetext$textentry <- gsub(d.sitetext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
d.siteobstext$textentry <- gsub(d.siteobstext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
d.phtext$textentry <- gsub(d.phtext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
d.sitetext$textentry <- gsub(d.sitetext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
d.siteobstext$textentry <- gsub(d.siteobstext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
d.phtext$textentry <- gsub(d.phtext$textentry, pattern = '\r\n', replacement = '\n', fixed = TRUE)
}



# return a list of results
return(list(pedon_text=d.petext,
site_text=d.sitetext,
Expand Down
2 changes: 1 addition & 1 deletion R/get_vegplot_data_from_NASIS_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ get_vegplot_from_NASIS_db <- function(SS=TRUE, stringsAsFactors = default.string
# vegplot textnotes
q.vegplottext <- "SELECT vegplotiidref as vegplotiid, seqnum, recdate, recauthor, vegplottextkind,
textcat, textsubcat, textentry, vegplottextiid
textcat, textsubcat, CAST(textentry AS ntext) AS textentry, vegplottextiid
FROM vegplottext_View_1;"
# setup connection local NASIS
Expand Down

0 comments on commit 3aec638

Please sign in to comment.