Skip to content

Commit b0c22ad

Browse files
committed
start with the new generated things
1 parent 4f247b0 commit b0c22ad

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

dump.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,30 @@ func (table *table) Init() (err error) {
327327
table.values = make([]interface{}, len(tt))
328328
for i, tp := range tt {
329329
st := tp.ScanType()
330-
if tp.DatabaseTypeName() == "BLOB" {
330+
dt := tp.DatabaseTypeName()
331+
332+
// SHOW FIELDS FROM jamfsoftware.computer_installed_certificates;
333+
// if tp.Name() == "cert_blob_lookup_hash" {
334+
// fmt.Println("why though =", st, ":", dt)
335+
// }
336+
337+
if dt == "BLOB" || dt == "BINARY" {
331338
t = reflect.TypeOf(sql.RawBytes{})
332-
} else if st != nil && (st.Kind() == reflect.Int ||
339+
} else if dt == "VARCHAR" || dt == "TEXT" || dt == "DECIMAL" {
340+
t = reflect.TypeOf(sql.NullString{})
341+
} else if (st != nil && (st.Kind() == reflect.Int ||
333342
st.Kind() == reflect.Int8 ||
334343
st.Kind() == reflect.Int16 ||
335344
st.Kind() == reflect.Int32 ||
336-
st.Kind() == reflect.Int64) {
345+
st.Kind() == reflect.Int64)) ||
346+
dt == "BIGINT" || dt == "TINYINT" || dt == "INT" {
337347
t = reflect.TypeOf(sql.NullInt64{})
348+
} else if (st != nil && (st.Kind() == reflect.Float32 ||
349+
st.Kind() == reflect.Float64)) ||
350+
tp.DatabaseTypeName() == "DOUBLE" {
351+
t = reflect.TypeOf(sql.NullFloat64{})
338352
} else {
353+
// unknown datatype
339354
t = reflect.TypeOf(sql.NullString{})
340355
}
341356
table.values[i] = reflect.New(t).Interface()

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module github.com/jamf/go-mysqldump
22

33
require (
44
github.com/DATA-DOG/go-sqlmock v1.3.0
5+
github.com/go-sql-driver/mysql v1.5.0
56
github.com/stretchr/testify v1.4.0
67
)
78

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ github.com/DATA-DOG/go-sqlmock v1.3.0 h1:ljjRxlddjfChBJdFKJs5LuCwCWPLaC1UZLwAo3P
22
github.com/DATA-DOG/go-sqlmock v1.3.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
33
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
6+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
57
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
68
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
79
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

random_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package mysqldump_test
2+
3+
import (
4+
"database/sql"
5+
"fmt"
6+
"os"
7+
"testing"
8+
9+
"github.com/go-sql-driver/mysql"
10+
"github.com/jamf/go-mysqldump"
11+
)
12+
13+
var socketFiles = []string{
14+
"/tmp/mysql.sock",
15+
"/var/run/mysqld/mysqld.sock",
16+
"/var/lib/mysql/mysql.sock",
17+
}
18+
19+
func findSocketFile() string {
20+
// Search under known defaults
21+
for _, socket := range socketFiles {
22+
if _, err := os.Stat(socket); err == nil {
23+
fmt.Println("default mysqld socket found:", socket)
24+
return socket
25+
}
26+
}
27+
return socketFiles[0]
28+
}
29+
30+
func TestDumpMyLocal(t *testing.T) {
31+
config := mysql.NewConfig()
32+
config.MaxAllowedPacket = 0
33+
config.DBName = "jamfsoftware"
34+
config.User = "jamfsoftware"
35+
config.Passwd = "jamfsw03"
36+
config.Net = "unix"
37+
config.Addr = findSocketFile()
38+
39+
db, err := sql.Open("mysql", config.FormatDSN())
40+
if err != nil {
41+
t.Error(err)
42+
}
43+
44+
dump := &mysqldump.Data{
45+
Out: os.Stdout,
46+
Connection: db,
47+
}
48+
49+
if err := dump.Dump(); err != nil {
50+
t.Error(err)
51+
}
52+
}

0 commit comments

Comments
 (0)