I have of folder/directory of one of my colleagues full of sqlstatements. The folder is updated by him daily as well. I would like to document these sqlstatements for futures colleagues. However, I'm looking for a way to "automate" that process.
I thought about to use crontab once a week and run a R-Markdown file which automatically update the existing R-Markdown file.
My approach is as follows:
path = "c:/SQL_files/"
out.file<-""
file.names <- dir(path, pattern =".sql") # here I changed `.txt` to `.sql`
for(i in 1:length(file.names)){
file <- read.csv2.sql(file.names[i],header=TRUE, sep=";", stringsAsFactors=FALSE)
out.file <- rbind(out.file, file)
}
# That second approach comes very close, but just generates a `.txt` for the first
#`.sql` file in the directory with the error:
Error in match.names(clabs, names(xi)) :
names do not match previous names
where the files are:
[1] "c:/SQL_files/first.sql"
[2] "c:/SQL_files/second.sql"
path = "c:/SQL_files/"
out.file<-""
files <- list.files(path=path, pattern="*.sql", full.names=T, recursive=FALSE)
for(i in 1:length(files)){
file <- read.table(files[i],header=TRUE, sep=";", stringsAsFactors=FALSE)
out.file <- rbind(out.file, file)
}
The loop which extracts the content of the .sql doesnt seem to capture the content at all(in the first example) or captures just the content of the first file in the directory (second example). So my question. Is there a way to extract content from a SQL Text File (.sql)? Which may result in the .txt/.Rmd as follows: (but doesnt have to):
output of the first loop: my_sql_statement.sql
output of the second loop: Select * From Data
