edbQuery.RODBC_MySQL: Send and retrieve a query in a SQLite database (referenced by...

Description Usage Arguments Value Author(s) See Also Examples

Description

Send and retrieve a query in a SQLIte database (referenced by 'edb').

Usage

1
2
3
4
5
## S3 method for class 'RODBC_MySQL'
edbQuery(edb, statement, formatCol = NULL, 


    verbose = FALSE, ...)

Arguments

edb

An object of class 'edb', such as returned by edb.

statement

Single character string. SQL statement / SQL query to be passed

to link[RODBC]{sqlQuery}.

formatCol

If not NULL, a named list of functions to be applied to certain columns

after the data has been extracted from the database. The name of each list

item gives the column to process, and the value of each item gives the

function that must be applied. For instance

formatCol = list("DATE"=as.Date) will apply the function

as.Date to the column "DATE".

verbose

Single logical. If TRUE, information on what is done are output

on screen.

...

Additional parameters to be passed to link[RODBC]{sqlQuery}.

Value

The function returns the requested table.

Author(s)

Julien MOEYS <Julien.Moeys@mark.slu.se>

See Also

edb, link[RODBC]{sqlQuery}.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
library( "easyrodbcmysql" ) 











testMySQL <- FALSE # Set to TRUE to run some tests


                   # after modifying the edb() part below 


                   # with your own database setting











### Windows only:


if( (Sys.info()[[ "sysname" ]] == "Windows") & testMySQL ){ 


    


    ### Describe the database (NB: this is not a connection)


    myDb <- edb( 


        dbType       = "RODBC_MySQL", 


        dbSourceName = "nameOfODBCSource", # or any name you like


        dbName       = "nameOfDatabase", 


        dbLogin      = "yourUserName", 


        dbPwd        = "yourPassword", 


        dbHost       = "127.0.0.1", 


        dbPort       = 3306 


    )   #    


    


    


    


    ### Register the data source in ODBC 


    edbDataSource( myDb, verbose = TRUE ) 


    


    


    


    ### Use the database:


    


    ## Read data in a table in the database


    


    # Retrieve a table (data.frame style subsetting):


    myDb[ "WRB_SOIL_GROUP" ] 


    


    # Same operation, but with edbRead()


    edbRead( edb = myDb, tableName = "WRB_SOIL_GROUP" ) 


    


    # Retrieve part of a table (with row constrains)


    myDb[ "WRB_SOIL_GROUP", list("ABBREV" = c("AC","CR","PL")), 


        verbose = TRUE ] 


    


    # Same operation, but with edbQuery() 


    edbQuery( edb = myDb, statement = 


        "SELECT * FROM [WRB_SOIL_GROUP] WHERE [ABBREV] IN ('AC','CR','PL')" ) 


    


    ### Un-register the data source in ODBC (windows only)


    edbDataSource( myDb, trash = TRUE ) 


}   #

easyrodbcmysql documentation built on May 2, 2019, 5:51 p.m.