Beispiel #1
0
func (mi *Indexer) SchemaVersion() (version int, err os.Error) {
	var client *mysql.Client
	client, err = mi.getConnection()
	if err != nil {
		return
	}
	defer mi.releaseConnection(client)

	err = client.Query("SELECT value FROM meta WHERE metakey='version'")
	if err != nil {
		return
	}
	res, err := client.UseResult()
	if err != nil {
		return
	}

	row := res.FetchRow()
	if row == nil {
		return 0, nil
	}

	version, err = strconv.Atoi(row[0].(string))

	client.FreeResult()
	return
}
Beispiel #2
0
func do(db *mysql.Client, sql string) {
	err := db.Query(sql)
	if err == nil {
		return
	}
	exitf("Error %v running SQL: %s", err, sql)
}
Beispiel #3
0
func dbExists(db *mysql.Client, dbname string) bool {
	check(db.Query("SHOW DATABASES"))
	result, err := db.UseResult()
	check(err)
	defer result.Free()
	for {
		row := result.FetchRow()
		if row == nil {
			break
		}
		if row[0].(string) == dbname {
			return true
		}
	}
	return false
}
Beispiel #4
0
func (mi *Indexer) IsAlive() (ok bool, err os.Error) {
	var client *mysql.Client
	client, err = mi.getConnection()
	if err != nil {
		return
	}
	defer mi.releaseConnection(client)

	err = client.Query("SELECT 1 + 1")
	if err != nil {
		return
	}
	_, err = client.UseResult()
	if err != nil {
		return
	}
	client.FreeResult()
	return true, nil
}