func InsertAddedCourses(moodleid int, courses []Course) error {
	// Get the connection
	connection, err := db.GetDB()
	if err != nil {
		return err
	}

	// https://golang.org/pkg/database/sql/#Tx.Query
	tx, err := connection.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback() // The rollback will be ignored if the tx has been committed later in the function.

	stmt, err := tx.Prepare(`
		INSERT INTO courses(moodleid, id, shortname, fullname, summary, downloaded, showgrades, previoushash, unhandlednotifications, newcourse, deletedcourse)
		VALUES (?,?,?,?,?,?,?,?,?,1,0)`)
	if err != nil {
		return err
	}
	defer stmt.Close()

	for _, c := range courses {
		_, err := stmt.Exec(
			moodleid,
			c.ID,
			c.Shortname,
			c.Fullname,
			c.Summary,
			c.Downloaded,
			c.Showgrades,
			c.Previoushash,
			c.Unhandlednotifications)
		if err != nil {
			return err
		}
	}
	if err := tx.Commit(); err != nil {
		return err
	}

	return nil
}
// InsertAddedCourses inserts into the DB all the new courses.
// NOTE: It doesn't change the unhandlednotifications status
InsertAddedCourses inserts into the DB all the new courses.
NOTE: It doesn't change the unhandlednotifications status
// InsertAddedCourses inserts into the DB all the new courses . // NOTE : It doesn ' t change the unhandlednotifications status
func InsertAddedCourses(moodleid int, courses []Course) error {
	connection, err := db.GetDB()
	if err != nil {
		return err
	}
	tx, err := connection.Begin()
	if err != nil {
		return err
	}
	defer tx.Rollback() 
	stmt, err := tx.Prepare(`
		INSERT INTO courses(moodleid, id, shortname, fullname, summary, downloaded, showgrades, previoushash, unhandlednotifications, newcourse, deletedcourse)
		VALUES (?,?,?,?,?,?,?,?,?,1,0)`)
	if err != nil {
		return err
	}
	defer stmt.Close()
	for _, c := range courses {
		_, err := stmt.Exec(
			moodleid,
			c.ID,
			c.Shortname,
			c.Fullname,
			c.Summary,
			c.Downloaded,
			c.Showgrades,
			c.Previoushash,
			c.Unhandlednotifications)
		if err != nil {
			return err
		}
	}
	if err := tx.Commit(); err != nil {
		return err
	}
	return nil
}
func InsertAddedCourses ( moodleid int , courses [ ] Course ) error { connection , err := db . GetDB ( ) if err != nil { return err } tx , err := connection . Begin ( ) if err != nil { return err } defer tx . Rollback ( ) stmt , err := tx . Prepare ( `
		INSERT INTO courses(moodleid, id, shortname, fullname, summary, downloaded, showgrades, previoushash, unhandlednotifications, newcourse, deletedcourse)
		VALUES (?,?,?,?,?,?,?,?,?,1,0)` ) if err != nil { return err } defer stmt . Close ( ) for _ , c := range courses { _ , err := stmt . Exec ( moodleid , c . ID , c . Shortname , c . Fullname , c . Summary , c . Downloaded , c . Showgrades , c . Previoushash , c . Unhandlednotifications ) if err != nil { return err } } if err := tx . Commit ( ) ; err != nil { return err } return nil }
InsertAddedCourses inserts into the DB all the new courses.
InsertAddedCourses inserts into the DB all the new courses .
// Get the connection // https://golang.org/pkg/database/sql/#Tx.Query // The rollback will be ignored if the tx has been committed later in the function.