Exemplo n.º 1
0
func (tbl *Table) NamedExecTx(tx sqlx.Ext, cmd string, val interface{}) (int64, error) {
	if tx == nil {
		tx = tbl.Db.DB
	}
	log.Println("Cmd:", cmd)
	res, err := sqlx.NamedExec(tx, cmd, val)
	var rowsAffected int64 = 0
	if err == nil {
		rowsAffected, err = res.RowsAffected()
	}
	if err != nil {
		log.Println("NamedExec: Error:", err)
	}
	return rowsAffected, err
}
Exemplo n.º 2
-1
func (tbl *Table) InsertTx(tx sqlx.Ext, val interface{}) (int64, error) {
	if tx == nil {
		tx = tbl.Db.DB
	}
	cmd := "insert into " + tbl.Name + " (" + tbl._fieldnames + ") VALUES (" + tbl._valuenames + ")"
	log.Println("Cmd:", cmd)
	res, err := sqlx.NamedExec(tx, cmd, val)
	var lastInserId int64 = 0
	if err == nil {
		lastInserId, err = res.LastInsertId()
	}
	if err != nil {
		log.Println("Error:", err)
	}
	return lastInserId, err
}