-
Notifications
You must be signed in to change notification settings - Fork 0
/
ce.go
57 lines (48 loc) · 1.41 KB
/
ce.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 db2
import (
"fmt"
"github.com/juztin/iquery"
"github.com/juztin/iquery/drivers"
)
type DB2_CE struct {
drivers.Driver
}
func (d DB2_CE) Name() string {
return "db2-ce"
}
func (d DB2_CE) DriverName() string {
return driverName
}
func (d DB2_CE) ConnectionString(s iquery.Server) string {
return fmt.Sprintf(connFmt, s.Database, s.Hostname, s.Port, s.Username, s.Password)
}
func (d DB2_CE) SchemasQuery() string {
return "select SCHEMANAME from SYSCAT.SCHEMATA;"
}
func (d DB2_CE) TablesQuery(schema string) string {
return fmt.Sprintf("select trim(NAME) as NAME, '' as TABLE_TEXT"+
" from SYSIBM.SYSTABLES"+
" where TYPE='T'"+
" and CREATOR='%s' order by NAME;", schema)
}
func (d DB2_CE) ColumnsQuery(schema, table string) string {
return fmt.Sprintf("select"+
" c.COLUMN_NAME, '' as COLUMN_HEADING,"+
" lower(c.DATA_TYPE) as DATA_TYPE,"+
" c.COLUMN_DEFAULT,"+
" case when c.CHARACTER_MAXIMUM_LENGTH is not null"+
" then c.CHARACTER_MAXIMUM_LENGTH"+
" else c.NUMERIC_PRECISION"+
" end as LENGTH,"+
" case when c.IS_NULLABLE='YES'"+
" then 1"+
" else 0"+
" end as IS_NULLABLE"+
" from SYSIBM.TABLES t"+
" join SYSIBM.COLUMNS c"+
" on t.TABLE_SCHEMA = c.TABLE_SCHEMA"+
" and t.TABLE_NAME = c.TABLE_NAME"+
" where t.TABLE_SCHEMA = '%s'"+
" and t.TABLE_NAME = '%s'"+
" order by t.TABLE_NAME, c.ORDINAL_POSITION", schema, table)
}