Exemplo n.º 1
0
func ScanIssue(row *sql.Row) (*Issue, error) {
	var v0 int64
	var v1 int
	var v2 string
	var v3 string
	var v4 string
	var v5 string
	var v6 []byte

	err := row.Scan(
		&v0,
		&v1,
		&v2,
		&v3,
		&v4,
		&v5,
		&v6,
	)
	if err != nil {
		return nil, err
	}

	v := &Issue{}
	v.ID = v0
	v.Number = v1
	v.Title = v2
	v.Body = v3
	v.Assignee = v4
	v.State = v5
	json.Unmarshal(v6, &v.Labels)

	return v, nil
}
Exemplo n.º 2
0
func extractPost(row *sql.Row) (*structure.Post, error) {
	post := structure.Post{}
	var userId int64
	var status string
	err := row.Scan(&post.Id, &post.Uuid, &post.Title, &post.Slug, &post.Markdown, &post.Html, &post.IsFeatured, &post.IsPage, &status, &post.Image, &userId, &post.Date)
	if err != nil {
		return nil, err
	}
	// If there was no publication date attached to the post, make its creation date the date of the post
	if post.Date == nil {
		post.Date, err = retrievePostCreationDateById(post.Id)
		if err != nil {
			return nil, err
		}
	}
	// Evaluate status
	if status == "published" {
		post.IsPublished = true
	} else {
		post.IsPublished = false
	}
	// Retrieve user
	post.Author, err = RetrieveUser(userId)
	if err != nil {
		return nil, err
	}
	// Retrieve tags
	post.Tags, err = RetrieveTags(post.Id)
	if err != nil {
		return nil, err
	}
	return &post, nil
}
Exemplo n.º 3
0
// Populates a video + type
func populateVideo(row *sql.Row, ch chan Video) {
	var v Video
	var tName, tIcon *string
	err := row.Scan(
		&v.ID,
		&v.VideoType.ID,
		&v.Title,
		&v.Description,
		&v.DateAdded,
		&v.DateModified,
		&v.IsPrimary,
		&v.Thumbnail,
		&tName,
		&tIcon,
	)
	if err != nil {
		ch <- v
		return
	}
	if tName != nil {
		v.VideoType.Name = *tName
	}
	if tIcon != nil {
		v.VideoType.Icon = *tIcon
	}

	ch <- v
	return
}
Exemplo n.º 4
0
func rowToCompte(trollId int, row *sql.Row) (*Compte, error) {
	c := new(Compte)
	c.trollId = trollId
	c.Troll = new(TrollData)
	err := row.Scan(
		&c.statut,
		&c.mdpRestreint,
		&c.Troll.PV_max,
		&c.Troll.PV_actuels,
		&c.Troll.X,
		&c.Troll.Y,
		&c.Troll.Z,
		&c.Troll.Fatigue,
		&c.Troll.PA,
		&c.Troll.Vue,
		&c.Troll.ProchainTour,
		&c.Troll.DureeTour,
		&c.Troll.MiseAJour)
	c.Troll.ProchainTour *= 1000
	c.Troll.MiseAJour *= 1000
	if err != nil {
		return nil, err
	}
	return c, err
}
Exemplo n.º 5
0
// Query the currently used space for the given user
func (tx *Transaction) QuerySpaceConsumptionFor(user string) (result uint64, err error) {
	err = tx.do(func(tx *sql.Tx) (err error) {
		var row *sql.Row

		row = tx.QueryRow(`
      SELECT
        SUM("u"."size") AS "size"
			FROM (
			  SELECT --DISTINCT
			    "u"."user" AS "user",
			    "u"."id" AS "id",
			    "u"."size" AS "size"
			  FROM "uploads" AS "u"
			  WHERE "u"."expiration" >= NOW()
			    AND "u"."user" = $1
			) AS "u"
			GROUP BY "u"."user"`,
			user)

		// Get result - use zero if query returned no result for the given username
		err = row.Scan(&result)
		if err == sql.ErrNoRows {
			result = 0
			err = nil
		}

		return
	})

	return
}
Exemplo n.º 6
0
func populateApplicationGuide(row *sql.Row, ch chan ApplicationGuide) {
	var ag ApplicationGuide
	var catID *int
	var icon []byte
	var catName *string
	err := row.Scan(
		&ag.ID,
		&ag.Url,
		&ag.Website.ID,
		&ag.FileType,
		&catID,
		&icon,
		&catName,
	)
	if err != nil {
		ch <- ag
	}
	if catID != nil {
		ag.Category.CategoryID = *catID
	}
	if catName != nil {
		ag.Category.Title = *catName
	}
	if icon != nil {
		ag.Icon = string(icon[:])
	}
	ch <- ag
	return
}
Exemplo n.º 7
0
// fetchLocationBySha look up the Tx sha information by name.
// Must be called with db lock held.
func (db *SqliteDb) fetchLocationBySha(txsha *btcwire.ShaHash) (blockidx int64, txoff int, txlen int, err error) {
	var row *sql.Row
	var blockid int64
	var ttxoff int
	var ttxlen int

	rowBytes := txsha.String()
	txop := db.txop(txFetchLocationByShaStmt)
	row = txop.QueryRow(rowBytes)

	err = row.Scan(&blockid, &ttxoff, &ttxlen)
	if err == sql.ErrNoRows {
		txop = db.txop(txtmpFetchLocationByShaStmt)
		row = txop.QueryRow(rowBytes)

		err = row.Scan(&blockid, &ttxoff, &ttxlen)
		if err == sql.ErrNoRows {
			err = btcdb.TxShaMissing
			return
		}
		if err != nil {
			log.Warnf("txtmp FetchLocationBySha: fail %v",
				err)
			return
		}
	}
	if err != nil {
		log.Warnf("FetchLocationBySha: fail %v", err)
		return
	}
	blockidx = blockid - 1
	txoff = ttxoff
	txlen = ttxlen
	return
}
Exemplo n.º 8
0
// FetchTxUsedBySha returns the used/spent buffer for a given transaction.
func (db *SqliteDb) FetchTxUsedBySha(txsha *btcwire.ShaHash) (spentbuf []byte, err error) {
	var row *sql.Row
	db.dbLock.Lock()
	defer db.dbLock.Unlock()

	rowBytes := txsha.String()
	txop := db.txop(txFetchUsedByShaStmt)
	row = txop.QueryRow(rowBytes)

	var databytes []byte
	err = row.Scan(&databytes)
	if err == sql.ErrNoRows {
		txop := db.txop(txtmpFetchUsedByShaStmt)
		row = txop.QueryRow(rowBytes)

		err = row.Scan(&databytes)
		if err == sql.ErrNoRows {
			err = btcdb.TxShaMissing
			return
		}
		if err != nil {
			log.Warnf("txtmp FetchLocationBySha: fail %v",
				err)
			return
		}
	}

	if err != nil {
		log.Warnf("FetchUsedBySha: fail %v", err)
		return
	}
	spentbuf = databytes
	return
}
Exemplo n.º 9
0
func (t *Topic) consumeRow(row *sql.Row) error {
	return row.Scan(
		&t.Id,
		&t.Name,
		&t.CreatedAt,
		&t.UpdatedAt,
	)
}
Exemplo n.º 10
0
Arquivo: mysql.go Projeto: hyl87/qbs
func (d mysql) indexExists(mg *Migration, tableName, indexName string) bool {
	var row *sql.Row
	var name string
	row = mg.Db.QueryRow("SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS "+
		"WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND INDEX_NAME = ?", mg.DbName, tableName, indexName)
	row.Scan(&name)
	return name != ""
}
Exemplo n.º 11
0
func rowToDBLink(row *sql.Row) *DBLink {
	link := DBLink{}
	err := row.Scan(&link.Key, &link.Link, &link.Sender_id, &link.Date, &link.Link_type, &link.Sender_name)
	if err != nil {
		return &DBLink{}
	}
	return &link
}
Exemplo n.º 12
0
func scanSelectSingle(m *model.Group, row *sql.Row) error {
	err := row.Scan(
		&m.UID,
		&m.Name,
		&m.UserUID,
		&m.CreatedAt,
	)
	return err
}
Exemplo n.º 13
0
func (pgSQL *pgSQL) scanNotification(row *sql.Row, hasVulns bool) (database.VulnerabilityNotification, error) {
	var notification database.VulnerabilityNotification
	var created zero.Time
	var notified zero.Time
	var deleted zero.Time
	var oldVulnerabilityNullableID sql.NullInt64
	var newVulnerabilityNullableID sql.NullInt64

	// Scan notification.
	if hasVulns {
		err := row.Scan(
			&notification.ID,
			&notification.Name,
			&created,
			&notified,
			&deleted,
			&oldVulnerabilityNullableID,
			&newVulnerabilityNullableID,
		)

		if err != nil {
			return notification, err
		}
	} else {
		err := row.Scan(&notification.ID, &notification.Name, &created, &notified, &deleted)

		if err != nil {
			return notification, err
		}
	}

	notification.Created = created.Time
	notification.Notified = notified.Time
	notification.Deleted = deleted.Time

	if hasVulns {
		if oldVulnerabilityNullableID.Valid {
			vulnerability, err := pgSQL.findVulnerabilityByIDWithDeleted(int(oldVulnerabilityNullableID.Int64))
			if err != nil {
				return notification, err
			}

			notification.OldVulnerability = &vulnerability
		}

		if newVulnerabilityNullableID.Valid {
			vulnerability, err := pgSQL.findVulnerabilityByIDWithDeleted(int(newVulnerabilityNullableID.Int64))
			if err != nil {
				return notification, err
			}

			notification.NewVulnerability = &vulnerability
		}
	}

	return notification, nil
}
Exemplo n.º 14
0
func MapChar(r *sql.Row) (*Character, error) {
	var c Character
	var t string
	err := r.Scan(&c.Id, &c.UserId, &c.Name, &c.Image, &c.StatsJson, &t)
	if err != nil {
		return nil, err
	}
	c.DateModified, err = StringToTime(t)
	return &c, err
}
Exemplo n.º 15
0
Arquivo: oracle.go Projeto: hyl87/qbs
func (d oracle) indexExists(mg *Migration, tableName, indexName string) bool {
	var row *sql.Row
	var name string
	query := "SELECT INDEX_NAME FROM USER_INDEXES "
	query += "WHERE TABLE_NAME = ? AND INDEX_NAME = ?"
	query = d.substituteMarkers(query)
	row = mg.Db.QueryRow(query, tableName, indexName)
	row.Scan(&name)
	return name != ""
}
Exemplo n.º 16
0
func (d postgres) indexExists(mg *Migration, tableName, indexName string) bool {
	var row *sql.Row
	var name string
	query := "SELECT indexname FROM pg_indexes "
	query += "WHERE tablename = ? AND indexname = ?"
	query = d.substituteMarkers(query)
	row = mg.Db.QueryRow(query, tableName, indexName)
	row.Scan(&name)
	return name != ""
}
Exemplo n.º 17
0
func MapUser(r *sql.Row) (*User, error) {
	var u User
	var t string
	err := r.Scan(&u.Id, &u.Email, &u.Hashword, &u.Rank, &t)
	if err != nil {
		return nil, err
	}
	u.Since, err = StringToTime(t)
	return &u, err
}
Exemplo n.º 18
0
func recordFromRow(row *sql.Row) (*record, error) {

	rec := new(record)
	err := row.Scan(&rec.name, &rec.salt, &rec.pass, &rec.gid)
	if err != nil {
		return nil, err
	}

	return rec, nil

}
Exemplo n.º 19
0
// ReadAnimeRow Read an Anime object in from a Database Row
func ReadAnimeRow(row *sql.Row) (*models.Anime, error) {
	anime := new(models.Anime)
	err := row.Scan(&anime.ID, &anime.Title, &anime.EnglishTitle, &anime.Description,
		&anime.Episodes, &anime.Score, &anime.Type, &anime.Status,
		&anime.Premiered, &anime.Rank, &anime.Popularity, &anime.StartDate,
		&anime.EndDate, &anime.Favorites, &anime.CreatedAt, &anime.UpdatedAt)
	if err != nil {
		return nil, err
	}
	return anime, err
}
Exemplo n.º 20
0
func (self *pgStore) getMeta(key string) (val string, err error) {
	var row *sql.Row
	dbh := self.db

	statement := "select value from meta where key=$1;"
	if row = dbh.QueryRow(statement, key); row != nil {
		row.Scan(&val)
		return val, err
	}
	return "", err
}
Exemplo n.º 21
0
func scanSelectSingle(m *model.ACL, row *sql.Row) error {
	err := row.Scan(
		&m.UID,
		&m.GroupID,
		&m.Object,
		&m.Permission,
		&m.Action,
		&m.CreatedAt,
	)
	return err
}
Exemplo n.º 22
0
func ScanToy(r *sql.Row) (Toy, error) {
	var s Toy
	if err := r.Scan(
		&s.Id,
		&s.Name,
		&s.IsActive,
	); err != nil {
		return Toy{}, err
	}
	return s, nil
}
Exemplo n.º 23
0
func readStripeTokenLine(row *sql.Row) (*StripeToken, error) {
	stripe_token := new(StripeToken)
	if err := row.Scan(
		&stripe_token.Id,
		&stripe_token.Stripe_token,
		&stripe_token.Guest_id,
		&stripe_token.Last4,
	); err != nil {
		return nil, err
	}
	return stripe_token, nil
}
Exemplo n.º 24
0
func ScanEstimate(r *sql.Row) (Estimate, error) {
	var s Estimate
	if err := r.Scan(
		&s.Id,
		&s.Userid,
		&s.Toyid,
		&s.Value,
		&s.CreatedDate,
	); err != nil {
		return Estimate{}, err
	}
	return s, nil
}
Exemplo n.º 25
0
func scanAccount(row *sql.Row) (*Account, error) {
	a := &Account{}
	err := row.Scan(&a.ID, &a.OpenID, &a.Mobile, &a.Email, &a.Password, &a.LoginToken, &a.Nick, &a.Gender,
		&a.Avatar, &a.Birthdate, &a.CreatedAt, &a.Status)
	if err != nil {
		log.Error("scanAccount", err)
		if err == sql.ErrNoRows {
			err = nil
		}
		return nil, err
	}
	return a, nil
}
Exemplo n.º 26
0
Arquivo: web.go Projeto: herokai/hk
func scan(w http.ResponseWriter, r *http.Request, q *sql.Row, v ...interface{}) bool {
	switch err := q.Scan(v...); err {
	case nil:
	case sql.ErrNoRows:
		http.NotFound(w, r)
		return false
	default:
		log.Println(err)
		w.WriteHeader(500)
		return false
	}
	return true
}
Exemplo n.º 27
0
func scanComment(row *sql.Row) (*Comment, error) {
	comment := Comment{}
	err := row.Scan(
		&comment.Id,
		&comment.Created,
		&comment.Email,
		&comment.Name,
		&comment.Body,
		&comment.Url,
		&comment.ClientIp,
		&comment.Approved)
	return &comment, err
}
Exemplo n.º 28
0
func convertCmd(row *sql.Row) (int, string, error) {
	var (
		seq int
		cmd string
	)
	err := row.Scan(&seq, &cmd)
	if err != nil {
		if err == sql.ErrNoRows {
			err = ErrNoMatchingCmd
		}
		return 0, "", err
	}
	return seq, cmd, nil
}
Exemplo n.º 29
0
func ScanUser(r *sql.Row) (User, error) {
	var s User
	if err := r.Scan(
		&s.Id,
		&s.Idp_user_id,
		&s.Name,
		&s.Last_updated,
		&s.Status,
		&s.User_attributes,
	); err != nil {
		return User{}, err
	}
	return s, nil
}
Exemplo n.º 30
0
func TestQueryManyNullsRow(t *testing.T) {
	conn := open(t)
	defer conn.Close()

	var row *sql.Row
	var err error
	if row = conn.QueryRow("select null, null, null, null, null, null, null, null"); err != nil {
		t.Fatal("Query failed", err)
	}
	var v [8]sql.NullInt64
	if err = row.Scan(&v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7]); err != nil {
		t.Fatal("Scan failed", err)
	}
}