Subversion Repositories public iLand

Rev

Rev 1221 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1221 Rev 1222
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/R_analysis/sql_tools.R':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/R_analysis/sql_tools.R':
2
### SQL helping function
2
### SQL helping function
3
3
4
# we use the R library RSQLite for all database accesses
4
# we use the R library RSQLite for all database accesses
5
# look up the help for the avaiable features.
5
# look up the help for the avaiable features.
6
library(RSQLite)
6
library(RSQLite)
7
7
8
db.conn <- NA
8
db.conn <- NA
9
query<-function(query_str) {
9
query<-function(query_str) {
10
  res <- dbSendQuery(db.conn, query_str) 
10
  res <- dbSendQuery(db.conn, query_str) 
11
  data <- fetch(res, n=-1)
11
  data <- fetch(res, n=-1)
12
  if (dbGetException(db.conn)$errorNum>0)
12
  if (dbGetException(db.conn)$errorNum>0)
13
    print(dbGetException(db.conn)$errorMsg)
13
    print(dbGetException(db.conn)$errorMsg)
14
  dbClearResult(res)
14
  dbClearResult(res)
15
  data
15
  data
16
}
16
}
17
17
18
## species colors
18
## species colors
19
# species_colors<-c("red", "blue", "green", "gray")
19
# species_colors<-c("red", "blue", "green", "gray")
20
# names(species_colors)<-c("piab","fasy","lade", "pisy")
20
# names(species_colors)<-c("piab","fasy","lade", "pisy")
21
# species.color <- function(species) { 
21
# species.color <- function(species) { 
22
#   if (species %in% names(species_colors)) {
22
#   if (species %in% names(species_colors)) {
23
#     return (species_colors[species]); 
23
#     return (species_colors[species]); 
24
#   } else {
24
#   } else {
25
#     return ("black");
25
#     return ("black");
26
#   }
26
#   }
27
# }
27
# }
28
28
29
### query all tables from the output database
29
### query all tables from the output database
30
query("SELECT name FROM sqlite_master WHERE type='table'"); # use select * for more details!
30
query("SELECT name FROM sqlite_master WHERE type='table'"); # use select * for more details!