diff options
| author | horus | 2018-02-19 15:59:52 +0100 |
|---|---|---|
| committer | horus | 2018-02-19 15:59:52 +0100 |
| commit | 48fb146188683048b9140f28cbdec3ce51289799 (patch) | |
| tree | fe85eaec4769bdcb06fb2ba67b1f0e946fdf33eb /crawler | |
| parent | e3312da52d0ede1c5f783feba0840c53eeca723d (diff) | |
| download | alkobote-48fb146188683048b9140f28cbdec3ce51289799.tar.gz | |
Bugfix + better error reporting. (crawler)
Diffstat (limited to 'crawler')
| -rw-r--r-- | crawler/database.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/crawler/database.go b/crawler/database.go index c1e0dd7..c557698 100644 --- a/crawler/database.go +++ b/crawler/database.go @@ -81,7 +81,7 @@ func (app *App) createTables() error { func (app *App) save_offer(W []Angebot) error { - query := `INSERT INTO angebot (shop, name, url, abv, volume, original_price, discounted_price, base_price, valid_until, image_url, website_raw, spirit_type, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` + query := `INSERT INTO angebot (shop, name, url, abv, volume, age, original_price, discounted_price, base_price, valid_until, image_url, website_raw, spirit_type, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)` stmt, err := app.DB.Prepare(query) if err != nil { @@ -99,22 +99,35 @@ func (app *App) save_offer(W []Angebot) error { } // resembles UNIQUE constraint - detect_duplicate_query := `SELECT 1 FROM all_view WHERE name = ? AND shop_id = ? AND - volume = ? AND abv = ? AND original_price = ? AND discounted_price = ? AND valid_until > ?` + detect_duplicate_query := `SELECT 1 FROM angebot WHERE name = ? AND shop = ? AND + volume = ? AND abv = ? AND original_price = ? AND discounted_price = ? AND valid_until = ?` err := app.DB.QueryRow(detect_duplicate_query, o.Name, o.Shop, o.Volume, o.Abv, o.Original_price, o.Discounted_price, o.Valid_until).Scan(&found) if err == sql.ErrNoRows { - _, err = stmt.Exec(o.Shop, o.Name, o.Url, o.Abv, o.Volume, o.Original_price, o.Discounted_price, o.Base_price, o.Valid_until, o.Image_url, o.Website, o.Spirit_type, app.Now) + _, err = stmt.Exec(o.Shop, o.Name, o.Url, o.Abv, o.Volume, o.Age, o.Original_price, o.Discounted_price, o.Base_price, o.Valid_until, o.Image_url, o.Website, o.Spirit_type, app.Now) if err != nil { o.error_msg = err.Error() - o.error_ctx = "Save Offer: Inserting offer failed" + o.error_ctx = fmt.Sprintf(`INSERT INTO angebot + (shop, name, url, abv, volume, age, original_price, discounted_price, base_price, + valid_until, image_url, spirit_type, created_at) + VALUES (%d, "%s", "%s", %f, %f, %d, %d, %d, %d, %d, "%s", "%s", %d)`, o.Shop, o.Name, o.Url, o.Abv, o.Volume, o.Age, o.Original_price, + o.Discounted_price, o.Base_price, o.Valid_until, o.Image_url, o.Spirit_type, app.Now) WarnOffer(o, "Save Offer: Inserting offer failed") return err } + DebugOffer(o, "database.go: Inserting offer.") + + } else if err != nil { + o.error_msg = err.Error() + o.error_ctx = fmt.Sprintf(`SELECT 1 FROM angebot WHERE name = %s AND shop = %d AND + volume = %f AND abv = %f AND original_price = %d AND discounted_price = %d + AND valid_until = %d`, o.Name, o.Shop, o.Volume, o.Abv, o.Original_price, o.Discounted_price, o.Valid_until) + WarnOffer(o, "database.go: Duplicate query failed") + return err } } |
