2 db_start <- function() {
3 drv <- dbDriver('SQLite')
4 con <- dbConnect(drv, dbname=file.path(root,'data/cran2deb.db'))
5 tables <- dbListTables(con)
6 if (!dbExistsTable(con,'sysreq_override')) {
7 dbGetQuery(con,paste('CREATE TABLE sysreq_override ('
8 ,' debian_name TEXT NOT NULL'
9 ,',r_pattern TEXT PRIMARY KEY NOT NULL'
12 if (!dbExistsTable(con,'license_override')) {
13 dbGetQuery(con,paste('CREATE TABLE license_override ('
14 ,' name TEXT PRIMARY KEY NOT NULL'
15 ,',accept INT NOT NULL'
18 if (!dbExistsTable(con,'license_hashes')) {
19 dbGetQuery(con,paste('CREATE TABLE license_hashes ('
20 ,' name TEXT NOT NULL'
21 ,',sha1 TEXT PRIMARY KEY NOT NULL'
27 db_stop <- function(con) {
31 db_quote <- function(text) {
32 return(paste('"',gsub('([^][[:alnum:]*?. ()<>:/=+-])','\\\\\\1',text),'"',sep=''))
35 db_sysreq_override <- function(sysreq_text) {
36 sysreq_text <- tolower(sysreq_text)
38 results <- dbGetQuery(con,paste(
39 'SELECT DISTINCT debian_name FROM sysreq_override WHERE'
40 ,db_quote(sysreq_text),'GLOB r_pattern'))
42 if (length(results) == 0) {
45 return(results$debian_name)
48 db_add_sysreq_override <- function(pattern,debian_name) {
49 pattern <- tolower(pattern)
50 debian_name <- tolower(debian_name)
52 results <- dbGetQuery(con,paste(
53 'INSERT OR REPLACE INTO sysreq_override'
54 ,'(debian_name, r_pattern) VALUES ('
55 ,' ',db_quote(debian_name)
56 ,',',db_quote(pattern)
61 db_sysreq_overrides <- function() {
63 overrides <- dbGetQuery(con,paste('SELECT * FROM sysreq_override'))
69 db_license_override_name <- function(name) {
72 results <- dbGetQuery(con,paste(
73 'SELECT DISTINCT accept FROM license_override WHERE'
74 ,db_quote(name),'= name'))
76 if (length(results) == 0) {
79 return(as.logical(results$accept))
82 db_add_license_override <- function(name,accept) {
84 message(paste('adding',name,'accept?',accept))
85 if (accept != TRUE && accept != FALSE) {
86 stop('accept must be TRUE or FALSE')
89 results <- dbGetQuery(con,paste(
90 'INSERT OR REPLACE INTO license_override'
91 ,'(name, accept) VALUES ('
93 ,',',as.integer(accept)
98 db_license_override_hash <- function(license_sha1) {
99 license_sha1 <- tolower(license_sha1)
101 results <- dbGetQuery(con,paste(
102 'SELECT DISTINCT accept FROM license_override'
103 ,'INNER JOIN license_hashes'
104 ,'ON license_hashes.name = license_override.name WHERE'
105 ,db_quote(license_sha1),'= license_hashes.sha1'))
107 if (length(results) == 0) {
110 return(as.logical(results$accept))
113 db_license_overrides <- function() {
115 overrides <- dbGetQuery(con,paste('SELECT * FROM license_override'))
116 hashes <- dbGetQuery(con,paste('SELECT * FROM license_hashes'))
118 # TODO: change accept from 0,1 into FALSE,TRUE
119 return(list(overrides=overrides,hashes=hashes))
122 db_add_license_hash <- function(name,license_sha1) {
123 name <- tolower(name)
124 license_sha1 <- tolower(license_sha1)
125 message(paste('adding hash',license_sha1,'for',name))
127 dbGetQuery(con,paste(
128 'INSERT OR REPLACE INTO license_hashes'
129 ,'(name, sha1) VALUES ('
131 ,',',db_quote(license_sha1)