dbConnect-MariaDBDriver-method: Connect/disconnect to a MariaDB DBMS

Description Usage Arguments References Examples

Description

These methods are straight-forward implementations of the corresponding generic functions.

Usage

1
2
3
4
5
6
7
8
9
## S4 method for signature 'MariaDBDriver'
dbConnect(drv, dbname = NULL, username = NULL,
  password = NULL, host = NULL, unix.socket = NULL, port = 0,
  client.flag = 0, groups = "rs-dbi", default.file = NULL,
  ssl.key = NULL, ssl.cert = NULL, ssl.ca = NULL, ssl.capath = NULL,
  ssl.cipher = NULL, ..., bigint = c("integer64", "integer", "numeric",
  "character"))

MariaDB()

Arguments

drv

an object of class MariaDBDriver or MariaDBConnection.

dbname

string with the database name or NULL. If not NULL, the connection sets the default database to this value.

username, password

Username and password. If username omitted, defaults to the current user. If password is omitted, only users without a password can log in.

host

string identifying the host machine running the MariaDB server or NULL. If NULL or the string "localhost", a connection to the local host is assumed.

unix.socket

(optional) string of the unix socket or named pipe.

port

(optional) integer of the TCP/IP default port.

client.flag

(optional) integer setting various MariaDB client flags, see Client-flags for details.

groups

string identifying a section in the default.file to use for setting authentication parameters (see MariaDB()).

default.file

string of the filename with MariaDB client options, only relevant if groups is given. The default value depends on the operating system (see references), on Linux and OS X the files ~/.my.cnf and ~/.mylogin.cnf are used.

ssl.key

(optional) string of the filename of the SSL key file to use.

ssl.cert

(optional) string of the filename of the SSL certificate to use.

ssl.ca

(optional) string of the filename of an SSL certificate authority file to use.

ssl.capath

(optional) string of the path to a directory containing the trusted SSL CA certificates in PEM format.

ssl.cipher

(optional) string list of permitted ciphers to use for SSL encryption.

...

Unused, needed for compatibility with generic.

bigint

The R type that 64-bit integer types should be mapped to, default is bit64::integer64, which allows the full range of 64 bit integers.

References

Configuration files: https://mariadb.com/kb/en/library/configuring-mariadb-with-mycnf/

Examples

 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
## Not run: 
# Connect to a MariaDB database running locally
con <- dbConnect(RMariaDB::MariaDB(), dbname = "mydb")
# Connect to a remote database with username and password
con <- dbConnect(RMariaDB::MariaDB(), host = "mydb.mycompany.com",
  user = "abc", password = "def")
# But instead of supplying the username and password in code, it's usually
# better to set up a group in your .my.cnf (usually located in your home
directory). Then it's less likely you'll inadvertently share them.
con <- dbConnect(RMariaDB::MariaDB(), group = "test")

# Always cleanup by disconnecting the database
dbDisconnect(con)

## End(Not run)

# All examples use the rs-dbi group by default.
if (mariadbHasDefault()) {
  con <- dbConnect(RMariaDB::MariaDB(), dbname = "test")
  con
  dbDisconnect(con)
}
if (mariadbHasDefault()) {
# connect to a database and load some data
con <- dbConnect(RMariaDB::MariaDB(), dbname = "test")
dbWriteTable(con, "USArrests", datasets::USArrests, temporary = TRUE)

# query
rs <- dbSendQuery(con, "SELECT * FROM USArrests")
d1 <- dbFetch(rs, n = 10)      # extract data in chunks of 10 rows
dbHasCompleted(rs)
d2 <- dbFetch(rs, n = -1)      # extract all remaining data
dbHasCompleted(rs)
dbClearResult(rs)
dbListTables(con)

# clean up
dbDisconnect(con)
}

RMariaDB documentation built on May 7, 2018, 1:03 a.m.