Something went wrong. Try again.
moderation music collection code, output, history etc.
Something went wrong. Try again.
moderation sql.go
1.4 kB · 69 lines
Go
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970package main
import ( "encoding/csv" "fmt" "log" "os")
func main() {
var output string
// open file, count rows, reset seek filer, err := os.Open("moderation.csv") if err != nil { fmt.Println("Error:", err) return } defer filer.Close()
output += "DROP TABLE moderation.cds;\n" output += "CREATE TABLE moderation.cds (Artist STRING(50), Title STRING(80), Year STRING(5), Media STRING(10), Format STRING(6), Label STRING(60), Label2 STRING(60), Serial STRING(30), Serial2 STRING(30), UPC STRING(20), Catalog STRING(20), ASIN STRING(10), URL STRING(100), Related STRING(100), Comment STRING(500), INDEX aty (Artist, Title, Year));\n" output += "INSERT INTO moderation.cds VALUES\n"
csvReader := csv.NewReader(filer) all, _ := csvReader.ReadAll() log.Println(len(all)) var celllength int
for i, line := range all { // log.Println(i) if i == 0 { celllength = len(line) - 1 log.Println(celllength) continue }
output += " ("
for x, cell := range line { // log.Println(cell) output += "'" + cell + "'" if x == celllength { continue } else { output += "," } }
output += ")"
if i == len(all)-1 { output += ";" } else { output += ", " } output += "\n" }
// persist to html filef, err := os.Create("moderation.sql") // For write access. if err != nil { log.Fatal(err) } filef.WriteString(output) filef.Close()
}