Пример #1
0
func salvaStatus(db *sql.DB, id int) {
	stmt, err := db.Prepare("update restricoes set processado = 'S' where id = ?")
	util.CheckErr(err)
	_, err = stmt.Exec(id)
	util.CheckErr(err)
	stmt.Close()
}
Пример #2
0
func salvaRestricao(db *sql.DB, restricao, cep string) {
	stmt, err := db.Prepare("update address set restricao = ? where cep = ?")
	util.CheckErr(err)
	_, err = stmt.Exec(restricao, cep)
	util.CheckErr(err)
	stmt.Close()
}
Пример #3
0
func Execute(db *sql.DB) {
	restricoes, err := db.Query("select id, inicial, final, restricao from restriction where processado is null order by id")
	util.CheckErr(err)
	defer restricoes.Close()

	for restricoes.Next() {

		var id int
		var inicial, final, restricao string
		err = restricoes.Scan(&id, &inicial, &final, &restricao)
		util.CheckErr(err)

		inicial = util.FillBefore(inicial, "0", 8)
		final = util.FillBefore(final, "0", 8)

		ceps, err := db.Query("select cep from address where cep between " + inicial + " and " + final + " order by cep")
		util.CheckErr(err)

		for ceps.Next() {

			var cep string
			err = ceps.Scan(&cep)
			util.CheckErr(err)
			salvaRestricao(db, restricao, cep)

		}

		ceps.Close()
		salvaStatus(db, id)

	}

}
Пример #4
0
func salvaCep(db *sql.DB, latitude, longitude, cep string) {
	stmt, err := db.Prepare("update address set latitude = ?, longitude = ? where cep = ?")
	stmt.Close()
	util.CheckErr(err)

	_, err = stmt.Exec(latitude, longitude, cep)
	util.CheckErr(err)
}
Пример #5
0
func Init() {
	var err error
	if db, err = gorm.Open("mysql", "root:root@tcp(127.0.0.1:3306)/dne?charset=utf8"); err == nil {
		if err = db.DB().Ping(); err == nil {
			db.LogMode(true)
			db.SingularTable(true)
		}
	}
	util.CheckErr(err)
}
Пример #6
0
func Init() {
	var err error
	db, err = sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/dne?charset=utf8")
	util.CheckErr(err)
}
Пример #7
0
func NewDB() *sql.DB {
	var err error
	db, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/dne?charset=utf8")
	util.CheckErr(err)
	return db
}