mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Retry create issue to cope with duplicate keys (#7898)
* Retry create issue to cope with duplicate keys * Use .SetExpr().Where().Insert()
This commit is contained in:
		
				
					committed by
					
						 techknowlogick
						techknowlogick
					
				
			
			
				
	
			
			
			
						parent
						
							541fab196f
						
					
				
				
					commit
					5fe2ec264f
				
			
							
								
								
									
										35
									
								
								vendor/github.com/go-xorm/xorm/statement.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										35
									
								
								vendor/github.com/go-xorm/xorm/statement.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -6,7 +6,6 @@ package xorm | ||||
|  | ||||
| import ( | ||||
| 	"database/sql/driver" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| @@ -398,7 +397,7 @@ func (statement *Statement) buildUpdates(bean interface{}, | ||||
| 								continue | ||||
| 							} | ||||
| 						} else { | ||||
| 							//TODO: how to handler? | ||||
| 							// TODO: how to handler? | ||||
| 							panic("not supported") | ||||
| 						} | ||||
| 					} else { | ||||
| @@ -579,21 +578,9 @@ func (statement *Statement) getExpr() map[string]exprParam { | ||||
|  | ||||
| func (statement *Statement) col2NewColsWithQuote(columns ...string) []string { | ||||
| 	newColumns := make([]string, 0) | ||||
| 	quotes := append(strings.Split(statement.Engine.Quote(""), ""), "`") | ||||
| 	for _, col := range columns { | ||||
| 		col = strings.Replace(col, "`", "", -1) | ||||
| 		col = strings.Replace(col, statement.Engine.QuoteStr(), "", -1) | ||||
| 		ccols := strings.Split(col, ",") | ||||
| 		for _, c := range ccols { | ||||
| 			fields := strings.Split(strings.TrimSpace(c), ".") | ||||
| 			if len(fields) == 1 { | ||||
| 				newColumns = append(newColumns, statement.Engine.quote(fields[0])) | ||||
| 			} else if len(fields) == 2 { | ||||
| 				newColumns = append(newColumns, statement.Engine.quote(fields[0])+"."+ | ||||
| 					statement.Engine.quote(fields[1])) | ||||
| 			} else { | ||||
| 				panic(errors.New("unwanted colnames")) | ||||
| 			} | ||||
| 		} | ||||
| 		newColumns = append(newColumns, statement.Engine.Quote(eraseAny(col, quotes...))) | ||||
| 	} | ||||
| 	return newColumns | ||||
| } | ||||
| @@ -764,7 +751,9 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition | ||||
| 			return statement | ||||
| 		} | ||||
| 		tbs := strings.Split(tp.TableName(), ".") | ||||
| 		var aliasName = strings.Trim(tbs[len(tbs)-1], statement.Engine.QuoteStr()) | ||||
| 		quotes := append(strings.Split(statement.Engine.Quote(""), ""), "`") | ||||
|  | ||||
| 		var aliasName = strings.Trim(tbs[len(tbs)-1], strings.Join(quotes, "")) | ||||
| 		fmt.Fprintf(&buf, "(%s) %s ON %v", subSQL, aliasName, condition) | ||||
| 		statement.joinArgs = append(statement.joinArgs, subQueryArgs...) | ||||
| 	case *builder.Builder: | ||||
| @@ -774,7 +763,9 @@ func (statement *Statement) Join(joinOP string, tablename interface{}, condition | ||||
| 			return statement | ||||
| 		} | ||||
| 		tbs := strings.Split(tp.TableName(), ".") | ||||
| 		var aliasName = strings.Trim(tbs[len(tbs)-1], statement.Engine.QuoteStr()) | ||||
| 		quotes := append(strings.Split(statement.Engine.Quote(""), ""), "`") | ||||
|  | ||||
| 		var aliasName = strings.Trim(tbs[len(tbs)-1], strings.Join(quotes, "")) | ||||
| 		fmt.Fprintf(&buf, "(%s) %s ON %v", subSQL, aliasName, condition) | ||||
| 		statement.joinArgs = append(statement.joinArgs, subQueryArgs...) | ||||
| 	default: | ||||
| @@ -1157,8 +1148,12 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string, needLimit, n | ||||
| 			if statement.Start != 0 || statement.LimitN != 0 { | ||||
| 				oldString := buf.String() | ||||
| 				buf.Reset() | ||||
| 				rawColStr := columnStr | ||||
| 				if rawColStr == "*" { | ||||
| 					rawColStr = "at.*" | ||||
| 				} | ||||
| 				fmt.Fprintf(&buf, "SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d", | ||||
| 					columnStr, columnStr, oldString, statement.Start+statement.LimitN, statement.Start) | ||||
| 					columnStr, rawColStr, oldString, statement.Start+statement.LimitN, statement.Start) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -1242,7 +1237,7 @@ func (statement *Statement) convertUpdateSQL(sqlStr string) (string, string) { | ||||
|  | ||||
| 	var whereStr = sqls[1] | ||||
|  | ||||
| 	//TODO: for postgres only, if any other database? | ||||
| 	// TODO: for postgres only, if any other database? | ||||
| 	var paraStr string | ||||
| 	if statement.Engine.dialect.DBType() == core.POSTGRES { | ||||
| 		paraStr = "$" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user