func (db *DB) GetUniquePeerIdx() (peerIdx uint32, err error) {

	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}

	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while getting unique peer index: \n%s", err)
			return
		}
		err = tx.Commit()
	}()

	// use peer schema
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}

	var rows *sql.Rows
	getMaxPeerIdxQuery := fmt.Sprintf("SELECT MAX(peerIdx) FROM %s;", db.peerTableName)
	if rows, err = tx.Query(getMaxPeerIdxQuery); err != nil {
		return
	}

	// Add row close to defer stack
	defer func() {
		if err = rows.Close(); err != nil {
			err = fmt.Errorf("Error closing peer rows: \n%s", err)
		}
	}()

	if rows.Next() {
		if err = rows.Scan(&peerIdx); err != nil {
			err = fmt.Errorf("Error scanning for max peer idx: \n%s", err)
			return
		}
	}

	return
}
// GetUniquePeerIdx gets a unique peer index
GetUniquePeerIdx gets a unique peer index
// GetUniquePeerIdx gets a unique peer index
func (db *DB) GetUniquePeerIdx() (peerIdx uint32, err error) {
	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while getting unique peer index: \n%s", err)
			return
		}
		err = tx.Commit()
	}()
	if _, err = tx.Exec("USE " + db.peerSchema + ";"); err != nil {
		return
	}
	var rows *sql.Rows
	getMaxPeerIdxQuery := fmt.Sprintf("SELECT MAX(peerIdx) FROM %s;", db.peerTableName)
	if rows, err = tx.Query(getMaxPeerIdxQuery); err != nil {
		return
	}
	defer func() {
		if err = rows.Close(); err != nil {
			err = fmt.Errorf("Error closing peer rows: \n%s", err)
		}
	}()
	if rows.Next() {
		if err = rows.Scan(&peerIdx); err != nil {
			err = fmt.Errorf("Error scanning for max peer idx: \n%s", err)
			return
		}
	}
	return
}
func ( db * DB ) GetUniquePeerIdx ( ) ( peerIdx uint32 , err error ) { var tx * sql . Tx if tx , err = db . DBHandler . Begin ( ) ; err != nil { return } defer func ( ) { if err != nil { tx . Rollback ( ) err = fmt . Errorf ( " \n " , err ) return } err = tx . Commit ( ) } ( ) if _ , err = tx . Exec ( " " + db . peerSchema + " " ) ; err != nil { return } var rows * sql . Rows getMaxPeerIdxQuery := fmt . Sprintf ( " " , db . peerTableName ) if rows , err = tx . Query ( getMaxPeerIdxQuery ) ; err != nil { return } defer func ( ) { if err = rows . Close ( ) ; err != nil { err = fmt . Errorf ( " \n " , err ) } } ( ) if rows . Next ( ) { if err = rows . Scan ( & peerIdx ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } } return }
GetUniquePeerIdx gets a unique peer index
GetUniquePeerIdx gets a unique peer index
// use peer schema // Add row close to defer stack