Write a Golang program that reads data from a CSV file and inserts it into an SQLite database. The program should also include functionality to query the database and display results based on user input. Additionally, ensure proper error handling and validation of user inputs.
PLAINFORMAT
package main

import (
	"database/sql"
	"encoding/csv"
	"fmt"
	"io"
	"log"
	"os"
	"strings"

	_ "github.com/mattn/go-sqlite3"
)

type Record struct {
	ID    int
	Name  string
	Email string
}

func main() {
	db, err := sql.Open("sqlite3", "./records.db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	createTable(db)

	file, err := os.Open("data.csv")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	reader := csv.NewReader(file)
	for {
		record, err := reader.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatal(err)
		}

		insertRecord(db, record[0], record[1])
	}

	queryAndDisplay(db)
}

func createTable(db *sql.DB) {
	sqlStmt := `
	CREATE TABLE IF NOT EXISTS records (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT);
	`
	_, err := db.Exec(sqlStmt)
	if err != nil {
		log.Printf("%q: %s\n", err, sqlStmt)
		return
	}
}

func insertRecord(db *sql.DB, name string, email string) {
	tx, err := db.Begin()
	if err != nil {
		log.Fatal(err)
	}
	stmt, err := tx.Prepare("INSERT INTO records(name, email) VALUES(?, ?)")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()

	_, err = stmt.Exec(name, email)
	if err != nil {
		log.Fatal(err)
	}
	tx.Commit()
}

func queryAndDisplay(db *sql.DB) {
	var input string
	fmt.Println("Enter a name to search for or type 'exit' to quit:")
	for {
		fmt.Scanln(&input)
		if strings.ToLower(input) == "exit" {
			break
		}

		rows, err := db.Query("SELECT id, name, email FROM records WHERE name LIKE ?", "%"+input+"%")
		if err != nil {
			log.Fatal(err)
		}
		defer rows.Close()

		var r Record
		found := false
		for rows.Next() {
			err = rows.Scan(&r.ID, &r.Name, &r.Email)
			if err != nil {
				log.Fatal(err)
			}
			fmt.Printf("ID: %d, Name: %s, Email: %s\n", r.ID, r.Name, r.Email)
			found = true
		}
		if !found {
			fmt.Println("No results found.")
		}
		err = rows.Err()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println("\nEnter a name to search for or type 'exit' to quit:")
	}
}