| 23 | ) |
| 24 | |
| 25 | func flushToSQLTable(db *sql.DB, table string) func([]byte) error { |
| 26 | row := 0 |
| 27 | return func(buf []byte) error { |
| 28 | if db == nil { |
| 29 | return fmt.Errorf("flushToSQLTable: no database connection") |
| 30 | } |
| 31 | |
| 32 | if len(buf) > 0 { |
| 33 | block := base64.StdEncoding.EncodeToString(buf) |
| 34 | query := fmt.Sprintf("INSERT INTO %s (id, block) VALUES(%d, '%s')", |
| 35 | table, row, block) |
| 36 | if _, e := db.Exec(query); e != nil { |
| 37 | return fmt.Errorf("cannot flush to table %s: %v", table, e) |
| 38 | } |
| 39 | row++ |
| 40 | } |
| 41 | return nil |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func noopWrapUp() error { |
| 46 | return nil |