Add Count()

Add Createf()
Fix inqbuild2() loop.
This commit is contained in:
Azareal 2021-04-27 20:24:04 +10:00
parent 6870d242e9
commit aa02f9fc48
1 changed files with 20 additions and 5 deletions

View File

@ -208,13 +208,28 @@ func Logf(str string, args ...interface{}) {
log.Printf(str, args...) log.Printf(str, args...)
} }
func Countf(stmt *sql.Stmt, args ...interface{}) (count int) { func Count(stmt *sql.Stmt) (count int) {
err := stmt.QueryRow(args...).Scan(&count) e := stmt.QueryRow().Scan(&count)
if err != nil { if e != nil {
LogError(err) LogError(e)
} }
return count return count
} }
func Countf(stmt *sql.Stmt, args ...interface{}) (count int) {
e := stmt.QueryRow(args...).Scan(&count)
if e != nil {
LogError(e)
}
return count
}
func Createf(stmt *sql.Stmt, args ...interface{}) (id int, e error) {
res, e := stmt.Exec(args...)
if e != nil {
return 0, e
}
id64, e := res.LastInsertId()
return int(id64), e
}
func eachall(stmt *sql.Stmt, f func(r *sql.Rows) error) error { func eachall(stmt *sql.Stmt, f func(r *sql.Rows) error) error {
rows, e := stmt.Query() rows, e := stmt.Query()
@ -261,7 +276,7 @@ func inqbuild2(count int) string {
} }
var sb strings.Builder var sb strings.Builder
sb.Grow((count * 2) - 1) sb.Grow((count * 2) - 1)
for i := 0; i <= count; i++ { for i := 0; i < count; i++ {
if i == 0 { if i == 0 {
sb.WriteRune('?') sb.WriteRune('?')
} else { } else {