odb.comments: Gets or sets column comments in an ODB database

Description Usage Arguments Details Value Note Author(s) Examples

View source: R/odb.comments_GET.r

Description

This function allows comment manipulation into OpenOffice Base databases, through an odb connection.

Usage

1
2
  odb.comments(odb, tableNames = NULL, columnNames = NULL, simplify = TRUE)
  odb.comments(odb, tableNames, columnNames) <- value

Arguments

odb

An ODB object, as produced by odb.open.

tableNames

Character vector naming tables to search comments in. See the 'Details' section.

columnNames

Character vector naming columns to search comments in. See the 'Details' section.

simplify

Single logical value, whether to simplify returns. See the 'Value' section

value

Character vector, the comments to store.

Details

tableNames, columnNames and value can be considered as columns from a same data.frame: the first comment considered will be the comment on the first columnNames for the first tableNames, and so on. Vectors are repeated to achieve same lengths if necessary.

The NULL value can be used for tableNames and columnNames in the first syntax, with the meaning of "all possible values". See the 'Examples' section.

Value

The first syntax returns a list of character vectors. Names in the list are table names, names in vectors are column names. Only tables and columns with comments are present in the results.

With simplify set to TRUE, a character vector is directly returned (without embedding list) when a single tableNames is interrogated, and column names are skipped if a single tableNames / columnNames couple is provided.

Note

Comments on non-existing tables or columns can be manipulated as well, as there is no link between the comment storage engine and the database itself. Keep in mind these comments are stored in the .odb file, not the database itself.

Comments can also be added manually from OpenOffice while creating a table.

Author(s)

Sylvain Mareschal

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
40
41
  # New empty .odb file
  odbFile <- tempfile(fileext=".odb")
  odb.create(odbFile, overwrite="do")
  ODB <- odb.open(odbFile)
  
  # New tables
  SQL <- c(
    "CREATE TABLE fruits (
      name VARCHAR(6) PRIMARY KEY,
      color VARCHAR(32)
      )",
    "CREATE TABLE vegetables (
      name VARCHAR(6) PRIMARY KEY,
      color VARCHAR(32)
      )"
    )
  odb.write(ODB, SQL)
  
  # Setting a single comment
  odb.comments(ODB,
    tableNames = "fruits",
    columnNames = "name"
  ) <- "Fruit names"
  print(odb.comments(ODB))
  
  # Setting two comments in the same table
  odb.comments(ODB,
    tableNames = "fruits",
    columnNames = c("name", "color")
  ) <- "Fruit columns"
  print(odb.comments(ODB))
  
  # Setting two distinct comments
  odb.comments(ODB,
    tableNames = c("fruits", "vegetables"),
    columnNames = c("name", "color")
  ) <- c("Fruit names", "Vegetable colors")
  print(odb.comments(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.