mercredi 2 septembre 2015

Connecting to SQLite Database in Go

I try to connect to my SQLite Database in Go using the "database/sql" package. (SearchResult is a struct to save the Results and marshal them later)

func ReturnResultFromSearch(sqlString string, databaseID string)([]SearchResult){ 
    var result []SearchResult
    db, err := sql.Open("sqlite3", "./comments/"+databaseID+".db") 
    if err != nil {
        fmt.Println("Can't access Database: ", err)
    }
    defer db.Close()
    rows, err := db.Query(sqlString)    
    if err != nil {
        fmt.Println("SQL-Error: ", err)
    }
    defer rows.Close()

    for rows.Next(){
        //Scan ResultSet
    }   
    return result
}

When running this function I get an error:

SQL-Error: unable to open database file

Doing the same with db.QueryRow(sqlString) returns a Row and a valid connection but I need the complete ResultSet.

Aucun commentaire:

Enregistrer un commentaire