本文整理汇总了Golang中database/sql.NullString类的典型用法代码示例。如果您正苦于以下问题:Golang NullString类的具体用法?Golang NullString怎么用?Golang NullString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NullString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SaveThing
func (w *DatabaseWorld) SaveThing(thing *Thing) (ok bool) {
tabletext, err := json.Marshal(thing.Table)
if err != nil {
log.Println("Error serializing table data for thing", thing.Id, ":", err.Error())
return false
}
var parent sql.NullInt64
if thing.Parent != 0 {
parent.Int64 = int64(thing.Parent)
parent.Valid = true
}
var owner sql.NullInt64
if thing.Owner != 0 && thing.Type.HasOwner() {
owner.Int64 = int64(thing.Owner)
owner.Valid = true
}
var program sql.NullString
if thing.Program != nil {
program.String = thing.Program.Text
program.Valid = true
}
// TODO: save the allow list
_, err = w.db.Exec("UPDATE thing SET name = $1, parent = $2, owner = $3, adminlist = $4, denylist = $5, tabledata = $6, program = $7 WHERE id = $8",
thing.Name, parent, owner, thing.AdminList, thing.DenyList,
types.JsonText(tabletext), program, thing.Id)
if err != nil {
log.Println("Error saving a thing", thing.Id, ":", err.Error())
return false
}
return true
}
开发者ID:natmeox,项目名称:mess,代码行数:33,代码来源:world.go
示例2: TestStringOrNull
func TestStringOrNull(t *testing.T) {
var (
nullString sql.NullString
value driver.Value
err error
)
// When the string is empty
nullString = StringOrNull("")
// nullString.Valid should be false
assert.False(t, nullString.Valid)
// nullString.Value() should return nil
value, err = nullString.Value()
assert.Nil(t, err)
assert.Nil(t, value)
// When the string is not empty
nullString = StringOrNull("foo")
// nullString.Valid should be true
assert.True(t, nullString.Valid)
// nullString.Value() should return the string
value, err = nullString.Value()
assert.Nil(t, err)
assert.Equal(t, "foo", value)
}
开发者ID:chenhougen,项目名称:go-oauth2-server,代码行数:29,代码来源:util_test.go
示例3: listAllConnections
func (database Database) listAllConnections() (res DbUsersWithConnections) {
res = make(DbUsersWithConnections)
rows, err := database.db.Query(`
-- Left join because we want users without connections as well
SELECT u1.id, u1.username, u2.id, u2.username FROM
user AS u1 LEFT JOIN connection ON u1.id = connection.fromUser
LEFT JOIN user AS u2 ON u2.id = connection.toUser
ORDER BY u1.id
`)
checkErr(err)
defer rows.Close()
for rows.Next() {
var fromUser User
var toUsername sql.NullString
var toId sql.NullInt64
err := rows.Scan(&fromUser.Id, &fromUser.Username, &toId, &toUsername)
checkErr(err)
if toId.Valid {
// this user has at least one connection, unpack the nullable values
toIdValue, _ := toId.Value()
toUsernameValue, _ := toUsername.Value()
res[fromUser] = append(res[fromUser], User{toIdValue.(int64), toUsernameValue.(string)})
} else {
// this user doesn't have any connections
res[fromUser] = []User{}
}
}
return res
}
开发者ID:rutchkiwi,项目名称:go-rest-api,代码行数:31,代码来源:db.go
示例4: Scan
// Scan implements the Scanner interface.
func (ns *ByteSlice) Scan(value interface{}) error {
n := sql.NullString{String: base64.StdEncoding.EncodeToString(ns.ByteSlice)}
err := n.Scan(value)
//ns.Float32, ns.Valid = float32(n.Float64), n.Valid
ns.ByteSlice, err = base64.StdEncoding.DecodeString(n.String)
ns.Valid = n.Valid
return err
}
开发者ID:ryanzec,项目名称:going,代码行数:9,代码来源:byte_slice.go
示例5: checkStringForNull
func checkStringForNull(eventStr string, event *sql.NullString) {
if len(eventStr) == 0 {
event.Valid = false
} else {
event.String = eventStr
event.Valid = true
}
}
开发者ID:Qlean,项目名称:silvia,代码行数:8,代码来源:postgres.go
示例6: Scan
func (this *ERole) Scan(value interface{}) error {
var x sql.NullString
err := x.Scan(value)
if !x.Valid || err != nil {
return err
}
*this = ERole(x.String)
return nil
}
开发者ID:quintans,项目名称:taskboard,代码行数:10,代码来源:0_ERole.go
示例7: Scan
func (this *Str) Scan(value interface{}) error {
var s sql.NullString
err := s.Scan(value)
if !s.Valid || err != nil {
return err
}
*this = Str(s.String)
return nil
}
开发者ID:quintans,项目名称:toolkit,代码行数:10,代码来源:Types.go
示例8: main
func main() {
c := configFromFile()
s := slack.New(c.SlackToken)
db, err := sql.Open("mysql", c.Datasource)
if err != nil {
log.Fatal(err)
}
defer db.Close()
err = updateChannels(s, db)
if err != nil {
log.Fatal(err)
}
err = updateUsers(s, db)
if err != nil {
log.Fatal(err)
}
rows, err := db.Query("SELECT id, name, latest FROM channels")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var id string
var name string
var latest sql.NullString
if err := rows.Scan(&id, &name, &latest); err != nil {
log.Fatal(err)
}
fmt.Printf("import history: #%s\n", name)
if !latest.Valid {
latest.String = ""
}
l, err := addChannelHistory(s, db, id, latest.String)
if err != nil {
log.Fatal(err)
}
if l != "" {
_, err = db.Exec(`UPDATE channels SET latest = ? WHERE id = ?`, l, id)
if err != nil {
log.Fatal(err)
}
}
}
}
开发者ID:kan,项目名称:slack-door,代码行数:49,代码来源:crawler.go
示例9: main
func main() {
db, err := sqlx.Connect("mysql", "root:[email protected](localhost:3306)/bookszilla?parseTime=true")
if err != nil {
log.Fatalln(err)
}
db.Ping()
for i := 1; i <= 1000; i++ {
url := "http://wmate.ru/ebooks/book" + strconv.Itoa(i) + ".html"
response, err := http.Get(url)
println(url + " " + response.Status)
if err != nil {
fmt.Printf("%s", err)
// os.Exit(1)
} else if response.StatusCode == 200 {
defer response.Body.Close()
doc, err := goquery.NewDocumentFromResponse(response)
if err != nil {
log.Fatal(err)
}
doc.Find("article.post").Each(func(i int, s *goquery.Selection) {
title := s.Find("h1").Text()
println(title)
// author := s.Find("ul.info li").Eq(2).Find("em").Text()
// println(author)
var desctiption sql.NullString
desc := ""
s.Find("p").Each(func(j int, sp *goquery.Selection) {
desc += strings.TrimSpace(sp.Text()) + "\n"
})
if len(desc) > 0 {
desctiption.Scan(desc)
}
// println(desctiption)
sql := "INSERT INTO `books` (`name`, `description`) VALUES (?, ?);"
db.Exec(sql, title, desctiption)
})
}
}
}
开发者ID:alexeyreznikov,项目名称:parser,代码行数:48,代码来源:main.go
示例10: Value
func (h Hstore) Value() (driver.Value, error) {
hstore := hstore.Hstore{Map: map[string]sql.NullString{}}
if len(h) == 0 {
return nil, nil
}
for key, value := range h {
var s sql.NullString
if value != nil {
s.String = *value
s.Valid = true
}
hstore.Map[key] = s
}
return hstore.Value()
}
开发者ID:Rking788,项目名称:hotseats-api,代码行数:16,代码来源:postgres.go
示例11: Login
// Input: email string, password string
// Output:
// - Success: session string
// - Failed: {}
func Login(w http.ResponseWriter, r *http.Request) {
var email sql.NullString
email.Scan(r.FormValue("email"))
password := r.FormValue("password")
user := models.User{Email: email, Password: password}
if !repository.Login(&user) {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte(`{"error":"Mat khau hoac email khong dung"}`))
return
}
createUserToken(&user)
repository.UpdateUser(&user)
json.NewEncoder(w).Encode(user)
}
开发者ID:khaiql,项目名称:instagram-go,代码行数:22,代码来源:user.go
示例12: TestNullTypeString
func TestNullTypeString(t *testing.T) {
var b Sqlizer
var name sql.NullString
b = Eq{"name": name}
sql, args, err := b.ToSql()
assert.NoError(t, err)
assert.Empty(t, args)
assert.Equal(t, "name IS NULL", sql)
name.Scan("Name")
b = Eq{"name": name}
sql, args, err = b.ToSql()
assert.NoError(t, err)
assert.Equal(t, []interface{}{"Name"}, args)
assert.Equal(t, "name = ?", sql)
}
开发者ID:collinglass,项目名称:squirrel,代码行数:19,代码来源:expr_test.go
示例13: Scan
func (s *scanner) Scan(src interface{}) error {
var err error
switch s.value.Type().Kind() {
case reflect.Struct:
nt := mysql.NullTime{}
err := nt.Scan(src)
if err != nil {
return err
}
s.value.Set(reflect.ValueOf(nt.Time))
case reflect.Bool:
nb := sql.NullBool{}
err := nb.Scan(src)
if err != nil {
return err
}
s.value.SetBool(nb.Bool)
case reflect.String:
ns := sql.NullString{}
err = ns.Scan(src)
if err != nil {
return err
}
s.value.SetString(ns.String)
case reflect.Int64:
ni := sql.NullInt64{}
err = ni.Scan(src)
if err != nil {
return err
}
s.value.SetInt(ni.Int64)
case reflect.Float64:
ni := sql.NullFloat64{}
err = ni.Scan(src)
if err != nil {
return err
}
s.value.SetFloat(ni.Float64)
}
return nil
}
开发者ID:hypertornado,项目名称:prago,代码行数:42,代码来源:struct_scanners.go
示例14: main
func main() {
db, err := sql.Open("postgres", "user=postgres password=pass dbname=mecab sslmode=disable")
checkErr(err)
//データの検索
//rows, err := db.Query("SELECT * FROM words LIMIT 3")
rows, err := db.Query("SELECT * FROM words WHERE first_char IS NULL")
checkErr(err)
for rows.Next() {
var surface string
var original string
var reading string
var first_c sql.NullString
var last_c sql.NullString
err = rows.Scan(&surface, &original, &reading, &first_c, &last_c)
checkErr(err)
/*
fmt.Println(surface)
fmt.Println(original)
fmt.Println(reading)
fmt.Println(reading[0:3])
fmt.Println(reading[len(reading)-3 : len(reading)])
fmt.Println(first_c)
fmt.Println(last_c)
*/
first_c.String = reading[0:3]
last_c.String = reading[len(reading)-3 : len(reading)]
//データの更新
stmt, err := db.Prepare("update words set first_char=$1, last_char=$2 where original=$3")
checkErr(err)
first_c.Valid = true
last_c.Valid = true
_, err = stmt.Exec(first_c.String, last_c.String, original)
checkErr(err)
/*
affect, err := res.RowsAffected()
checkErr(err)
fmt.Println(affect)
*/
}
db.Close()
fmt.Println("finish")
}
开发者ID:tom--bo,项目名称:go_postgres,代码行数:49,代码来源:prepare_firstlast.go
示例15: FRES
func (b *BaseConditionQuery) FRES(value interface{}) interface{} {
if (*b.SqlClause).IsAllowEmptyStringQuery() {
return value
}
switch value.(type) {
case sql.NullString:
var nstr sql.NullString = value.(sql.NullString)
if nstr.Valid && nstr.String == "" {
nstr.Valid = false
}
return nstr
case *sql.NullString:
var nstr *sql.NullString = value.(*sql.NullString)
if nstr.Valid && nstr.String == "" {
nstr.Valid = false
}
return nstr
case string:
var str string = value.(string)
if str == "" {
var null sql.NullString
null.Valid = false
return null
}
case *string:
var strx string = *value.(*string)
if strx == "" {
var null sql.NullString
null.Valid = false
return null
}
default:
panic("This type not supported :" + GetType(value))
}
return value
}
开发者ID:mikeshimura,项目名称:go-dbflute-example,代码行数:36,代码来源:conditionQuery.go
示例16: CheckAndComvertEmptyToNull
func (b *BasePmb) CheckAndComvertEmptyToNull(value interface{}) interface{} {
if DBCurrent_I.EmptyStringParameterAllowed {
return value
}
switch value.(type) {
case sql.NullString:
var nstr sql.NullString = value.(sql.NullString)
if nstr.Valid && nstr.String == "" {
nstr.Valid = false
}
return nstr
case *sql.NullString:
var nstr *sql.NullString = value.(*sql.NullString)
if nstr.Valid && nstr.String == "" {
nstr.Valid = false
}
return nstr
case string:
var str string = value.(string)
if str == "" {
var null sql.NullString
null.Valid = false
return null
}
case *string:
var strx string = *value.(*string)
if strx == "" {
var null sql.NullString
null.Valid = false
return null
}
default:
panic("This type not supported :" + GetType(value))
}
return value
}
开发者ID:mikeshimura,项目名称:go-dbflute-example,代码行数:36,代码来源:pmb.go
示例17: GenerateTestSuiteHandler
func GenerateTestSuiteHandler(w http.ResponseWriter, r *http.Request) {
DontCache(&w)
// Generate a test suite based on the category IDs given by the user: of the
// category IDs that are live and have a route back to the "root" of the
// test suite hierarchy based on the category IDs given, this generates the
// JavaScript code necessary to add the categories and tests to the test
// framework running in the user's browser
// Sanity-check for given category IDs: it must be a comma-delimited list of
// integers, or * (which denotes all live categories in the category table)
categoryIDs := mux.Vars(r)["catids"]
if categoryIDs == "*" {
// It's enough just to find the top-level categories here: the recursive
// query we run below will find all of the live child categories we also
// need to include in the test suite execution
if err := db.QueryRow("SELECT '{' || array_to_string(array_agg(id),',') || '}' AS categories FROM category WHERE parent IS NULL AND live = true").Scan(&categoryIDs); err != nil {
log.Panicf("Unable to get list of top-level categories: %s\n", err)
}
} else if regexp.MustCompile("^[0-9]+(,[0-9]+)*$").MatchString(categoryIDs) {
categoryIDs = "{" + categoryIDs + "}"
} else {
log.Panic("Malformed category IDs supplied")
}
w.Header().Set("Content-Type", "text/javascript")
fmt.Fprintln(w, "// Automatically-generated BrowserAudit test suite\n")
// The table returned by this query is sorted by the order in which the
// categories and then tests are to be executed; the hierarchy is correct by
// the time it gets here, and so can be printed line-by-line with no further
// processing of the resulting table
// Suggestion for using WITH RECURSIVE courtesy of:
// http://blog.timothyandrew.net/blog/2013/06/24/recursive-postgres-queries/
// (note: WITH RECURSIVE is Postgres-specific)
rows, err := db.Query(`
WITH RECURSIVE touched_parent_categories AS (
SELECT unnest($1::int[]) AS id
UNION
SELECT category.parent AS id FROM category, touched_parent_categories tpc WHERE tpc.id = category.id AND category.parent IS NOT NULL
), touched_child_categories AS (
SELECT unnest($1::int[]) AS id
UNION
SELECT category.id FROM category, touched_child_categories tcc WHERE category.parent = tcc.id
), touched_categories AS (
SELECT id FROM touched_parent_categories
UNION
SELECT id FROM touched_child_categories
), hierarchy AS (
(
SELECT 'c' as type, id, title, description, NULL::test_behaviour AS behaviour, NULL::varchar AS test_function, NULL::smallint AS timeout, parent, array[execute_order] AS execute_order
FROM category
WHERE parent IS NULL AND live = true AND id IN (SELECT id FROM touched_categories)
) UNION (
SELECT e.type, e.id, e.title, e.description, e.behaviour, e.test_function, e.timeout, e.parent, (h.execute_order || e.execute_order)
FROM (
SELECT 't' as type, id, title, NULL::varchar AS description, behaviour, test_function, timeout, parent, execute_order
FROM test
WHERE live = true AND parent IN (SELECT id FROM touched_categories)
UNION
SELECT 'c' as type, id, title, description, NULL::test_behaviour AS behaviour, NULL::varchar AS test_function, NULL::smallint AS timeout, parent, execute_order
FROM category
WHERE live = true AND id IN (SELECT id FROM touched_categories)
) e, hierarchy h
WHERE e.parent = h.id AND h.type = 'c'
)
)
SELECT type, id, title, description, behaviour, test_function, timeout, parent FROM hierarchy ORDER BY execute_order`, categoryIDs)
if err != nil {
log.Fatal(err)
}
for rows.Next() {
var rowType string
var id int
var title string
var description sql.NullString
var behaviour sql.NullString
var testFunctionInvocation sql.NullString
var timeoutNullable sql.NullInt64
var parentNullable sql.NullInt64
// NULL description -> empty string (only the case for categories, which
// doesn't matter because they aren't written out for categories in the
// JavaScript below)
description.String = ""
// NULL behaviour -> empty string (only the case for categories, which
// doesn't matter because they aren't written out for categories in the
// JavaScript below)
behaviour.String = ""
// NULL test_function -> empty string (only the case for
// categories, which doesn't matter because they aren't written out for
// categories in the JavaScript below)
testFunctionInvocation.String = ""
if err := rows.Scan(&rowType, &id, &title, &description, &behaviour, &testFunctionInvocation, &timeoutNullable, &parentNullable); err != nil {
//.........这里部分代码省略.........
开发者ID:postfix,项目名称:browseraudit,代码行数:101,代码来源:test_suite.go
示例18: fetchResult
func fetchResult(itemT reflect.Type, rows *sql.Rows, columns []string) (reflect.Value, error) {
var item reflect.Value
var err error
switch itemT.Kind() {
case reflect.Map:
item = reflect.MakeMap(itemT)
case reflect.Struct:
item = reflect.New(itemT)
default:
return item, db.ErrExpectingMapOrStruct
}
expecting := len(columns)
// Allocating results.
values := make([]*sql.RawBytes, expecting)
scanArgs := make([]interface{}, expecting)
for i := range columns {
scanArgs[i] = &values[i]
}
if err = rows.Scan(scanArgs...); err != nil {
return item, err
}
// Range over row values.
for i, value := range values {
if value != nil {
// Real column name
column := columns[i]
// Value as string.
svalue := string(*value)
var cv reflect.Value
v, _ := to.Convert(svalue, reflect.String)
cv = reflect.ValueOf(v)
switch itemT.Kind() {
// Destination is a map.
case reflect.Map:
if cv.Type() != itemT.Elem() {
if itemT.Elem().Kind() == reflect.Interface {
cv, _ = util.StringToType(svalue, cv.Type())
} else {
cv, _ = util.StringToType(svalue, itemT.Elem())
}
}
if cv.IsValid() {
item.SetMapIndex(reflect.ValueOf(column), cv)
}
// Destionation is a struct.
case reflect.Struct:
index := util.GetStructFieldIndex(itemT, column)
if index == nil {
continue
} else {
// Destination field.
destf := item.Elem().FieldByIndex(index)
if destf.IsValid() {
if cv.Type() != destf.Type() {
if destf.Type().Kind() != reflect.Interface {
switch destf.Type() {
case nullFloat64Type:
nullFloat64 := sql.NullFloat64{}
if svalue != `` {
nullFloat64.Scan(svalue)
}
cv = reflect.ValueOf(nullFloat64)
case nullInt64Type:
nullInt64 := sql.NullInt64{}
if svalue != `` {
nullInt64.Scan(svalue)
}
cv = reflect.ValueOf(nullInt64)
case nullBoolType:
nullBool := sql.NullBool{}
if svalue != `` {
nullBool.Scan(svalue)
}
cv = reflect.ValueOf(nullBool)
case nullStringType:
nullString := sql.NullString{}
nullString.Scan(svalue)
cv = reflect.ValueOf(nullString)
default:
var decodingNull bool
if svalue == "" {
//.........这里部分代码省略.........
开发者ID:huuzkee-foundation,项目名称:dbcli,代码行数:101,代码来源:fetch.go
示例19: CreateContainer
func (db *SQLDB) CreateContainer(container Container, ttl time.Duration) (SavedContainer, error) {
if !(isValidCheckID(container.ContainerIdentifier) || isValidStepID(container.ContainerIdentifier)) {
return SavedContainer{}, ErrInvalidIdentifier
}
tx, err := db.conn.Begin()
if err != nil {
return SavedContainer{}, err
}
defer tx.Rollback()
checkSource, err := json.Marshal(container.CheckSource)
if err != nil {
return SavedContainer{}, err
}
envVariables, err := json.Marshal(container.EnvironmentVariables)
if err != nil {
return SavedContainer{}, err
}
user := container.User
interval := fmt.Sprintf("%d second", int(ttl.Seconds()))
if container.PipelineName != "" && container.PipelineID == 0 {
// containers that belong to some pipeline must be identified by pipeline ID not name
return SavedContainer{}, errors.New("container metadata must include pipeline ID")
}
var pipelineID sql.NullInt64
if container.PipelineID != 0 {
pipelineID.Int64 = int64(container.PipelineID)
pipelineID.Valid = true
}
var resourceID sql.NullInt64
if container.ResourceID != 0 {
resourceID.Int64 = int64(container.ResourceID)
resourceID.Valid = true
}
var resourceTypeVersion string
if container.ResourceTypeVersion != nil {
resourceTypeVersionBytes, err := json.Marshal(container.ResourceTypeVersion)
if err != nil {
return SavedContainer{}, err
}
resourceTypeVersion = string(resourceTypeVersionBytes)
}
var buildID sql.NullInt64
if container.BuildID != 0 {
buildID.Int64 = int64(container.BuildID)
buildID.Valid = true
}
workerName := container.WorkerName
if workerName == "" {
workerName = container.WorkerName
}
var attempts sql.NullString
if len(container.Attempts) > 0 {
attemptsBlob, err := json.Marshal(container.Attempts)
if err != nil {
return SavedContainer{}, err
}
attempts.Valid = true
attempts.String = string(attemptsBlob)
}
var imageResourceSource sql.NullString
if container.ImageResourceSource != nil {
marshaled, err := json.Marshal(container.ImageResourceSource)
if err != nil {
return SavedContainer{}, err
}
imageResourceSource.String = string(marshaled)
imageResourceSource.Valid = true
}
var imageResourceType sql.NullString
if container.ImageResourceType != "" {
imageResourceType.String = container.ImageResourceType
imageResourceType.Valid = true
}
_, err = tx.Exec(`
INSERT INTO containers (handle, resource_id, step_name, pipeline_id, build_id, type, worker_name, expires_at, ttl, check_type, check_source, plan_id, working_directory, env_variables, attempts, stage, image_resource_type, image_resource_source, process_user, resource_type_version)
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW() + $8::INTERVAL, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)`,
container.Handle,
resourceID,
container.StepName,
pipelineID,
buildID,
container.Type.String(),
workerName,
interval,
//.........这里部分代码省略.........
开发者ID:xoebus,项目名称:checkin,代码行数:101,代码来源:sqldb_containers.go
示例20: getBook
func getBook(db *sql.DB, id string) (Book, error) {
var (
BookIDValue driver.Value
BookTitleValue driver.Value
InfoValue driver.Value
BookInfoValue driver.Value
AuthorValue driver.Value
AuthorBioValue driver.Value
CategoryValue driver.Value
DiedValue driver.Value
book Book
)
rows, err := db.Query("SELECT BkId, Bk, Betaka, Inf, Auth, AuthInf, cat, AD FROM main")
if err != nil {
log.Println(err)
return book, err
}
defer rows.Close()
for rows.Next() {
var (
bookid sql.NullString
booktitle sql.NullString
info sql.NullString
bookinfo sql.NullString
author sql.NullString
authorbio sql.NullString
category sql.NullString
died sql.NullString
)
if err := rows.Scan(&bookid, &booktitle, &info, &bookinfo, &author, &authorbio, &category, &died); err != nil {
log.Println(err)
return book, err
}
if bookid.Valid {
BookIDValue, err = bookid.Value()
if err != nil {
log.Println(err)
return book, err
}
} else {
BookIDValue = "null"
}
if booktitle.Valid {
BookTitleValue, err = booktitle.Value()
if err != nil {
log.Println(err)
return book, err
}
} else {
BookTitleValue = "null"
}
if info.Valid {
InfoValue, err = info.Value()
if err != nil {
log.Println(err)
return book, err
}
} else {
InfoValue = "null"
}
if bookinfo.Valid {
BookInfoValue, err = bookinfo.Value()
if err != nil {
log.Println(err)
return book, err
}
} else {
BookInfoValue = "null"
}
if author.Valid {
AuthorValue, err = author.Value()
if err != nil {
log.Println(err)
return book, err
}
} else {
AuthorValue = "null"
}
if authorbio.Valid {
AuthorBioValue, err = authorbio.Value()
if err != nil {
log.Println(err)
return book, err
}
} else {
AuthorBioValue = "null"
//.........这里部分代码省略.........
开发者ID:shaybix,项目名称:ahsan,代码行数:101,代码来源:export.go
注:本文中的database/sql.NullString类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论