-
Notifications
You must be signed in to change notification settings - Fork 1
/
getintarray.go
57 lines (56 loc) · 1.32 KB
/
getintarray.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package pgkebab
////noinspection ALL
//const (
// BehaviourSkipErrors = 0
// BehaviourConvertNullsToZero = 1
// BehaviourConvertNullsToEmpty = 1
// BehaviourAbortOnScanError = 2
//)
//
//// GetIntArray returns first col of query result as []int
//// The first param is the behaviour in case of "null scan" errors
//// The available behaviours are:
//// BehaviourSkipErrors
//// BehaviourConvertNullsToZero
//// BehaviourAbortOnScanError
//func (k *DBLink) GetIntArray(behaviour uint8, sqlQuery string, params ...interface{}) ([]int, error) {
// k.assureConnection()
//
// k.lastSQLQuery = sqlQuery
//
// rows, err := k.db.Query(sqlQuery, params...)
//
// var a []int
//
// if err != nil {
// if k.DebugPrint {
// log.Printf(`pgkebab.GetIntArray db.Query The query "%s" with params "%v" has failed with "%v"\n`, sqlQuery, params, err)
// }
//
// return a, err
// }
//
// defer func() { _ = rows.Close() }()
//
// for rows.Next() {
// var i int
//
// if errx := rows.Scan(&i); errx == nil {
// a = append(a, i)
// } else {
// switch behaviour {
// case BehaviourSkipErrors:
// continue
// case BehaviourConvertNullsToZero:
// if strings.Contains(errx.Error(), "converting driver.Value type <nil>") {
// a = append(a, 0)
// }
// default:
// return []int{}, errx
// }
// }
// }
//
// return a, nil
//}
//