英文:
return default value when user not input
问题
当用户没有输入字段时返回默认值
var (
notes ='this will be default'
)
qapi := `
UPDATE custom_param SET param_value = $1, start_date = $2, end_date = $3, status = $4 `enter code here` WHERE param_name = 'default-password'
RETURNING param_value, start_date, end_date, status, notes;
`
// 插入到 master_param
sqlError := tx.QueryRowContext(ctx, qapi, request.Value, request.StartDate, request.EndDate, request.Status, request.Notes).Scan(
&value,
&startDate,
&endDate,
&status,
¬es,
)
queryInsertNotes := `insert `
if request.Notes != "" {
notes = request.Notes
}
if sqlError != nil {
log.Println("SQL Error on ReadApplication on UpdateScheduleMaintenance", sqlError)
tx.Rollback()
return schedule, sqlError
}
err = tx.Commit()
if err != nil {
tx.Rollback()
return schedule, err
}
当用户没有输入任何备注时返回默认备注
英文:
return default value when user not input field
var (
notes ='this will be default'
)
qapi := `
UPDATE custom_param SET param_value = $1, start_date = $2, end_date = $3, status = $4 `enter code here` WHERE param_name = 'default-password'
RETURNING param_value, start_date, end_date, status, notes;
`
// insrt into master_param
sqlError := tx.QueryRowContext(ctx, qapi, request.Value, request.StartDate, request.EndDate, request.Status, request.Notes).Scan(
&value,
&startDate,
&endDate,
&status,
&notes,
)
queryInsertNotes := `insert `
if request.Notes != "" {
notes = request.Notes
}
if sqlError != nil {
log.Println("SQL Error on ReadApplication on UpdateScheduleMaintenance", sqlError)
tx.Rollback()
return schedule, sqlError
}
err = tx.Commit()
if err != nil {
tx.Rollback()
return schedule, err
}
return default notes when user not inputs any notes
答案1
得分: 0
我认为你需要类似这样的代码,但我没有测试过这段代码,不过你可以理解其中的意思。
notes := "this will be default"
if request.Notes != "" {
notes = request.Notes
}
qapi := `
UPDATE custom_param SET param_value = $1, start_date = $2, end_date = $3, status = $4, notes = $4 WHERE param_name = 'default-password'
RETURNING param_value, start_date, end_date, status, notes;
`
// 插入到 master_param
sqlError := tx.QueryRowContext(ctx, qapi, request.Value, request.StartDate, request.EndDate, request.Status, notes).Scan(
&value,
&startDate,
&endDate,
&status,
¬es,
)
if sqlError != nil {
log.Println("SQL Error on ReadApplication on UpdateScheduleMaintenance", sqlError)
tx.Rollback()
return schedule, sqlError
}
err = tx.Commit()
if err != nil {
tx.Rollback()
return schedule, err
}
英文:
I think you need something like this, haven't tested the code but you get the idea.
notes := "this will be default"
if request.Notes != "" {
notes = request.Notes
}
qapi := `
UPDATE custom_param SET param_value = $1, start_date = $2, end_date = $3, status = $4, notes = $4 WHERE param_name = 'default-password'
RETURNING param_value, start_date, end_date, status, notes;
`
// insrt into master_param
sqlError := tx.QueryRowContext(ctx, qapi, request.Value, request.StartDate, request.EndDate, request.Status, notes).Scan(
&value,
&startDate,
&endDate,
&status,
&notes,
)
if sqlError != nil {
log.Println("SQL Error on ReadApplication on UpdateScheduleMaintenance", sqlError)
tx.Rollback()
return schedule, sqlError
}
err = tx.Commit()
if err != nil {
tx.Rollback()
return schedule, err
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论