odb.write: Executes writing SQL queries in an ODB database (INSERT ...)

Description Usage Arguments Note Author(s) See Also Examples

View source: R/odb.write.r

Description

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

Usage

1
2
  odb.write(odb, sqlQueries, onError = c("warning", "stop"),
    progress = c("console", "file", "none"))

Arguments

odb

An ODB object, as produced by odb.open.

sqlQueries

Single or multiple character vector, with queries to be executed ordered in distinct elements. ";" query separation should not be used.

onError

Single character vector, defining how to handle SQL errors (using warning or stop). If "sqlQueries" contains more than one query, "stop" will prevent remaining queries to be executed, while "warning" won't.

progress

Single character vector, the type of progression to print when multiple queries are to be executed (See progress-class for further details).

Note

To query databases built with OpenOffice or LibreOffice, it may be necessary to quote table and/or column names in sqlQueries, 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.read

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
  # New empty .odb file
  odbFile <- tempfile(fileext=".odb")
  odb.create(odbFile, overwrite="do")
  odb <- odb.open(odbFile)
  
  # New table
  odb.write(odb, "CREATE TABLE fruits (name VARCHAR(6) PRIMARY KEY)")
  odb.insert(odb, "fruits", c("banana", "pear", "peach"))
  print(odb.tables(odb))
  
  # Manual insert
  odb.write(odb, "INSERT INTO fruits VALUES('apple')")
  print(odb.read(odb, "SELECT * FROM fruits"))
  
  # Remove table
  odb.write(odb, "DROP TABLE fruits")
  print(odb.tables(odb))
  
  # Writes to the file and closes the connection
  odb.close(odb, write=TRUE)

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