Cookbook ODBC: RequeteODBCwhere.r

File RequeteODBCwhere.r, 2.6 KB (added by cedric, 15 years ago)

Class for querying using where clause and and clause

Line 
1# Nom fichier :        RequeteODBCwhere (classe)
2#' @title RequeteODBCwhere class
3#' @note Inherits from RequeteODBC
4#' the syntax is where="WHERE ..."
5#' and =vector("AND...","AND...")
6#' order_by="ORDER BY.."
7#' @author Cedric Briand \email{cedric.briand@@lavilaine.com}
8#' @slot select="character"
9#' @slot where="character"
10#' @slot and="vector"
11#' @slot order_by="character"
12#' @slot baseODBC="vector"      (inherited from ConnexionODBC)
13#' @slot silent="logical"       (inherited from ConnexionODBC)
14#' @slot etat="character"       (inherited from ConnexionODBC)
15#' @slot connexion="ANY"        (inherited from ConnexionODBC)
16#' @slot sql="character"        (inherited from RequeteODBC)
17#' @slot query="data.frame"     (inherited from RequeteODBC)
18#' @slot open="logical"         (inherited from RequeteODBC)
19#' @example objet=new("RequeteODBCwhere")
20#' @exportClass
21setClass(Class="RequeteODBCwhere",
22                representation= representation(select="character",where="character",and="vector",order_by="character"),
23                prototype = list(silent=TRUE,open=FALSE),contains="RequeteODBC")
24
25#' transformation method from RequeteODBCwhere to RequeteODBC
26#' @returnType S4 object
27#' @return An object of class RequeteODBC
28setAs("RequeteODBCwhere","RequeteODBC",function(from,to){
29                        requeteODBC=new("RequeteODBC")
30                        requeteODBC@sql=paste(from@select,from@where,paste(from@and,sep=" "),from@order_by,";",sep=" ")
31                        requeteODBC@baseODBC=from@baseODBC
32                        requeteODBC@silent=from@silent
33                        # other slots will be filled in by connect     
34                        return(requeteODBC)
35                })
36#' connect method loads a request to the database and returns either an error or a data.frame
37#' @note method modified from v0.2.1240 to use the connect method of the mother class
38#' @returnType S4 object
39#' @return An object of class RequeteODBCwhere
40#' @author Cedric Briand \email{cedric.briand@@lavilaine.com}
41#' @exportMethod
42#' @example
43#' objet<-new("RequeteODBCwhere")
44#' objet@baseODBC<-baseODBC
45#' objet@sql<- "select * from t_lot_lot"
46#' objet@where<-"WHERE lot_tax_code='2038'"
47#' objet@and<-c("AND lot_std_code='CIV'","AND lot_ope_identifiant<1000")
48#' objet@order_by<-"ORDER BY lot_identifiant"
49#' objet<-connect(objet)
50setMethod("connect",signature=signature("RequeteODBCwhere"),definition=function(objet) {
51                        requeteODBC=as(objet,"RequeteODBC")
52                        requeteODBC=connect(requeteODBC) # utilise la méthode de la classe mère
53                        # récupère au sein de l'objet les éléments de requeteODBC
54                        objet@sql=requeteODBC@sql
55                        objet@connexion=requeteODBC@connexion
56                        objet@query=requeteODBC@query
57                        objet@etat=requeteODBC@etat
58                        return(objet)
59                })