例2-10にore.sync
関数の使用を示します。この例ではまず、ore.exec
関数を呼び出して、rquserのデータベース・スキーマに存在する表を表すいくつかの表を作成します。次に、ore.sync
を呼び出し、スキーマの3つの表を指定します。ore.sync
の呼出しによりrquserに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
オブジェクトのQUERY1
、QUERY2
およびTABLE4
をrquser環境から削除します。最後に、環境内のプロキシ・オブジェクトを再びリストします。
注意:
ore.rm
関数の呼出しにより、TABLE4表のプロキシであるore.frame
が環境から削除されます。スキーマから表は削除されません。
例2-10 ore.frameプロキシ・オブジェクトをR環境に追加するためのore.syncの使用方法
# After connecting to a database as rquser, 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 rquser 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 rquser 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()例2-10のリスト
R> # After connecting to a database as rquser, 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 rquser 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 rquser 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"