3.2.3.1.2 ore.sync関数を使用してプロキシ・オブジェクトを取得する例

次の例では、ore.sync関数の使用方法を示します。

この例ではまず、ore.exec関数を呼び出して、OML_USERデータベース・スキーマに存在する表を表すいくつかの表を作成します。次に、ore.syncを呼び出し、スキーマの3つの表を指定します。ore.syncの呼出しによりOML_USERスキーマにR環境を作成し、そのスキーマ内の指定された表に対するプロキシore.frameオブジェクトを作成します。この例では、現在の環境にあるore.frameプロキシ・オブジェクトをリストします。TABLE3表はスキーマ内に存在しますが、ore.frameプロキシ・オブジェクトは含まれません(このプロキシ・オブジェクトはore.sync呼出しに含められていないため)。

次に、query引数を使用してore.syncを呼び出して、指定されたSQL問合せに対するore.frameオブジェクトを作成します。再びore.frameオブジェクトをリストします。

次にore.syncを再び呼び出し、SHスキーマにR環境を作成し、そのスキーマ内の指定された表に対するプロキシ・オブジェクトをその環境内に作成します。この例では、ore.exists関数を呼び出して、指定された表が現在の環境に存在するかどうかを確認した後に、SH環境に存在するかどうかを確認します。SH環境内のRオブジェクトをリストします。

次に、ore.frameオブジェクトのQUERY1QUERY2およびTABLE4をOML_USER環境から削除します。最後に、環境内のプロキシ・オブジェクトを再びリストします。

ノート:

ore.rm関数の呼出しにより、TABLE4表のプロキシであるore.frameが環境から削除されます。スキーマから表は削除されません。

例3-10 ore.frameプロキシ・オブジェクトをR環境に追加するためのore.syncの使用方法

# After connecting to a database as OML_USER, create some tables.
ore.exec("CREATE TABLE TABLE1 AS SELECT * FROM dual")
ore.exec("CREATE TABLE TABLE2 AS SELECT * FROM dual")
ore.exec("CREATE TABLE TABLE3 AS SELECT * FROM dual")
ore.exec("CREATE TABLE TABLE4 AS SELECT * FROM dual")
# Create ore.frame objects for the specified tables.
ore.sync(table = c("TABLE1", "TABLE3", "TABLE4"))
# List the ore.frame proxy objects in the current environment.
ore.ls()
# Create ore.frame objects for the specified queries.
ore.sync(query = c("QUERY1" = "SELECT 0 X, 1 Y FROM dual",
                   "QUERY2" = "SELECT 1 X, 0 Y FROM dual"))
ore.ls()
# The OML_USER user has been granted SELECT permission on the tables in the 
# SH schema.
ore.sync("SH", table = c("CUSTOMERS", "SALES"))
# Find out if the CUSTOMERS ore.frame exists in the OML_USER environment.
ore.exists("CUSTOMERS")
# Find out if it exists in the SH environment.
ore.exists("CUSTOMERS", schema = "SH")
# List the ore.frame proxy objects in the SH environment.
ore.ls("SH")
# Remove the ore.frame objects for the specified objects.
ore.rm(c("QUERY1", "QUERY2", "TABLE4"))
# List the ore.frame proxy objects in the current environment again.
ore.ls()
この例のリスト
R> # After connecting to a database as OML_USER, create some tables.
R> ore.exec("CREATE TABLE TABLE1 AS SELECT * FROM dual")
R> ore.exec("CREATE TABLE TABLE2 AS SELECT * FROM dual")
R> ore.exec("CREATE TABLE TABLE3 AS SELECT * FROM dual")
R> ore.exec("CREATE TABLE TABLE4 AS SELECT * FROM dual")
R> # Create ore.frame objects for the specified tables.
R> ore.sync(table = c("TABLE1", "TABLE3", "TABLE4"))
R> # List the ore.frame proxy objects in the current environment.
R> ore.ls()
 [1] "TABLE1"     "TABLE3"     "TABLE4"
R> # Create ore.frame objects for the specified queries.
R> ore.sync(query = c("QUERY1" = "SELECT 0 X, 1 Y FROM dual",
+                     "QUERY2" = "SELECT 1 X, 0 Y FROM dual"))
R> ore.ls()
 [1] "QUERY1"     "QUERY2"     "TABLE1"     "TABLE3"     "TABLE4"
R> # The OML_USER user has been granted SELECT permission on the tables in the 
R> # SH schema.
R> ore.sync("SH", table = c("CUSTOMERS", "SALES"))
R> # Find out if the CUSTOMERS ore.frame exists in the OML_USER environment.
R> ore.exists("CUSTOMERS")
[1] FALSE
R> # Find out if it exists in the SH environment.
R> ore.exists("CUSTOMERS", schema = "SH")
[1] TRUE
R> # List the ore.frame proxy objects in the SH environment.
R> ore.ls("SH")
[1] "CUSTOMERS" "SALES"
R> # Remove the ore.frame objects for the specified objects.
R> ore.rm(c("QUERY1", "QUERY2", "TABLE4"))
R> # List the ore.frame proxy objects in the current environment again.
R> ore.ls()
 [1] "TABLE1"     TABLE3"