I'm trying to learn Go and am trying to scan rows into values which I will then assign to a struct. It seems like not all values are making it into the struct but I don't know why. Below is the full script. Running the query against the server actually returns results. However, when I test in the Scanned results, no data appears. In this case, the expected results would be "en" "en" Below is the script. I'm pretty sure I'm messing something up with my struct or with my types (or both).
package main
import (
"log"
_ "github.com/lib/pq"
"fmt"
"database/sql"
)
//local variables
var cnstr = "cnstr"
var dbdriver = "postgres"
//data structure
type WordData struct {
Word string
WordID int
Root string
RootID int
PartOfSpeech string
Case *string
Person *string
Gender *string
Number *string
Tense *string
Voice *string
Mood *string
Transliteration *string
Root_Definition *string
}
func main() {
db, _ := sql.Open(dbdriver, cnstr)
var word string
var wordid int
var root string
var rootid int
var partofspeech string
var caseval *string
var person *string
var gender *string
var number *string
var tense *string
var voice *string
var mood *string
var transliteration *string
var definition *string
if db != nil {
err := db.QueryRow(`select
morph as word,
morph_id as wordid,
lemma as root,
lemma_id as rootid,
part_of_speech as partofspeech,
"case",
person, gender, number, tense, voice, mood,
transliteration,
definition
from texts where sort_order = 65006`).Scan(&word,&wordid,&root,&rootid,&partofspeech,&caseval,&person,&gender,&number,&tense,&voice,&mood,&transliteration,&definition)
switch {
case err == sql.ErrNoRows:
log.Printf("No user with that ID.")
case err != nil:
log.Fatal(err)
default:
/*wd := new (WordData)
wd.Word = word
wd.WordID = wordid
wd.Root = root
wd.RootID = rootid
wd.PartOfSpeech = partofspeech
wd.Case = caseval
wd.Person = person
wd.Gender = gender
wd.Number = number
wd.Tense = tense
wd.Voice = voice
wd.Mood = mood
wd.Transliteration = transliteration
wd.Root_Definition = definition */
wd := WordData{
word,
wordid,
root,
rootid,
partofspeech,
caseval,
person,
gender,
number,
tense,
voice,
mood,
transliteration,
definition}
fmt.Printf("Printf: %s",wd.Transliteration)
fmt.Println(transliteration)
}
//or, comment out and use the other initializer type
}
db.Close()
}