func insertTimeSection(tx *sql.Tx, centerId, startTime, endTime string) (id int64, err error) { sql := "insert into time_section(center_id,start_time,end_time,lesson_no) values(?,?,?,?)" lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(centerId, startTime, endTime, "1") if err != nil { lessgo.Log.Error(err.Error()) return 0, err } newTimeSectionId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return newTimeSectionId, nil }
func (stor *Storage) insertBinaryAnnotations(tx *sql.Tx, span *models.Span) error { stmt, err := tx.Prepare(`INSERT INTO zipkin_annotations VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`) if err != nil { return fmt.Errorf("prepare: %+v", err) } defer stmt.Close() for _, ann := range span.BinaryAnnotations { // BinaryAnnotation.Value is base64, see: https://github.com/openzipkin/zipkin/blob/master/zipkin-common/src/main/scala/com/twitter/zipkin/json/JsonBinaryAnnotation.scala value, err := base64str2sql(ann.Value) if err != nil { return fmt.Errorf("parse value: %+v", value) } ipv4, port, service := ep2sql(ann.Endpoint) _, err = stmt.Exec( hex2int64(span.TraceID), hex2int64(span.ID), ann.Key, value, ann.AnnotationType, span.Timestamp, ipv4, port, service, ) if err != nil { return err } } return nil }
// 保存错误信息 func saveError(tx *sql.Tx, date, message string) error { stmt, err := tx.Prepare("replace into error values(?,?)") if err != nil { return err } defer stmt.Close() // 新增 result, err := stmt.Exec(date, message) if err != nil { return err } ra, err := result.RowsAffected() if err != nil { return err } if ra == 0 { return sql.ErrNoRows } return nil }
func insertVideoContributorRelation(tx *sql.Tx, videoId string, contributorId string) { // 存在チェック stmt, stmtErr := tx.Prepare("SELECT count(video_id) FROM videos_contributors WHERE video_id = ? AND contributor_id = ?") if stmtErr != nil { panic(stmtErr.Error()) } defer stmt.Close() var count int err := stmt.QueryRow(videoId, contributorId).Scan(&count) if err != nil { panic(err.Error()) } defer stmt.Close() if count > 0 { return } stmtIns, stmtInsErr := tx.Prepare("INSERT INTO videos_contributors (video_id, contributor_id) VALUES(?, ?)") if stmtInsErr != nil { panic(stmtInsErr.Error()) } defer stmtIns.Close() _, insErr := stmtIns.Exec(videoId, contributorId) if insErr != nil { panic(insErr.Error()) } defer stmtIns.Close() }
func insertCourse(tx *sql.Tx, centerId, courseName, courseType string) (id int64, err error) { sql := "insert into course(name,center_id,price,is_probation,type,begin_age,end_age,intro,app_display_level,create_time,lesson_num) values(?,?,?,?,?,?,?,?,?,?,?)" lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(courseName, centerId, "0", "0", courseType, "0", "60", courseName, "0", time.Now().Format("20060102150405"), "12") if err != nil { lessgo.Log.Error(err.Error()) return 0, err } newCourseId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return newCourseId, nil }
func insertConsumerStatusLog(tx *sql.Tx, consumerId, employeeId, oldStatus, newStatus string) (id int64, err error) { sql := "insert into consumer_status_log(consumer_id,employee_id,create_time,old_status,new_status) values(?,?,?,?,?)" lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(consumerId, employeeId, time.Now().Format("20060102150405"), oldStatus, newStatus) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } logId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return logId, err }
func StoreOIP041Artifact(o Oip041, txid string, block int, dbtx *sql.Tx) error { // store in database stmtStr := `INSERT INTO 'oip_artifact' ('active','block','json','tags','timestamp', 'title','txid','type','year','publisher') VALUES (?,?,?,?,?,?,?,?,?,?);` stmt, err := dbtx.Prepare(stmtStr) if err != nil { return err } defer stmt.Close() s, err := o.GetJSON() if err != nil { return nil } _, err = stmt.Exec(1, block, s, strings.Join(o.Artifact.Info.ExtraInfo.Tags, ","), o.Artifact.Timestamp, o.Artifact.Info.Title, txid, o.Artifact.Type, o.Artifact.Info.Year, o.Artifact.Publisher) if err != nil { return err } return nil }
func APIGetAllOIP041(dbtx *sql.Tx) ([]Oip041ArtifactAPIResult, error) { stmtStr := `select a.block, a.json, a.tags, a.timestamp, a.title, a.txid, a.type, a.year, a.publisher from oip_artifact as a join publisher as p where p.address = a.publisher and a.invalidated = 0` stmt, err := dbtx.Prepare(stmtStr) if err != nil { return []Oip041ArtifactAPIResult{}, err } defer stmt.Close() rows, err := stmt.Query() if err != nil { return []Oip041ArtifactAPIResult{}, err } var results []Oip041ArtifactAPIResult for rows.Next() { var a Oip041ArtifactAPIResult var s string rows.Scan(&a.Block, &s, &a.Tags, &a.Timestamp, &a.Title, &a.TxID, &a.Type, &a.Year, &a.Publisher) json.Unmarshal([]byte(s), &a.OIP041) results = append(results, a) } stmt.Close() rows.Close() return results, nil }
// Delete will delete all of the configurations whose name is in the list // of names in the arugment. It will not return an error if the name is not found. func (cc *ConfigurationController) Delete(names ...string) (err error) { var ( tx *sql.Tx stmt *sql.Stmt ) tx, err = cc.DB.Begin() if err != nil { tx.Rollback() return err } stmt, err = tx.Prepare("DELETE FROM configurations where config_name = $1") if err != nil { tx.Rollback() return err } for _, name := range names { _, err := stmt.Exec(name) if err == sql.ErrNoRows { err = nil } if err != nil { tx.Rollback() return err } } return tx.Commit() }
// Up is executed when this migration is applied func Up_20160429102901(txn *sql.Tx) { var sql string = "create table if not exists users ( " + "id int(10) unsigned not null auto_increment, " + "created_at int(13) unsigned not null, " + "updated_at int(13) unsigned not null, " + "name varchar(100) not null unique, " + "screen_name varchar(100), " + "mail varchar(100) not null unique, " + "phone varchar(100) unique, " + "avatar varchar(200), " + "gender varchar(10), " + "birth int(13), " + "description text, " + "type varchar(16), " + "password varchar(100), " + "last_login_at int(13), " + "PRIMARY KEY(id) " + ")" stmt, err := txn.Prepare(sql) if err != nil { panic(err.Error()) } _, err = stmt.Exec() if err != nil { panic(err.Error()) } }
func insertParent(tx *sql.Tx, name, password, telephone, comeForm string) (id int64, err error) { sql := "insert into parent(name,password,telephone,reg_date,come_form) values(?,?,?,?,?)" lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(name, password, telephone, time.Now().Format("20060102150405"), comeForm) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } newParentId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return newParentId, nil }
func insertConsumerContactsLog(tx *sql.Tx, createUser, note, consumerId, contactsType string) (id int64, err error) { sql := "insert into consumer_contact_log(create_user,create_time,note,consumer_id,type) values(?,?,?,?,?) " lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(createUser, time.Now().Format("20060102150405"), note, consumerId, contactsType) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } consumerContactsLogId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return consumerContactsLogId, nil }
func insertConsumer(tx *sql.Tx, centerId, contactStatus, homePhone, child, year, month, birthday, lastContactTime, comeFromId, createUser, parttimeName string) (id int64, err error) { sql := "insert into consumer_new(center_id,contact_status,home_phone,create_time,child,year,month,birthday,last_contact_time,come_from_id,create_user_id,parttime_name) values(?,?,?,?,?,?,?,?,?,?,?,?)" lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(centerId, contactStatus, homePhone, time.Now().Format("20060102150405"), child, year, month, birthday, lastContactTime, comeFromId, createUser, parttimeName) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } consumerId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return consumerId, err }
func SaveAttrs(log *logging.Logger, tx *sql.Tx, section *common.Section, metadata common.JSONFile) error { var stmt *sql.Stmt var err error var insert = "INSERT INTO attrs" + "(area, grace, dataset, element, os, username, groupname, type," + " link, mtime, ctime, hash, perms, compressed)" + " VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)" stmt, err = tx.Prepare(insert) if err != nil { log.Debug("Failed prepare: " + err.Error()) return errorMsg(log, 3, "Cannot save Attributes for element "+section.Name) } _, err = stmt.Exec(section.Name, section.Grace, section.Dataset, metadata.Name, metadata.Os, metadata.User, metadata.Group, metadata.Type, metadata.Link, metadata.Mtime, metadata.Ctime, metadata.Hash, metadata.Mode, section.Compressed) if err != nil { log.Debug("Failed execute: " + err.Error()) return errorMsg(log, 4, "Cannot save Attributes for element "+section.Name) } stmt.Close() return nil }
func (s *SQLEngine) consumeMsgIDsToDismiss(tx *sql.Tx, u gregor.UID, mid gregor.MsgID, dmids []gregor.MsgID, ctime time.Time) error { // early out if no msg IDs to dismiss were specified if len(dmids) == 0 { return nil } ins, err := tx.Prepare("INSERT INTO gregor_dismissals_by_id(uid, msgid, dmsgid) VALUES(?, ?, ?)") if err != nil { return err } defer ins.Close() upd, err := tx.Prepare("UPDATE gregor_items SET dtime=? WHERE uid=? AND msgid=?") if err != nil { return err } defer upd.Close() ctimeArg := s.newQueryBuilder().TimeArg(ctime) hexUID := hexEnc(u) hexMID := hexEnc(mid) for _, dmid := range dmids { _, err = ins.Exec(hexUID, hexMID, hexEnc(dmid)) if err != nil { return err } _, err = upd.Exec(ctimeArg, hexUID, hexEnc(dmid)) if err != nil { return err } } return err }
//scheduleId==""为无班签到 func insertSignIn(tx *sql.Tx, scheduleId, childId, signType, contractId, cardId, employeeId, isFree string) (err error) { sql := "" if scheduleId == "" { sql = "insert into sign_in(child_id,sign_time,type,contract_id,card_id,employee_id,is_free) values(?,?,?,?,?,?,?)" } else { sql = "insert into sign_in(child_id,sign_time,schedule_detail_id,type,contract_id,card_id,employee_id,is_free) values(?,?,?,?,?,?,?,?)" } lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return err } if scheduleId == "" { _, err = stmt.Exec(childId, time.Now().Format("20060102150405"), signType, contractId, cardId, employeeId, isFree) } else { _, err = stmt.Exec(childId, time.Now().Format("20060102150405"), scheduleId, signType, contractId, cardId, employeeId, isFree) } if err != nil { lessgo.Log.Error(err.Error()) return err } return nil }
func prepareInsert(tx *sql.Tx) *sql.Stmt { combined, err := tx.Prepare(`merge(n:Ngram { phrase: {0} } ) create unique (n)-[:PRECEDED {p: {2} }]->(nw:NextWord { word: {1} } )`) if err != nil { log.Fatal(err) } return combined }
func updateCourse(tx *sql.Tx, courseDataMap map[string]interface{}, id string) error { sql := "update course set %v where cid=?" params := []interface{}{} setSql := "" for key, value := range courseDataMap { setSql += key + "=?," params = append(params, value) } params = append(params, id) setSql = commonlib.Substr(setSql, 0, len(setSql)-1) sql = fmt.Sprintf(sql, setSql) lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return err } _, err = stmt.Exec(params...) if err != nil { lessgo.Log.Error(err.Error()) return err } return nil }
func insertVideo(tx *sql.Tx, video Thumb, videoId string, postDatetime string, videoPrefix string) { stmtIns, stmtErr := tx.Prepare(` INSERT INTO videos (id, title, description, contributor_id, contributor_name, thumbnail_url, post_datetime, length, view_counter, comment_counter, mylist_counter, prefix) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) if stmtErr != nil { panic(stmtErr.Error()) } defer stmtIns.Close() _, insErr := stmtIns.Exec( videoId, video.Thumb.Title, // video.Thumb.Description // 説明が長すぎる場合に登録に失敗するので一旦空文字とする, "", video.Thumb.ContributorId, video.Thumb.ContributorName, video.Thumb.ThumbnailUrl, postDatetime, video.Thumb.Length, video.Thumb.ViewCounter, video.Thumb.CommentNum, video.Thumb.MylistCounter, videoPrefix) if insErr != nil { panic(insErr.Error()) } }
func createLoadStmt(tableName *string, values *[]string, vld_op string, blWithPK bool, db *sql.Tx, verbose *bool) *sql.Stmt { if len(*values) == 0 { log.Fatalln("Nothing to build insert with!") } var buffer bytes.Buffer buffer.WriteString("INSERT ") if len(vld_op) > 0 && blWithPK { buffer.WriteString(" OR " + vld_op + " ") } buffer.WriteString(" INTO " + (*tableName) + " VALUES (") for i := range *values { buffer.WriteString("?") if i != len(*values)-1 { buffer.WriteString(", ") } } buffer.WriteString(");") if *verbose { fmt.Println(buffer.String()) } stmt, err := db.Prepare(buffer.String()) if err != nil { log.Fatalln(err) } return stmt }
func insertVideoTagRelation(tx *sql.Tx, videoId string, tagId string) { // 存在チェック // ※アルファベット長音記号の有無を区別できずにコンフリクトが発生するため stmt, stmtErr := tx.Prepare("SELECT count(video_id) FROM videos_tags WHERE video_id = ? AND tag_id = ?") if stmtErr != nil { panic(stmtErr.Error()) } defer stmt.Close() var count int err := stmt.QueryRow(videoId, tagId).Scan(&count) if err != nil { panic(err.Error()) } defer stmt.Close() if count > 0 { return } stmtIns, stmtInsErr := tx.Prepare("INSERT INTO videos_tags (video_id, tag_id) VALUES(?, ?)") if stmtInsErr != nil { panic(stmtInsErr.Error()) } defer stmtIns.Close() _, insErr := stmtIns.Exec(videoId, tagId) if insErr != nil { panic(insErr.Error()) } defer stmtIns.Close() }
// 处理分时数据 func savePeroid(tx *sql.Tx, table string, peroid []Peroid60) error { if len(peroid) == 0 { return nil } stmt, err := tx.Prepare("replace into " + table + " values(?,?,?,?,?,?)") if err != nil { return err } defer stmt.Close() for _, p := range peroid { // 新增 result, err := stmt.Exec(p.Time, p.Open, p.Close, p.High, p.Low, p.Volume) if err != nil { return err } ra, err := result.RowsAffected() if err != nil { return err } if ra == 0 { return sql.ErrNoRows } } return nil }
func insertContacts(tx *sql.Tx, name, phone, consumerId string) (id int64, err error) { sql := "insert into contacts(name,phone,is_default,consumer_id) values(?,?,?,?)" lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } res, err := stmt.Exec(name, phone, "1", consumerId) if err != nil { lessgo.Log.Error(err.Error()) return 0, err } contactsId, err := res.LastInsertId() if err != nil { lessgo.Log.Error(err.Error()) return 0, err } return contactsId, nil }
func SaveAcls(log *logging.Logger, tx *sql.Tx, section *common.Section, element string, acls []common.JSONFileAcl) error { var acl common.JSONFileAcl var stmt *sql.Stmt var err error var insert = "INSERT INTO acls" + "(area, grace, dataset, element, name, type, perms)" + " VALUES($1, $2, $3, $4, $5, $6, $7)" stmt, err = tx.Prepare(insert) if err != nil { log.Debug("Failed prepare: " + err.Error()) return errorMsg(log, 1, "Cannot save ACLs for element "+section.Name) } for _, acl = range acls { if acl.User != "" { _, err = stmt.Exec(section.Name, section.Grace, section.Dataset, element, acl.User, "user", acl.Mode) } else { _, err = stmt.Exec(section.Name, section.Grace, section.Dataset, element, acl.Group, "group", acl.Mode) } if err != nil { log.Debug("Failed execute: " + err.Error()) return errorMsg(log, 2, "Cannot save ACLs for element "+section.Name) } } stmt.Close() return nil }
func insertScheduleChild(tx *sql.Tx, childId, scheduleId, classId, employeeId, contractId, isFree string) error { sql := "" if classId != "" { sql += "insert into schedule_detail_child(schedule_detail_id,child_id,create_time,create_user,sms_status,wyclass_id,is_free) values(?,?,?,?,?,?,?) " } else { sql += "insert into schedule_detail_child(schedule_detail_id,child_id,create_time,create_user,sms_status,is_free,contract_id) values(?,?,?,?,?,?,?) " } lessgo.Log.Debug(sql) stmt, err := tx.Prepare(sql) if err != nil { lessgo.Log.Error(err.Error()) return err } if classId != "" { _, err = stmt.Exec(scheduleId, childId, time.Now().Format("20060102150405"), employeeId, 1, classId, isFree) } else { _, err = stmt.Exec(scheduleId, childId, time.Now().Format("20060102150405"), employeeId, 1, isFree, contractId) } if err != nil { lessgo.Log.Error(err.Error()) return err } return nil }
func dbContainerConfigInsert(tx *sql.Tx, id int, config map[string]string) error { str := "INSERT INTO containers_config (container_id, key, value) values (?, ?, ?)" stmt, err := tx.Prepare(str) if err != nil { return err } defer stmt.Close() for k, v := range config { if k == "raw.lxc" { err := validateRawLxc(config["raw.lxc"]) if err != nil { return err } } if !ValidContainerConfigKey(k) { return fmt.Errorf("Bad key: %s\n", k) } _, err = stmt.Exec(id, k, v) if err != nil { shared.Debugf("Error adding configuration item %s = %s to container %d\n", k, v, id) return err } } return nil }
func (qs *QuadStore) copyFrom(tx *sql.Tx, in []graph.Delta) error { stmt, err := tx.Prepare(pq.CopyIn("quads", "subject", "predicate", "object", "label", "id", "ts", "subject_hash", "predicate_hash", "object_hash", "label_hash")) if err != nil { return err } for _, d := range in { _, err := stmt.Exec( d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label, d.ID.Int(), d.Timestamp, hashOf(d.Quad.Subject), hashOf(d.Quad.Predicate), hashOf(d.Quad.Object), hashOf(d.Quad.Label), ) if err != nil { glog.Errorf("couldn't prepare COPY statement: %v", err) return err } } _, err = stmt.Exec() if err != nil { return err } return stmt.Close() }
func HandleOIP041Edit(o Oip041, txid string, block int, dbtx *sql.Tx) error { // ToDo: This is super ugly patch := UnSquashPatch(strings.Replace(string(o.Edit.Patch), `"path":"/`, `"path":"/artifact/`, -1)) fmt.Printf("Patch:\n%s\n", patch) obj, err := jsonpatch.DecodePatch([]byte(patch)) if err != nil { log.Fatalf("Failed to decode patch:\n%v", err) } // ToDo: Check the signature... but first decide what to sign stmtstr := `SELECT json,txid,publisher FROM oip_artifact WHERE txid=? LIMIT 1` stmt, err := dbtx.Prepare(stmtstr) if err != nil { fmt.Println("RIP Handle Edit 1") log.Fatal(err) } row := stmt.QueryRow(o.Edit.TxID) var sJSON string var publisher string var txID string err = row.Scan(&sJSON, &txID, &publisher) if err != nil { fmt.Println("RIP Handle Edit 2") log.Fatal(err) } stmt.Close() fmt.Printf("Pre-Patch:\n%s\n", sJSON) out, err := obj.Apply([]byte(sJSON)) if err != nil { log.Fatalf("Failed to apply patch:\n%v", err) } fmt.Printf("Post-Patch Result:\n%s\n", string(out)) stmtstr = `UPDATE oip_artifact SET json=? WHERE txid=?` // ToDo: apply update to searchable meta-data stmt, err = dbtx.Prepare(stmtstr) if err != nil { fmt.Println("exit 600") log.Fatal(err) } _, stmterr := stmt.Exec(string(out), o.Edit.TxID) if stmterr != nil { fmt.Println("exit 601") log.Fatal(stmterr) } stmt.Close() return nil }
func HandleOIP041Edit(o Oip041, txid string, block int, dbtx *sql.Tx) error { // ToDo: Check the signature... but first decide what to sign stmtstr := `SELECT ('json','txid','publisher') FROM oip_artifact WHERE txid=? LIMIT 1` stmt, err := dbtx.Prepare(stmtstr) if err != nil { fmt.Println("RIP Handle Edit 1") log.Fatal(err) } row := stmt.QueryRow(txid) var old Oip041 var sJSON string var publisher string var txID string err = row.Scan(&sJSON, &txID, &publisher) if err != nil { fmt.Println("RIP Handle Edit 2") log.Fatal(err) } err = json.Unmarshal([]byte(sJSON), &old) if err != nil { fmt.Println("RIP Handle Edit 3") return err } if len(o.Edit.Add) > 0 { // we got stuff to add } if len(o.Edit.Edit) > 0 { // we got stuff to edit for k, v := range o.Edit.Edit { p := strings.Split(k, ".") if len(p) == 1 { updateField(k, v, txid, dbtx) // something along these lines... } } } if len(o.Edit.Remove) > 0 { // we got stuff to remove } b, err := json.Marshal(old) if err != nil { fmt.Println("RIP Handle Edit 4") return err } fmt.Println(string(b)) return nil }
func (qs *QuadStore) runTxPostgres(tx *sql.Tx, in []graph.Delta, opts graph.IgnoreOpts) error { allAdds := true for _, d := range in { if d.Action != graph.Add { allAdds = false } } if allAdds { return qs.copyFrom(tx, in) } insert, err := tx.Prepare(`INSERT INTO quads(subject, predicate, object, label, id, ts, subject_hash, predicate_hash, object_hash, label_hash) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`) defer insert.Close() if err != nil { glog.Errorf("Cannot prepare insert statement: %v", err) return err } for _, d := range in { switch d.Action { case graph.Add: _, err := insert.Exec( d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label, d.ID.Int(), d.Timestamp, hashOf(d.Quad.Subject), hashOf(d.Quad.Predicate), hashOf(d.Quad.Object), hashOf(d.Quad.Label), ) if err != nil { glog.Errorf("couldn't prepare INSERT statement: %v", err) return err } case graph.Delete: result, err := tx.Exec(`DELETE FROM quads WHERE subject=$1 and predicate=$2 and object=$3 and label=$4;`, d.Quad.Subject, d.Quad.Predicate, d.Quad.Object, d.Quad.Label) if err != nil { glog.Errorf("couldn't exec DELETE statement: %v", err) return err } affected, err := result.RowsAffected() if err != nil { glog.Errorf("couldn't get DELETE RowsAffected: %v", err) return err } if affected != 1 && !opts.IgnoreMissing { return errors.New("deleting non-existent triple; rolling back") } default: panic("unknown action") } } return nil }