setupTable either creates the table or, in case it already exists and the config has Clear=true, we truncate the table.
(tx *sql.Tx)
| 304 | // setupTable either creates the table or, in case it already exists and the |
| 305 | // config has Clear=true, we truncate the table. |
| 306 | func (c *SQLite) setupTable(tx *sql.Tx) error { |
| 307 | // Build the SQL statement that creates the table. |
| 308 | // CREATE TABLE IF NOT EXISTS ? ( ?, ?, ... ) |
| 309 | var fields []string |
| 310 | for _, f := range c.fieldNames { |
| 311 | fields = append(fields, sqliteQuote(f)) |
| 312 | } |
| 313 | if c.isRaw { |
| 314 | // Raw record is a BLOB column. |
| 315 | fields = append(fields, sqliteQuote(c.cfg.RecordBlobName)+" BLOB") |
| 316 | } |
| 317 | |
| 318 | sstmt := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (%s)", |
| 319 | sqliteQuote(c.cfg.TableName), strings.Join(fields, ",")) |
| 320 | |
| 321 | stmt, err := tx.Prepare(sstmt) |
| 322 | if err != nil { |
| 323 | return fmt.Errorf("prepare create statement: %s", err) |
| 324 | } |
| 325 | if _, err = stmt.Exec(); err != nil { |
| 326 | stmt.Close() |
| 327 | return fmt.Errorf("create table: %s", err) |
| 328 | } |
| 329 | stmt.Close() |
| 330 | |
| 331 | return c.maybeTruncate(tx) |
| 332 | } |
| 333 | |
| 334 | func (c *SQLite) doRun(input <-chan baker.OutputRecord) error { |
| 335 | // Install a deferred rollback; if something errors out, we execute |
no test coverage detected