forked from godror/godror
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathz_119_test.go
68 lines (61 loc) · 1.83 KB
/
z_119_test.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
58
59
60
61
62
63
64
65
66
67
68
package godror_test
import (
"context"
"database/sql"
"testing"
"time"
godror "github.com/godror/godror"
)
func Test119GetTables(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
const qry = "SELECT ALL_TABLES.TABLE_NAME,COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DECODE(NULLABLE,'Y','Yes','N','No','X') AS NULLALOWED,'X' AS X FROM ALL_TABLES JOIN ALL_TAB_COLUMNS ON (ALL_TABLES.TABLE_NAME=ALL_TAB_COLUMNS.TABLE_NAME) ORDER BY TABLE_NAME,COLUMN_ID"
rows, err := testDb.QueryContext(ctx, qry, godror.FetchArraySize(1024), godror.PrefetchCount(1024+1))
if err != nil {
t.Fatalf("%s: %+v", qry, err)
}
defer rows.Close()
type Column struct {
ColumnName string
DataType string
NullAllowed string
DataLength sql.NullInt64
DataPrecision sql.NullInt64
}
type Table struct {
Name string
Columns []Column
}
var (
colCnt int
stat = make(map[string]int, 3)
tables = make([]Table, 0, 1024)
table = Table{Columns: make([]Column, 0, 32)}
)
for rows.Next() {
var column Column
var tableName, x string
if err := rows.Scan(&tableName, &column.ColumnName, &column.DataType, &column.DataLength, &column.DataPrecision, &column.NullAllowed, &x); err != nil {
t.Fatalf("%s: %+v", qry, err)
}
stat[column.NullAllowed] += 1
if table.Name != tableName {
if table.Name != "" {
tables = append(tables, table)
table = Table{Name: tableName, Columns: make([]Column, 0, 32)}
} else {
table.Name = tableName
}
}
table.Columns = append(table.Columns, column)
colCnt++
}
//in the end we have last table to add to result, if there was one
if table.Name != "" {
tables = append(tables, table)
}
if rows.Err() != nil {
t.Fatalf("%s: %+v", qry, err)
}
t.Logf("NullableStat: %+v tables:%d columns:%d", stat, len(tables), colCnt)
}