# NOT RUN {
# Define a new source, 'A', by a connection string. Alternatively,
# the string could be replaced with the name of a DSN, the path of
# a config file, or the name of an existing source (to be copied).
# This particular connection string would be for a GNU/Linux system
# upon which the unixODBC driver alias 'MariaDB' has been defined,
# in addition to the 'MDB' alias for the server address.
sqrlSource(A = "Driver=MariaDB;Server=MDB;User=zarkov;Password=zenith")
# Redefine source 'A', by a connection string given in sections.
# This is for a GNU/Linux system without a unixODBC driver alias.
sqrlSource("A", "dbcname=planet;uid=zakharov;pwd=$tdwallet(planet)",
"driver=/opt/teradata/client/16.10/lib64/tdata.so")
# Define a new source, by way of named connection-string components.
# This example is for a Windows-system client, and uses the '<pwd>'
# placeholder (it remains to set a value for the pwd parameter before
# connecting to the ODBC source).
sqrlSource("jumbo",
driver = "PostgreSQL ANSI(x64)",
server = "localhost",
port = 5432,
uid = "admin",
pwd = "<pwd>")
# Define another source, as a vector of connection string
# components, along with some RODBC/SQRL parameter values.
sqrlSource("mydb", believeNRows = FALSE, autoclose = TRUE,
connection = c(Driver = "SQLite3 ODBC Driver",
Database = "C:/mydatabase.db",
Timeout = 10000,
StepAPI = 1))
# Define another source, from a DSN (rather than a connection
# string), while also setting an RODBC/SQRL parameter value.
sqrlSource("ak", dsn = "Akademgorodok", as.is = TRUE)
# Redefine the source. This time, the dsn term is treated as a
# connection string component (because the server term must be).
sqrlSource("ak", dsn = "Akademgorodok", server = "Novosibirsk")
# Define another source, 'Huma', by a list of components, which
# includes an explicit source name, a vector of connection string
# components, a config list of RODBC/SQRL parameter values, and
# one more RODBC/SQRL parameter value outside of that config list.
# This list format is convenient for programmatic source creation.
sqrlSource(list(name = "Huma",
connection = c(DRIVER = "Firebird/InterBase(r) driver",
DBNAME = "C:\\Database\\myDB.fdb",
UID = "MCSSITE",
PWD = "mcssite"),
config = list(as.is = TRUE, scdo = FALSE),
visible = TRUE))
# Define a source called 'source'. Although the name 'source' clashes
# with that of the base::source function, this definition is allowed
# because we simultaneously set an interface, 'S', that does not clash.
# Note the mixture of named and unnamed connection string components.
sqrlSource(source = list(connection = c("DSN=Source", UID = "me"),
interface = "S"))
# Another source, defined by a list of named connection string
# components (without setting any other parameter values).
sqrlSource(sf = list(driver = "{SnowflakeDSIIDriver}",
server = "xyz.eu-central-1.snowflakecomputing.com",
uid = "me", pwd = "guess", port = 443))
# Create a configuration file.
config.file <- tempfile()
writeLines(c("autoclose = TRUE",
"readOnlyOptimize = TRUE",
"visible = FALSE"),
config.file)
# Define a new source, 'papango', as a copy of the existing source,
# 'Huma', then apply the above configuration file over that, and
# then set values for the dsn and interface parameters over those.
# In this example, the value of the 'visible' parameter inherited
# from Huma is overwritten by the value from the config file.
# Setting the dsn parameter likewise erases the value of the
# connection parameter inherited from Huma, while the inherited
# uid and pwd values survive. Alternatively, we could have set
# 'connection = "dsn=Aythya"' in place of 'dsn = "Aythya"', and
# this would ignore the inherited uid and pwd values.
sqrlSource("papango",
copy = "Huma",
config = config.file,
dsn = "Aythya",
interface = "P")
# Review all defined sources.
sqrlSources()
# Review the configuration of the papango source.
P("config")
# Review details of how we connect to the source.
P("source")
# Clean-up (various methods of source removal).
sqrlSource("remove", "jumbo")
sqrlSource(remove = c("mongo", "papango"))
sqrlSource(Huma = NULL)
unlink(config.file)
# }
Run the code above in your browser using DataLab