func (this *InsertBuilder) Column(insert *db.Insert) { values := insert.GetValues() parameters := insert.GetParameters() var val string for it := values.Iterator(); it.HasNext(); { entry := it.Next() column := entry.Key.(*db.Column) // use only not virtual columns token := entry.Value.(db.Tokener) // only includes null keys if IgnoreNullKeys is false if column.IsKey() && this.translator.IgnoreNullKeys() && db.TOKEN_PARAM == token.GetOperator() { param := token.GetValue().(string) if parameters[param] != nil { val = this.translator.Translate(db.INSERT, token) } } else { val = this.translator.Translate(db.INSERT, token) } col := this.translator.ColumnName(column) if val != "" { this.columnPart.Add(col) this.valuePart.Add(val) } val = "" } }
// INSERT func (this *PostgreSQLTranslator) GetSqlForInsert(insert *db.Insert) string { // insert generated by super sql := this.GenericTranslator.GetSqlForInsert(insert) // only ONE numeric id is allowed // if no value was defined for the key, it is assumed an auto number, // otherwise is a guid (or something else) singleKeyColumn := insert.GetTable().GetSingleKeyColumn() if !insert.HasKeyValue && singleKeyColumn != nil { str := tk.NewStrBuffer() str.Add(sql, " RETURNING ", this.overrider.ColumnName(singleKeyColumn)) sql = str.String() } return sql }
func (this *InsertBuilder) From(insert *db.Insert) { table := insert.GetTable() this.tablePart.Add(this.translator.TableName(table)) }