RODBC -ERROR:无法在mysql中插入SQLExecDirect语句

时间:2014-03-31 16:29:05

标签: mysql r rodbc

你好我使用RODBC和Mysql的插入语句有这个错误:

  

[2]“[RODBC]错误:无法将SQLExecDirect'插入test   (NumExpNumExecECGXYZTempParaSymp,   SympHRAmplSujet)VALUES(,,'NA / NA / NA /','   NA / NA / NA /','NA / NA / NA /','NA / NA / NA /','NA / NA / NA /','   NA / NA / NA /','NA / NA / NA /','NA / NA / NA /',,,);'“

我认为我的价值观是空的? 有人有想法,这是我第一次在R语言中使用OOP这是我的完整代码

 # generic function
setGeneric( name ="encoder",
def = function(x,i,j,value){standardGeneric("encoder")}
)


#### method ####
# encode a signal into string for storage
setMethod( f ="encoder",signature ="Signal",
def =function(x,i,j,value)
{
s <- as.character(x["val"][1])
for(i in 2:length(x["val"]))
{
s <- paste(s,x["val"][i],sep="/")
}
return(s)
}
)


####   Ecg class   ####
.Ecg.valid <- function(object){ return(TRUE)}
setClass (
Class ="Ecg",
contains =c("Signal"),
validity =.Ecg.valid
)
rm (.Ecg.valid )


####   Experimentation Class  ####
.Experimentation.valid <- function(object){ return(TRUE)}
setClass (
Class ="Experimentation",
representation= representation(numExp="numeric",numExec="numeric",ECG="Ecg",X="Signal",Y="Signal",Z="Signal",Temp="Signal",Ampl="numeric",ParaSymp="Signal",Symp="Signal",HR="Signal",Sujet="numeric"),
validity =.Experimentation.valid
)
rm (.Experimentation.valid )

#### Experimentation class Getter ####
setMethod( f ="[",signature ="Experimentation",
definition = function(x,i,j,drop){
switch(EXPR=i,
"numExp"={return(x@numExp)},
"numExec"={return(x@numExec)},
"ECG"={return(x@ECG)},
"X"={return(x@X)},
"Y"={return(x@Y)},
"Z"={return(x@Z)},
"Temp"={return(x@Temp)},
"Ampl"={return(x@Ampl)},
"Sujet"={return(x@Sujet)},
"ParaSymp"={return(x@ParaSymp)},
"Symp"={return(x@Symp)},
"HR"={return(x@HR)},
stop("this attribute does not existe!")
)
}
)

#### Load Experimentation from csv files####
loadExp <- function(Nom, NumExp, NumExec, sujet)
{
nomdata <- paste(Nom,"_data.csv",sep = "")
nomaut <- paste(Nom,"_aut.csv",sep = "")
nomrr <- paste(Nom,"_rr.csv", sep= "")

# Read data file
e <- read.csv(nomdata, col.names = c("ECG","X","Y","Z","Temp","Ampl"))
taille <- dim(e)[1]
s <- e[100:(taille-200),]
ecg <- new(Class="Ecg", val=as.numeric(unlist(s["ECG"])))
x <- new(Class="Signal", val=as.numeric(unlist(s["X"])))
y <- new(Class="Signal", val=as.numeric(unlist(s["Y"])))
z <- new(Class="Signal", val=as.numeric(unlist(s["Z"])))
temp <- new(Class="Signal", val=as.numeric(unlist(s["Temp"])))

# Read aut file
e2 <- read.csv(nomaut, col.names = c("ParaSymp","Symp"))
taille <- dim(e2)[1]
e2 <- e2[10:(taille-20),]
para <- new(Class="Signal", val=as.numeric(unlist(e2["ParaSymp"])))
symp <- new(Class="Signal", val=as.numeric(unlist(e2["Symp"])))

# Read rr file
e3 <- read.csv(nomrr, col.names = c("HR"))
taille <- dim(e3)[1]
e3 <- e3[10:(taille-20),]
hr <- new(Class="Signal", val=as.numeric(unlist(e3)))

return(new(Class="Experimentation", numExp=NumExp, numExec=NumExec,
ECG=ecg, X=x, Y=y, Z=z, Temp = temp, Ampl = s[1,"Ampl"], Sujet = sujet, ParaSymp = para, Symp = symp, HR = hr))

}





                ####   DBwin class   ####
                .DB_win.valid <- function(object){ return(TRUE)}
                setClass (
                Class ="DB_win",
                contains =c("DB"),
                validity =.DB_win.valid
                )
                rm (.DB_win.valid )



                setGeneric( name ="addExp",
                def = function(x, obj ){standardGeneric("addExp")}
                )

                # add Experimentation to data base
                setMethod( f ="addExp",signature =c(x="DB_win",obj="Experimentation"),
                def = function(x, obj)
{

                channel<- odbcConnect("RSQL",uid="root",pwd="toor")
                numExp <- obj["numExp"]

                numExec <- obj["numExec"]
                sujet <- obj["Sujet"]

                ecg <- encoder((obj["ECG"]))
                cat("*")
                x <- encoder((obj["X"]))
                cat("*")
                y <- encoder((obj["Y"]))
                cat("*")
                z <- encoder((obj["Z"]))
                cat("*")
                temp <- encoder((obj["Temp"]))
                cat("*")
                ampl <- (obj["Ampl"])
                cat("*")
                para <- encoder((obj["ParaSymp"]))
                cat("*")
                symp <- encoder((obj["Symp"]))
                cat("*")
                hr <- encoder((obj["HR"]))
                cat(" OK \n")
                requeteSql.valeur <- paste("'",ecg,"'",",",
                "'",x,"'",",",
                "'",y,"'",",",
                "'",z,"'",",",
                "'",temp,"'",",",
                "'",para,"'",",",
                "'",symp,"'",",",
                "'",hr,"'",",")
                requetesql <- paste("INSERT INTO `test` (`NumExp`, `NumExec`, `ECG`, `X`, `Y`, `Z`, `Temp`, `ParaSymp`, `Symp`, `HR`, `Ampl`, `Sujet`) VALUES (",numExp,",",numExec,", ",requeteSql.valeur, ampl,", ",sujet,");")

                #requetesql <- paste("INSERT INTO test (NumExp,NumExec,Sujet,ECG) values (",numExp,",2,3,",ecg,");")

                sqlQuery(channel,requetesql)

}

                ) 


to run it , i use this 2 lines

loadExp("C:\\Users\\admin\\Documents\\RDMZ\\test",1,1,1)
addExp(new("DB_win"),new("Experimentation"))

0 个答案:

没有答案