mariadb-tables: Read and write MariaDB tables.

Description Usage Arguments Value Note Examples

Description

These methods read or write entire tables from a MariaDB database.

Usage

 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
## S4 method for signature 'MariaDBConnection,character'
dbReadTable(conn, name, ...,
  row.names = FALSE, check.names = TRUE)

## S4 method for signature 'MariaDBConnection,character,data.frame'
dbWriteTable(conn, name,
  value, field.types = NULL, row.names = FALSE, overwrite = FALSE,
  append = FALSE, ..., temporary = FALSE)

## S4 method for signature 'MariaDBConnection,character,character'
dbWriteTable(conn, name,
  value, field.types = NULL, overwrite = FALSE, append = FALSE,
  header = TRUE, row.names = FALSE, nrows = 50, sep = ",",
  eol = "\n", skip = 0, quote = "\"", temporary = FALSE, ...)

## S4 method for signature 'MariaDBConnection'
dbListTables(conn, ...)

## S4 method for signature 'MariaDBConnection'
dbListObjects(conn, prefix = NULL, ...)

## S4 method for signature 'MariaDBConnection,character'
dbExistsTable(conn, name, ...)

## S4 method for signature 'MariaDBConnection,character'
dbRemoveTable(conn, name, ...,
  temporary = FALSE, fail_if_missing = TRUE)

Arguments

conn

a MariaDBConnection object, produced by DBI::dbConnect()

name

a character string specifying a table name.

...

Unused, needed for compatibility with generic.

row.names

Either TRUE, FALSE, NA or a string.

If TRUE, always translate row names to a column called "row_names". If FALSE, never translate row names. If NA, translate rownames only if they're a character vector.

A string is equivalent to TRUE, but allows you to override the default name.

For backward compatibility, NULL is equivalent to FALSE.

check.names

If TRUE, the default, column names will be converted to valid R identifiers.

value

A data frame.

field.types

Optional, overrides default choices of field types, derived from the classes of the columns in the data frame.

overwrite

a logical specifying whether to overwrite an existing table or not. Its default is FALSE.

append

a logical specifying whether to append to an existing table in the DBMS. If appending, then the table (or temporary table) must exist, otherwise an error is reported. Its default is FALSE.

temporary

If TRUE, creates a temporary table that expires when the connection is closed. For dbRemoveTable(), only temporary tables are considered if this argument is set to TRUE.

header

logical, does the input file have a header line? Default is the same heuristic used by read.table(), i.e., TRUE if the first line has one fewer column that the second line.

nrows

number of lines to rows to import using read.table from the input file to create the proper table definition. Default is 50.

sep

field separator character

eol

End-of-line separator

skip

number of lines to skip before reading data in the input file.

quote

the quote character used in the input file (defaults to \".)

prefix

A fully qualified path in the database's namespace, or NULL. This argument will be processed with dbUnquoteIdentifier(). If given the method will return all objects accessible through this prefix.

fail_if_missing

If FALSE, dbRemoveTable() succeeds if the table doesn't exist.

Value

A data.frame in the case of dbReadTable(); otherwise a logical indicating whether the operation was successful.

Note

The data.frame returned by dbReadTable() only has primitive data, e.g., it does not coerce character data to factors. Temporary tables are ignored for dbExistsTable() and dbListTables() due to limitations of the underlying C API. For this reason, a prior existence check is performed only before creating a regular persistent table; an attempt to create a temporary table with an already existing name will fail with a message from the database driver.

Examples

1
2
3
4
5
6
7
8
9
if (mariadbHasDefault()) {
con <- dbConnect(RMariaDB::MariaDB(), dbname = "test")

# By default, row names are written in a column to row_names, and
# automatically read back into the row.names()
dbWriteTable(con, "mtcars", mtcars[1:5, ], temporary = TRUE)
dbReadTable(con, "mtcars")
dbReadTable(con, "mtcars", row.names = FALSE)
}

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