-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathconnect.Rd
236 lines (209 loc) · 9.77 KB
/
connect.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Connect.R
\name{connect}
\alias{connect}
\title{connect}
\arguments{
\item{connectionDetails}{An object of class \code{connectionDetails} as created by the
\code{\link[=createConnectionDetails]{createConnectionDetails()}} function.}
\item{dbms}{The type of DBMS running on the server. Valid values are
\itemize{
\item "oracle" for Oracle
\item "postgresql" for PostgreSQL
\item "redshift" for Amazon Redshift
\item "sql server" for Microsoft SQL Server
\item "pdw" for Microsoft Parallel Data Warehouse (PDW)
\item "netezza" for IBM Netezza
\item "bigquery" for Google BigQuery
\item "sqlite" for SQLite
\item "sqlite extended" for SQLite with extended types (DATE and DATETIME)
\item "spark" for Spark
\item "snowflake" for Snowflake
}}
\item{user}{The user name used to access the server.}
\item{password}{The password for that user.}
\item{server}{The name of the server.}
\item{port}{(optional) The port on the server to connect to.}
\item{extraSettings}{(optional) Additional configuration settings specific to the database
provider to configure things as security for SSL. For connections using
JDBC these will be appended to end of the connection string. For
connections using DBI, these settings will additionally be used to call
\code{\link[=dbConnect]{dbConnect()}}.}
\item{oracleDriver}{Specify which Oracle drive you want to use. Choose between \code{"thin"}
or \code{"oci"}.}
\item{connectionString}{The JDBC connection string. If specified, the \code{server}, \code{port},
\code{extraSettings}, and \code{oracleDriver} fields are ignored. If
\code{user} and \code{password} are not specified, they are assumed to
already be included in the connection string.}
\item{pathToDriver}{Path to a folder containing the JDBC driver JAR files. See
\code{\link[=downloadJdbcDrivers]{downloadJdbcDrivers()}} for instructions on how to download the
relevant drivers.}
}
\value{
An object that extends \code{DBIConnection} in a database-specific manner. This object is used to
direct commands to the database engine.
}
\description{
Creates a connection to a database server .There are four ways to call this
function:
\itemize{
\item \code{connect(dbms, user, password, server, port, extraSettings, oracleDriver, pathToDriver)}
\item \code{connect(connectionDetails)}
\item \verb{connect(dbms, connectionString, pathToDriver))}
\item \code{connect(dbms, connectionString, user, password, pathToDriver)}
}
\subsection{DBMS parameter details:}{
Depending on the DBMS, the function arguments have slightly different
interpretations:
Oracle:
\itemize{
\item \code{user}. The user name used to access the server
\item \code{password}. The password for that user
\item \code{server}. This field contains the SID, or host and servicename, SID, or TNSName:
'sid', 'host/sid', 'host/service name', or 'tnsname'
\item \code{port}. Specifies the port on the server (default = 1521)
\item \code{extraSettings}. The configuration settings for the connection (i.e. SSL Settings such
as "(PROTOCOL=tcps)")
\item \code{oracleDriver}. The driver to be used. Choose between "thin" or "oci".
\item \code{pathToDriver}. The path to the folder containing the Oracle JDBC driver JAR files.
}
Microsoft SQL Server:
\itemize{
\item \code{user}. The user used to log in to the server. If the user is not specified, Windows
Integrated Security will be used, which requires the SQL Server JDBC drivers to be installed
(see details below).
\item \code{password}. The password used to log on to the server
\item \code{server}. This field contains the host name of the server
\item \code{port}. Not used for SQL Server
\item \code{extraSettings}. The configuration settings for the connection (i.e. SSL Settings such
as "encrypt=true; trustServerCertificate=false;")
\item \code{pathToDriver}. The path to the folder containing the SQL Server JDBC driver JAR files.
}
Microsoft PDW:
\itemize{
\item \code{user}. The user used to log in to the server. If the user is not specified, Windows
Integrated Security will be used, which requires the SQL Server JDBC drivers to be installed
(see details below).
\item \code{password}. The password used to log on to the server
\item \code{server}. This field contains the host name of the server
\item \code{port}. Not used for SQL Server
\item \code{extraSettings}. The configuration settings for the connection (i.e. SSL Settings such
as "encrypt=true; trustServerCertificate=false;")
\item \code{pathToDriver}. The path to the folder containing the SQL Server JDBC driver JAR files.
}
PostgreSQL:
\itemize{
\item \code{user}. The user used to log in to the server
\item \code{password}. The password used to log on to the server
\item \code{server}. This field contains the host name of the server and the database holding the
relevant schemas: host/database
\item \code{port}. Specifies the port on the server (default = 5432)
\item \code{extraSettings}. The configuration settings for the connection (i.e. SSL Settings such
as "ssl=true")
\item \code{pathToDriver}. The path to the folder containing the PostgreSQL JDBC driver JAR files.
}
Redshift:
\itemize{
\item \code{user}. The user used to log in to the server
\item \code{password}. The password used to log on to the server
\item \code{server}. This field contains the host name of the server and the database holding the
relevant schemas: host/database
\item \code{port}. Specifies the port on the server (default = 5439)
\item `extraSettings The configuration settings for the connection (i.e. SSL Settings such
as "ssl=true&sslfactory=com.amazon.redshift.ssl.NonValidatingFactory")
\item \code{pathToDriver}. The path to the folder containing the RedShift JDBC driver JAR files.
}
Netezza:
\itemize{
\item \code{user}. The user used to log in to the server
\item \code{password}. The password used to log on to the server
\item \code{server}. This field contains the host name of the server and the database holding the
relevant schemas: host/database
\item \code{port}. Specifies the port on the server (default = 5480)
\item \code{extraSettings}. The configuration settings for the connection (i.e. SSL Settings such
as "ssl=true")
\item \code{pathToDriver}. The path to the folder containing the Netezza JDBC driver JAR file
(nzjdbc.jar).
}
Impala:
\itemize{
\item \code{user}. The user name used to access the server
\item \code{password}. The password for that user
\item \code{server}. The host name of the server
\item \code{port}. Specifies the port on the server (default = 21050)
\item \code{extraSettings}. The configuration settings for the connection (i.e. SSL Settings such
as "SSLKeyStorePwd=*****")
\item \code{pathToDriver}. The path to the folder containing the Impala JDBC driver JAR files.
}
SQLite:
\itemize{
\item \code{server}. The path to the SQLIte file.
}
Spark / Databricks:
Currently both JDBC and ODBC connections are supported for Spark. Set the
\code{connectionString} argument to use JDBC, otherwise ODBC is used:
\itemize{
\item \code{connectionString}. The JDBC connection string (e.g. something like
'jdbc:databricks://my-org.cloud.databricks.com:443/default;transportMode=http;ssl=1;AuthMech=3;httpPath=/sql/1.0/warehouses/abcde12345;').
\item \code{user}. The user name used to access the server. This can be set to 'token' when using a personal token (recommended).
\item \code{password}. The password for that user. This should be your personal token when using a personal token (recommended).
\item \code{server}. The host name of the server (when using ODBC), e.g. 'my-org.cloud.databricks.com')
\item \code{port}. Specifies the port on the server (when using ODBC)
\item \code{extraSettings}. Additional settings for the ODBC connection, for example
\code{extraSettings = list(HTTPPath = "/sql/1.0/warehouses/abcde12345", SSL = 1, ThriftTransport = 2, AuthMech = 3)}
}
Snowflake:
\itemize{
\item \code{connectionString}. The connection string (e.g. starting with
'jdbc:snowflake://host:port/?db=database').
\item \code{user}. The user name used to access the server.
\item \code{password}. The password for that user.
}
}
\subsection{Windows authentication for SQL Server:}{
To be able to use Windows authentication for SQL Server (and PDW), you have to install the JDBC
driver. Download the version 9.2.0 .zip from \href{https://learn.microsoft.com/en-us/sql/connect/jdbc/release-notes-for-the-jdbc-driver?view=sql-server-ver15#92-releases}{Microsoft}
and extract its contents to a folder. In the extracted folder you will find the file
sqljdbc_9.2/enu/auth/x64/mssql-jdbc_auth-9.2.0.x64.dll (64-bits) or
ssqljdbc_9.2/enu/auth/x86/mssql-jdbc_auth-9.2.0.x86.dll (32-bits), which needs to be moved to
location on the system path, for example to c:/windows/system32. If you not have write access to
any folder in the system path, you can also specify the path to the folder containing the dll by
setting the environmental variable PATH_TO_AUTH_DLL, so for example
\code{Sys.setenv("PATH_TO_AUTH_DLL" = "c:/temp")} Note that the environmental variable needs to be
set before calling \code{\link[=connect]{connect()}} for the first time.
}
}
\details{
This function creates a connection to a database.
}
\examples{
\dontrun{
connectionDetails <- createConnectionDetails(
dbms = "postgresql",
server = "localhost/postgres",
user = "root",
password = "xxx"
)
conn <- connect(connectionDetails)
dbGetQuery(conn, "SELECT COUNT(*) FROM person")
disconnect(conn)
conn <- connect(dbms = "sql server", server = "RNDUSRDHIT06.jnj.com")
dbGetQuery(conn, "SELECT COUNT(*) FROM concept")
disconnect(conn)
conn <- connect(
dbms = "oracle",
server = "127.0.0.1/xe",
user = "system",
password = "xxx",
pathToDriver = "c:/temp"
)
dbGetQuery(conn, "SELECT COUNT(*) FROM test_table")
disconnect(conn)
conn <- connect(
dbms = "postgresql",
connectionString = "jdbc:postgresql://127.0.0.1:5432/cmd_database"
)
dbGetQuery(conn, "SELECT COUNT(*) FROM person")
disconnect(conn)
}
}