dbq: query the database

dbqR Documentation

query the database

Description

query the database using an user-defined connection or a temp connection based on saved credentials.

Usage

dbq(con, q, geom, ...)

## S4 method for signature 'MySQLConnection,character,ANY'
dbq(con, q, enhance = FALSE, asUTC = TRUE, ...)

## S4 method for signature 'MariaDBConnection,character,ANY'
dbq(con, q, asUTC = TRUE, ...)

## S4 method for signature 'missing,character,ANY'
dbq(q, enhance = FALSE, ...)

## S4 method for signature 'MySQLConnection,character,character'
dbq(con, q, geom = "SHAPE", tableNam, ...)

Arguments

con

a connection object returned by dbcon

q

a query string. credentials are stored on disk.

geom

name of the geometry column. Default to 'SHAPE'

...

pass to dbGetQuery

enhance

FALSE. if TRUE then enhanceOutput() is applied by reference on the output.

asUTC

for MariaDBConnection. not yet implemented

tableNam

name of the table containing the geometry.

Value

a data.frame or a Spatial*DataFrame (spatial_MySQL) for a SELECT query, or NULL for non-SELECT queries.

See Also

saveCredentials,dbcon

Examples

## Not run: 
# A connection is made and used by dbq
 con = dbcon('testuser', host =  '127.0.0.1', pwd =  'cs')
 d1 = dbq(con, 'SELECT * from tests.t1')
 d2 = dbq(con, 'SELECT * from tests.t1', enhance = TRUE)

# A temp. connection is made and closed once the data is retrieved
dbq(q = 'select now()', user = 'testuser', host =  '127.0.0.1', pwd =  'cs') 
dbq(q = 'select now()', user = 'testuser',host =  '127.0.0.1', pwd =  'cs',  
	enhance = TRUE)%>% print

# spatial return
s = dbq(con, q = 'select * from tests.t3', geom = 'SHAPE')
s = dbq(con, q = 'select SHAPE from tests.t3', geom = 'SHAPE')
s = dbq(con, q = 'select * from tests.t2', geom = 'SHAPE')


## End(Not run)

mpio-be/sdb documentation built on Nov. 18, 2022, 12:24 a.m.