本文整理汇总了Golang中database/sql.Stmt类的典型用法代码### 示例。如果您正苦于以下问题:Golang Stmt类的具体用法?Golang Stmt怎么用?Golang Stmt使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。

在下文中一共展示了Stmt类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: AddNewUser

func (gkDbCon *GkDbConDef) AddNewUser(userName string, passwordHash string, passwordSalt string, email string) *gkerr.GkErrDef {

    var stmt *sql.Stmt
    var err error

    var id int64
    var gkErr *gkerr.GkErrDef

    id, gkErr = gkDbCon.getNextUsersId()
    if gkErr != nil {
        return gkErr
    }

    stmt, err = gkDbCon.sqlDb.Prepare("insert into users (id, user_name, password_hash, password_salt, email, account_creation_date, last_login_date) values ($1, $2, $3, $4, $5, $6, $7)")
    if err != nil {
        return gkerr.GenGkErr("stmt.Prepare"+getDatabaseErrorMessage(err), err, ERROR_ID_PREPARE)
    }

    defer stmt.Close()

    var accountCreationDate time.Time = time.Now()
    var lastLoginDate time.Time = time.Now()

    _, err = stmt.Exec(id, userName, passwordHash, passwordSalt, email, accountCreationDate, lastLoginDate)
    if err != nil {
        if isUniqueViolation(err) {
            return gkerr.GenGkErr("stmt.Exec unique violation", err, ERROR_ID_UNIQUE_VIOLATION)
        }
        return gkerr.GenGkErr("stmt.Exec"+getDatabaseErrorMessage(err), err, ERROR_ID_EXECUTE)
    }

    return nil
}

开发者ID:gk-turnip,项目名称:server,代码行数:33,代码来源:users.go

示例2: getMaxChatId

func (gkDbCon *GkDbConDef) getMaxChatId() (int32, *gkerr.GkErrDef) {
    var stmt *sql.Stmt
    var maxId int32 = 0
    var err error

    stmt, err = gkDbCon.sqlDb.Prepare("select max(id) from chat_archives")
    if err != nil {
        return 0, gkerr.GenGkErr("sql.Prepare"+getDatabaseErrorMessage(err), err, ERROR_ID_PREPARE)
    }

    defer stmt.Close()

    var rows *sql.Rows

    rows, err = stmt.Query()
    if err != nil {
        return 0, gkerr.GenGkErr("stmt.Query"+getDatabaseErrorMessage(err), err, ERROR_ID_QUERY)
    }

    defer rows.Close()

    if rows.Next() {
        err = rows.Scan(&maxId)
        if err != nil {
            return 0, gkerr.GenGkErr("rows.Scan"+getDatabaseErrorMessage(err), err, ERROR_ID_ROWS_SCAN)
        }
    }

    return maxId, nil
}

开发者ID:gk-turnip,项目名称:server,代码行数:30,代码来源:chatArchives.go

示例3: GeoipLookup

func GeoipLookup(stmt *sql.Stmt, ip string) (*GeoIP, error) {
    IP := net.ParseIP(ip)
    reserved := false
    for _, net := range reservedIPs {
        if net.Contains(IP) {
            reserved = true
            break
        }
    }
    geoip := GeoIP{Ip: ip}
    if reserved {
        geoip.CountryCode = "RD"
        geoip.CountryName = "Reserved"
    } else {
        var uintIP uint32
        b := bytes.NewBuffer(IP.To4())
        binary.Read(b, binary.BigEndian, &uintIP)
        if err := stmt.QueryRow(uintIP).Scan(
            &geoip.CountryCode,
            &geoip.CountryName,
            &geoip.RegionCode,
            &geoip.RegionName,
            &geoip.CityName,
            &geoip.ZipCode,
            &geoip.Latitude,
            &geoip.Longitude,
            &geoip.MetroCode,
            &geoip.AreaCode,
        ); err != nil {
            return nil, err
        }
    }
    return &geoip, nil
}

开发者ID:hatahet,项目名称:freegeoip,代码行数:34,代码来源:freegeoip.go

示例4: ProtocollCheck

// DBID is the ID of the correspondig metadata record
func (conn *watcherdb) ProtocollCheck(id database.DBID, isnew bool, messages []ogdat.CheckMessage) error {

    // This is append only; revise later if it should also delete or update entries.
    const insstmt = "INSERT INTO status(datasetid, field_id, status, fieldstatus, reason_text, hittime) VALUES ($1, $2, $3, $4, $5, $6)"

    var stmt *sql.Stmt
    var err error
    if stmt, err = conn.Prepare(insstmt); err != nil {
        return err
    }

    // get time here and not within the loop so we have a grouping possibilitiy
    t := time.Now().UTC()
    var status string
    for _, msg := range messages {
        switch {
        case (msg.Type & ogdat.Error) != 0:
            status = "error"
        case (msg.Type & ogdat.Warning) != 0:
            status = "warning"
        case (msg.Type & ogdat.Info) != 0:
            status = "info"
        }
        if _, err = stmt.Exec(id, msg.OGDID, status, msg.Type, msg.Text, t); err != nil {
            return fmt.Errorf("Error inserting status for datasetid %d, fieldid %d: %s", id, msg.OGDID, err)
        }
    }
    return nil
}

开发者ID:the42,项目名称:ogdat,代码行数:30,代码来源:database.go

示例5: lookup

func lookup(stmt *sql.Stmt, IP net.IP, nIP uint32) (*GeoIP, error) {
    var reserved bool
    for _, net := range reservedIPs {
        if net.Contains(IP) {
            reserved = true
            break
        }
    }
    geoip := GeoIP{Ip: IP.String()}
    if reserved {
        geoip.CountryCode = "RD"
        geoip.CountryName = "Reserved"
    } else {
        if err := stmt.QueryRow(nIP).Scan(
            &geoip.CountryCode,
            &geoip.CountryName,
            &geoip.RegionCode,
            &geoip.RegionName,
            &geoip.CityName,
            &geoip.ZipCode,
            &geoip.Latitude,
            &geoip.Longitude,
            &geoip.MetroCode,
            &geoip.AreaCode,
        ); err != nil {
            return nil, err
        }
    }
    return &geoip, nil
}

开发者ID:jrumbut,项目名称:freegeoip,代码行数:30,代码来源:freegeoip.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng