Skip to content

Commit

Permalink
Add db populating scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
kopolindo committed Mar 24, 2018
1 parent 6368263 commit 0393995
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"fmt"
"database/sql"
"os"
_"github.com/mattn/go-sqlite3"
)

var database = ".local/vuln_db"

func main(){
//Check file existence
if _, err := os.Stat(database); err != nil {
fmt.Println("non esiste")
} else {
fmt.Println("esiste")
}
//Open db file
cveDB,err_opening := sql.Open("sqlite3",database)
if err_opening != nil{
fmt.Println("ERRORE IN FASE DI APERTURA:")
panic(err_opening)
}
//Create table query
createTest,err_preparing := cveDB.Prepare("CREATE TABLE IF NOT EXISTS people(id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT, CONSTRAINT identity UNIQUE (firstname, lastname))")
if err_preparing != nil{
fmt.Println("ERRORE IN FASE DI PREPARAZIONE QUERY")
panic(err_preparing)
}
createTest.Exec()
//Insert query
query,_ := cveDB.Prepare("INSERT OR IGNORE INTO people (firstname, lastname) VALUES (?, ?)")
query.Exec("alex","conti")
//Close db file
cveDB.Close()
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"encoding/json"
"fmt"
"io/ioutil"

//"./db"
"os"
"./nvd"
)
var testJson = "./.sources/nvd/test.json"
Expand Down

0 comments on commit 0393995

Please sign in to comment.