找回密码
 注册
查看: 4165|回复: 0

R语言 RODBC包 sqlSave()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-9-27 22:49:52 | 显示全部楼层 |阅读模式
sqlSave(RODBC)
sqlSave()所属R语言包:RODBC

                                        Write a Data Frame to a Table in an ODBC Database
                                         写一个数据框的ODBC数据库中的一个表

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Write or update a table in an ODBC database.
写出或更新的ODBC数据库中的一个表。


用法----------Usage----------


sqlSave(channel, dat, tablename = NULL, append = FALSE,
        rownames = TRUE, colnames = FALSE, verbose = FALSE,
        safer = TRUE, addPK = FALSE, typeInfo, varTypes,
        fast = TRUE, test = FALSE, nastring = NULL)

sqlUpdate(channel, dat, tablename = NULL, index = NULL,
          verbose = FALSE, test = FALSE, nastring = NULL,
          fast = TRUE)



参数----------Arguments----------

参数:channel
connection handle returned by odbcConnect.
连接返回的句柄odbcConnect。


参数:dat
a data frame.
一个数据框。


参数:tablename
character: a database table name accessible from the connected DSN.  If missing, the name of dat.
特点:从连接的DSN访问数据库表名。如果缺少,dat的名称。


参数:index
character.  Name(s) of index column(s) to be used.
字符。索引列的名称(s)的(S)以被使用。


参数:append
logical.  Should data be appended to an existing table?
逻辑。如果数据被追加到现有的表吗?


参数:rownames
either logical or character.  If logical, save the row names as the first column rownames in the table?  If character, the column name under which to save the rownames.
逻辑或字符。如果逻辑,保存该行的第一列rownames表中的名称?如果字符的列名保存的行名。


参数:colnames
logical: save column names as the first row of table?
逻辑:列名作为表的第一行吗?


参数:verbose
display statements as they are sent to the server?
显示报表,因为它们发送到服务器?


参数:safer
logical. If true, create a non-existing table but only allow appends to an existing table. If false, allow sqlSave to attempt to delete all the rows of an existing table, or to drop it.
逻辑。如果为true,创建一个不存在的表,但只允许追加到现有的表。如果为false,允许sqlSave试图删除一个现有的表中的所有行,或放弃它。


参数:addPK
logical.  Should rownames (if included) be specified as a primary key?
逻辑。行名(如果有)被指定为一个主键?


参数:typeInfo
optional list of DBMS datatypes.  Should have elements named "character", "double" and "integer".
DBMS数据类型的可选列表。应该有命名"character","double"和"integer"的元素。


参数:varTypes
an optional named character vector giving the DBMSs datatypes to be used for some (or all) of the columns if a table is to be created.
一个可选的指定的字符向量部分(或全部)的列用于给DBMS的数据类型,如果是要创建一个表。


参数:fast
logical.  If false, write data a row at a time.  If true, use a parametrized INSERT INTO or UPDATE query to write all the data in one operation.
逻辑。如果为false,将数据写入一个行一次。如果为true,使用一个参数化的INSERT INTO或UPDATE查询,写在一个操作中的所有数据。


参数:test
logical: if TRUE show what would be done, only.
逻辑:如果TRUE会做什么,只。


参数:nastring
optional character string to be used for writing NAs to the database.  See "Details".
可选的字符串,用于写NAS到数据库。请参阅“详细信息”。


Details

详细信息----------Details----------

sqlSave saves the data frame dat in the table tablename.  If the table exists and has the appropriate structure it is used, or else it is created anew.  If a new table is created, column names are remapped by removing any characters which are not alphanumeric or _, and the types are selected by consulting arguments varTypes and typeInfo, then looking the driver up in the database used by getSqlTypeInfo or failing that by interrogating sqlTypeInfo.
sqlSave保存的数据框dat表中的tablename。如果该表存在,并有适当的使用它,否则它创建一个新的结构。如果创建一个新表中,列名被重新映射删除任何字符是不是字母,数字或_,通过咨询论证和类型的选择varTypes和typeInfo,然后再寻找驱动程序在数据库中使用getSqlTypeInfo或未能通过询问sqlTypeInfo的。

If rownames = TRUE the first column of the table will be the row labels with colname rowname: rownames can also be a string giving the desired column name (see "Examples"). If colnames is true, the column names are copied into row 1.  This is intended for cases where case conversion alters the original column names and it is desired that they are retained.  Note that there are drawbacks to this approach: it presupposes that the rows will be returned in the correct order; not always valid.  It will also cause numeric columns to be returned as factors.
如果rownames = TRUE的第一列的表行标签与COLNAMErowname:rownames也可以是一个字符串,提供所需的列名(见“的例子”)。如果colnames是真实的,列名复制到第1行。这旨在用于大小写转换的情况下,改变的原始列名,它是期望的,它们被保留。请注意,这种方法也有缺点:它的前提是,将返回行以正确的顺序并不总是有效的。这也将导致数字要返回的列的因素。

