Пример #1
0
func (store *MysqlStore) ReadTotalStats() (*BestiaryExtract, os.Error) {
	db, err := mysql.DialUnix(mysql.DEFAULT_SOCKET, store.user, store.password, store.database)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	err = db.Query("select count(id), count(distinct num_monstre) from cdm")
	if err != nil {
		return nil, err
	}

	result, err := db.UseResult()
	if err != nil {
		return nil, err
	}
	defer result.Free()

	be := new(BestiaryExtract)
	row := result.FetchRow()
	be.NbCdm = row[0].(int64)
	be.NbMonsters = row[1].(int64)

	return be, nil
}
Пример #2
0
func MySQLNewConnection(sock string, user string, password string, database string) (Connection, os.Error) {
	var err os.Error
	var db *mysql.Client
	db, err = mysql.DialUnix(sock, user, password, database)
	if err != nil {
		err = db.Close()
		return nil, err
	}

	conn := new(MySQL)
	conn.Database = database
	conn.db = db
	return conn, err
}
Пример #3
0
// renvoie une liste de noms pour un champ d'auto-completion
func (store *MysqlStore) getMonsterCompleteNames(partialName string, limit uint) ([]string, os.Error) {
	if limit > 100 {
		limit = 100
	} else if limit < 5 {
		limit = 5
	}
	db, err := mysql.DialUnix(mysql.DEFAULT_SOCKET, store.user, store.password, store.database)
	if err != nil {
		return nil, err
	}
	defer db.Close()

	sql := "select distinct nom_complet from cdm where nom_complet like " + toMysqlString(partialName+"%") + " or nom_complet like " + toMysqlString("% "+partialName+"%") + " limit " + strconv.Uitoa(limit)
	stmt, err := db.Prepare(sql)
	defer stmt.Close()

	//fmt.Println(sql)

	err = stmt.Execute()
	if err != nil {
		return nil, err
	}

	names := make([]string, limit)
	count := 0
	var name string
	stmt.BindResult(&name)
	for {
		eof, err := stmt.Fetch()
		if err != nil {
			return nil, err
		}
		if eof {
			break
		}
		names[count] = name
		//fmt.Println(names[count])
		count++
	}
	return names[0:count], nil
}
Пример #4
0
// renvoie une instance de mysql.Client connectée. Il est impératif de faire suivre
// l'appel à cette méthode d'un defer db.Close()
func (store *MysqlStore) Connect() (db *mysql.Client, err os.Error) {
	return mysql.DialUnix(mysql.DEFAULT_SOCKET, store.user, store.password, store.database)
}