@@ -29,6 +29,7 @@ type Data struct {
29
29
footerTmpl * template.Template
30
30
mux sync.Mutex
31
31
wg sync.WaitGroup
32
+ err error
32
33
}
33
34
34
35
type table struct {
@@ -43,7 +44,7 @@ type metaData struct {
43
44
CompleteTime string
44
45
}
45
46
46
- const version = "0.3.3 "
47
+ const version = "0.3.4 "
47
48
48
49
const headerTmpl = `-- Go SQL Dump {{ .DumpVersion }}
49
50
--
@@ -105,7 +106,6 @@ func (data *Data) Dump() error {
105
106
DumpVersion : version ,
106
107
}
107
108
108
- // Get server version
109
109
if err := meta .updateServerVersion (data .Connection ); err != nil {
110
110
return err
111
111
}
@@ -118,22 +118,22 @@ func (data *Data) Dump() error {
118
118
return err
119
119
}
120
120
121
- // Get tables
122
121
tables , err := data .getTables ()
123
122
if err != nil {
124
123
return err
125
124
}
126
125
127
- // Get sql for each table
128
126
data .wg .Add (len (tables ))
129
127
for _ , name := range tables {
130
128
if err := data .dumpTable (name ); err != nil {
131
129
return err
132
130
}
133
131
}
134
132
data .wg .Wait ()
133
+ if data .err != nil {
134
+ return data .err
135
+ }
135
136
136
- // Set complete time
137
137
meta .CompleteTime = time .Now ().String ()
138
138
return data .footerTmpl .Execute (data .Out , meta )
139
139
}
@@ -152,18 +152,20 @@ func (data *Data) dumpTable(name string) error {
152
152
return nil
153
153
}
154
154
155
- func (data * Data ) writeTable (table * table ) error {
155
+ func (data * Data ) writeTable (table * table ) {
156
156
data .mux .Lock ()
157
- err := data .tableTmpl .Execute (data .Out , table )
157
+ if err := data .tableTmpl .Execute (data .Out , table ); err != nil && data .err == nil {
158
+ data .err = err
159
+ }
158
160
data .mux .Unlock ()
159
161
data .wg .Done ()
160
- return err
162
+ return
161
163
}
162
164
163
165
// MARK: get methods
164
166
167
+ // getTemplates initilaizes the templates on data from the constants in this file
165
168
func (data * Data ) getTemplates () (err error ) {
166
- // Write dump to file
167
169
data .headerTmpl , err = template .New ("mysqldumpHeader" ).Parse (headerTmpl )
168
170
if err != nil {
169
171
return
@@ -184,14 +186,12 @@ func (data *Data) getTemplates() (err error) {
184
186
func (data * Data ) getTables () ([]string , error ) {
185
187
tables := make ([]string , 0 )
186
188
187
- // Get table list
188
189
rows , err := data .Connection .Query ("SHOW TABLES" )
189
190
if err != nil {
190
191
return tables , err
191
192
}
192
193
defer rows .Close ()
193
194
194
- // Read result
195
195
for rows .Next () {
196
196
var table sql.NullString
197
197
if err := rows .Scan (& table ); err != nil {
@@ -238,7 +238,6 @@ func (data *Data) createTable(name string) (*table, error) {
238
238
}
239
239
240
240
func (data * Data ) createTableSQL (name string ) (string , error ) {
241
- // Get table creation SQL
242
241
var tableReturn , tableSQL sql.NullString
243
242
err := data .Connection .QueryRow ("SHOW CREATE TABLE " + name ).Scan (& tableReturn , & tableSQL )
244
243
@@ -253,14 +252,12 @@ func (data *Data) createTableSQL(name string) (string, error) {
253
252
}
254
253
255
254
func (data * Data ) createTableValues (name string ) (string , error ) {
256
- // Get Data
257
255
rows , err := data .Connection .Query ("SELECT * FROM " + name )
258
256
if err != nil {
259
257
return "" , err
260
258
}
261
259
defer rows .Close ()
262
260
263
- // Get columns
264
261
columns , err := rows .Columns ()
265
262
if err != nil {
266
263
return "" , err
@@ -269,7 +266,6 @@ func (data *Data) createTableValues(name string) (string, error) {
269
266
return "" , errors .New ("No columns in table " + name + "." )
270
267
}
271
268
272
- // Read data
273
269
dataText := make ([]string , 0 )
274
270
tt , err := rows .ColumnTypes ()
275
271
if err != nil {
@@ -296,7 +292,6 @@ func (data *Data) createTableValues(name string) (string, error) {
296
292
values [i ] = reflect .New (types [i ]).Interface ()
297
293
}
298
294
for rows .Next () {
299
- // Read data
300
295
if err := rows .Scan (values ... ); err != nil {
301
296
return "" , err
302
297
}
0 commit comments