Argument addPK = TRUE causes the row names to be marked as a primary key.  This is usually a good idea, and may allow database updates to be done.  However, the ODBC drivers for some DBMSs (e.g. Access) do not support primary keys, and earlier versions of the PostgreSQL ODBC driver generated internal memory corruption if this option is used.
参数addPK = TRUE导致行名称被标记为一个主键。这通常是一个好主意,并可能允许做数据库更新。然而,某些DBMS(如接入)的ODBC驱动程序不支持主键和早期版本的PostgreSQL的ODBC驱动程序产生的内部记忆体损坏,如果使用此选项。

sqlUpdate updates the table where the rows already exist.  Data frame dat should contain columns with names that map to (some of) the columns in the table.  It also needs to contain the column(s) specified by index which together identify the rows to be updated.  If index = NULL, the function tries to identify such columns.  First it looks for a primary key for the table, then for the column(s) that the database regards as the optimal for defining a row uniquely (these are returned by sqlColumns(special =   TRUE): if this returns a pseudo-column it cannot be used as we do not have values for the rows to be changed).  Finally, the row names are used if they are stored as column "rownames" in the table.
sqlUpdate更新表中的行已经存在。数据框dat应包含列名映射到一些表中的列。它也需要到指定的index共同确定要更新的行包含列(S)。如果index = NULL,试图找出这样的列。首先,它查找表中的主键,然后该数据库被视为唯一的最佳定义行(这些返回sqlColumns(special =   TRUE):如果此命令将返回一个伪列,它不能为列(S)作为我们没有改变)的行的值。最后,该行的名称用于如果它们存储作为列"rownames"表中。

When fast = TRUE, NAs are always written as SQL nulls in the database, and this is also the case if fast = FALSE and nastring = NULL (its default value).  Otherwise nastring gives the character string to be sent to the driver when NAs are encountered: for all but the simplest applications it will be better to prepare a data frame with non-null missing values already substituted.
当fast = TRUE,NAs的写在数据库中的SQL空值,这也是fast = FALSE和nastring = NULL(它的默认值)。否则nastring给出的字符串被发送到驱动程序时NAs的遭遇:为所有,但最简单的应用,将更好地准备一个数据框与非空的缺失值已经取代。

If fast = FALSE all data are sent as character strings. If fast = TRUE, integer and double vectors are sent as types SQL_C_SLONG and SQL_C_DOUBLE respectively.  Some drivers seem to require fast = FALSE to send other types, e.g. datetime.  SQLite's approach is to use the data to determine how it is stored, and this does not work well with fast = TRUE.
如果fast = FALSE的所有数据将作为字符串。如果fast = TRUE,整数和双向量类型SQL_C_SLONG和SQL_C_DOUBLE分别发送。有些司机似乎需要fast = FALSE发送其他类型,例如datetime。 SQLite的方法是使用数据,以确定它是如何存储的,这并不工作,以及与fast = TRUE。

If tablename contains . and neither catalog nor schema is supplied, an attempt is made to interpret <VAR>qualifier</VAR>.<VAR>table</VAR> names as table <VAR>table</VAR> in schema <VAR>qualifier</VAR> (and for MySQL "schema" means "database").  (This can be suppressed by opening the connection with interpretDot = FALSE.)
如果tablename包含.也不catalog,也不schema提供,试图解释<VAR>qualifier</VAR>.<VAR>table</VAR>如表<VAR>table</VAR>的架构名称 <VAR>qualifier</VAR>(和MySQL的架构的方式数据库)。 (这可以抑制由打开连接interpretDot = FALSE。)


值----------Value----------

1 invisibly for success (and failures cause errors).
1看不见的(成功和失败会导致错误)。


警告----------Warning----------

sqlSave(safer = FALSE) uses the "great white shark" method of testing tables (bite it and see).  The logic will unceremoniously DROP the table and create it anew with its own choice of column types in its attempt to find a writable solution. test = TRUE will not necessarily predict this behaviour. Attempting to write indexed columns or writing to pseudo-columns are less obvious causes of failed writes followed by a DROP.  If your table structure is precious it is up to you back it up.
sqlSave(safer = FALSE)使用方法测试表“大白鲨”(咬它,看到的)。逻辑也会毫不客气地DROP表,并重新创建它自己选择的列类型在试图找到一个可写的解决方案。 test = TRUE将不一定预测这种行为。试图写入索引的列或书面形式向伪列,是不那么明显的原因,没有写的DROP。如果你的表结构是珍贵的,它是先对其进行备份。


(作者)----------Author(s)----------



Michael Lapsley and Brian Ripley




参见----------See Also----------

sqlFetch, sqlQuery, odbcConnect, odbcGetInfo
sqlFetch,sqlQuery,odbcConnect,odbcGetInfo


实例----------Examples----------


## Not run: [#不运行:]
channel <- odbcConnect("test")
sqlSave(channel, USArrests, rownames = "state", addPK=TRUE)
sqlFetch(channel, "USArrests", rownames = "state") # get the lot[得到了很多]
foo <- cbind(state=row.names(USArrests), USArrests)[1:3, c(1,3)]
foo[1,2] <- 222
sqlUpdate(channel, foo, "USArrests")
sqlFetch(channel, "USArrests", rownames = "state", max = 5)
sqlDrop(channel, "USArrests")
close(channel)


转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2024-11-25 13:51 , Processed in 0.022527 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表