MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / RemoveRemote

Function RemoveRemote

cli/internal/dal/remote.go:95–159  ·  view source on GitHub ↗
(remoteId int, host string, userName string)

Source from the content-addressed store, hash-verified

93}
94
95func RemoveRemote(remoteId int, host string, userName string) error {
96 db := getDb()
97 defer db.Close()
98
99 // 数据校验
100 var exitCount, referenceCount int
101 var row *sql.Row
102 if len(host) > 0 {
103 row = db.QueryRow(`select count(1) exitCount,
104 (select count(1) from workspace where w_is_del = 0 and r_id = remote.r_id) referenceCount
105 from remote
106 where r_addr=? and r_username = ? and r_is_del = 0`, host, userName)
107 } else if remoteId > 0 {
108 row = db.QueryRow("select count(1) exitCount,(select count(1) from workspace where w_is_del = 0 and r_id = remote.r_id) referenceCount from remote where r_id=? and r_is_del = 0", remoteId)
109 }
110 switch err := row.Scan(&exitCount, &referenceCount); err {
111 case sql.ErrNoRows:
112 msg := fmt.Sprintf("remote (%v | %v)", remoteId, host)
113 common.SmartIDELog.WarningF(i18nInstance.Common.Warn_dal_record_not_exit_condition, msg) // 没有查询到数据
114 case nil:
115 if exitCount <= 0 { // 没有找到相关的记录
116 return errors.New(i18nInstance.Common.Warn_dal_record_not_exit)
117 } else if exitCount > 1 { // 存在多条记录
118 return errors.New(i18nInstance.Common.Err_dal_record_repeat)
119 }
120 default:
121 return err
122 }
123
124 // 是否被其他的workspace引用
125 if referenceCount > 0 {
126 return errors.New(i18nInstance.Common.Err_dal_remote_reference_by_workspace)
127 }
128
129 //
130 var stmt *sql.Stmt
131 var err error
132 if len(host) > 0 {
133 stmt, err = db.Prepare("update remote set r_is_del=1 where r_addr=? and r_is_del = 0")
134 } else if remoteId > 0 {
135 stmt, err = db.Prepare("update remote set r_is_del=1 where r_id=? and r_is_del = 0")
136 }
137 if err != nil {
138 return err
139 }
140 res, err := stmt.Exec(remoteId, host)
141 if err != nil {
142 return err
143 }
144 affect, err := res.RowsAffected()
145 if err != nil {
146 return err
147 }
148
149 //
150 if affect != 1 {
151 if affect <= 0 {
152 return errors.New(i18nInstance.Common.Err_dal_update_fail) // 更新失败

Callers

nothing calls this directly

Calls 4

getDbFunction · 0.85
WarningFMethod · 0.80
ExecMethod · 0.80
WarningMethod · 0.80

Tested by

no test coverage detected