func (t *TableDef) Insert(db *sql.DB, row rowmessage.RowMessage) error { args := make([]interface{}, len(t.Columns)) for index, column := range t.Columns { args[index] = row.GetValue(column.Name) if args[index] == nil && column.NotNull { return fmt.Errorf("Missing column %s: %s", column.Name, row) } } _, err := db.Exec(t.insertSQL, args...) if err != nil { log.Printf("TableDef.insert: error sql=\"%s\" args=%v", t.insertSQL, args) } return err }
func Insert(db *sql.DB, tables tabledef.TableDefs, row rowmessage.RowMessage) error { tableName := row.GetType() if tableName == "" { return fmt.Errorf("Message had invalid or missing type property: %s", row) } table := tables[tableName] if table == nil { return fmt.Errorf("Message type not found in table list: %s", tableName) } if table.Ignore { return nil } return table.Insert(db, row) }
func (t *TableShaper) Add(row rowmessage.RowMessage) error { var err error messageType := row.GetType() tableDef := t.tables[messageType] if tableDef == nil { tableDef, err = newTableDef(messageType, row) if err != nil { return err } t.tables[messageType] = tableDef } // TODO: merge...as much as we need. // TODO: set notnull = True as needed? // err = updateTableDef(tableDef, row) // return err return nil }