Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on RSQLite #165

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions R/Andromeda.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ lowLevelQuerySqlToAndromeda.default <- function(connection,
integerAsNumeric = integerAsNumeric
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I just use andromeda's interface for writing and appending to a table.

RSQLite::dbWriteTable(
conn = andromeda,
name = andromedaTableName,
value = batch,
overwrite = first,
append = !first
)
if (first) {
andromeda[[andromedaTableName]] <- batch
} else {
Andromeda::appendToTable(andromeda[[andromedaTableName]], batch)
}
first <- FALSE
}
invisible(andromeda)
Expand All @@ -132,13 +130,7 @@ lowLevelQuerySqlToAndromeda.DatabaseConnectorDbiConnection <- function(connectio
integer64AsNumeric = integer64AsNumeric
)

RSQLite::dbWriteTable(
conn = andromeda,
name = andromedaTableName,
value = results,
overwrite = TRUE,
append = FALSE
)
andromeda[[andromedaTableName]] <- results
invisible(andromeda)
}

Expand Down Expand Up @@ -216,8 +208,8 @@ querySqlToAndromeda <- function(connection,
) && rJava::is.jnull(connection@jConnection)) {
stop("Connection is closed")
}
if (!inherits(andromeda, "SQLiteConnection")) {
stop("The andromeda argument must be an Andromeda object (or SQLiteConnection objecT).")
if (!inherits(andromeda, "Andromeda")) {
stop("The andromeda argument must be an Andromeda object.")
}

# Calling splitSql, because this will also strip trailing semicolons (which cause Oracle to crash).
Expand All @@ -239,21 +231,12 @@ querySqlToAndromeda <- function(connection,
integerAsNumeric = integerAsNumeric,
integer64AsNumeric = integer64AsNumeric
)
columnNames <- RSQLite::dbListFields(andromeda, andromedaTableName)
columnNames <- colnames(andromeda[[andromedaTableName]])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work with the current Andromeda version.

newColumnNames <- toupper(columnNames)
if (snakeCaseToCamelCase) {
newColumnNames <- SqlRender::snakeCaseToCamelCase(newColumnNames)
}
idx <- columnNames != newColumnNames
if (any(idx)) {
sql <- sprintf(
"ALTER TABLE %s RENAME COLUMN %s TO %s;",
andromedaTableName,
columnNames[idx],
newColumnNames[idx]
)
lapply(sql, function(x) RSQLite::dbExecute(andromeda, x))
}
names(andromeda[[andromedaTableName]]) <- newColumnNames
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This required a new Andromeda method and is in the current develop branch of Andromeda.

invisible(andromeda)
},
error = function(err) {
Expand Down