odb.read: Executes a reading SQL query in an ODB database (SELECT ...)

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/odb.read.r

Description

Executes an SQL query expecting an output through an "odb" connection.

Usage

1
2
  odb.read(odb, sqlQuery, stringsAsFactors = FALSE, check.names = FALSE,
    encode = TRUE, autoLogical = TRUE)

Arguments

odb

An ODB object, as produced by odb.open.

sqlQuery

A single character value, containing an unique SQL query to be executed.

stringsAsFactors

Single logical value : should character columns in the output be turned to factor columns or not.

check.names

Single logical value : should column names in the output be made syntactically valid by make.names or not.

encode

Single logical value : should character values be translated from UTF-8 charset (native charset for ODB files) to the locale one or not.

autoLogical

Single logical value : should logical-like columns be converted to logical or not. Notice this is a workaround, the conversion is not properly done by JDBC and the logical column type is guessed from the values.

Value

Returns a data.frame, whose content depends on the SQL query executed.

Note

To query databases built with OpenOffice or LibreOffice, it may be necessary to quote table and/or column names in sqlQuery, as the default behavior of the HSQL engine is to convert unquoted table and column names to uppercases.

Author(s)

Sylvain Mareschal

See Also

odb.write

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
  # New empty .odb file
  odbFile <- tempfile(fileext=".odb")
  odb.create(odbFile, overwrite="do")
  odb <- odb.open(odbFile)
  
  # New table
  SQL <- "CREATE TABLE fruits (
    name VARCHAR(6) PRIMARY KEY,
    color VARCHAR(32)
  )"
  odb.write(odb, SQL)
  
  # Data insertion
  dat <- data.frame(
    c("banana", "pear", "peach"),
    c("yellow", "yellow", "purple")
  )
  odb.insert(odb, "fruits", dat)
  
  # Read content
  print(odb.read(odb, "SELECT * FROM fruits"))
  
  # Writes to the file and closes the connection
  odb.close(odb, write=TRUE)

ODB documentation built on March 26, 2020, 7:46 p.m.