From c4a4f834f79fe49c31e1e9ae02d448aa8081c6ff Mon Sep 17 00:00:00 2001 From: Gerhard Gruber Date: Wed, 8 Sep 2021 08:04:46 +0200 Subject: [PATCH] Added GetSQLWhereClause --- expression_ext.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/expression_ext.go b/expression_ext.go index 8052a6be..746faaa1 100644 --- a/expression_ext.go +++ b/expression_ext.go @@ -465,6 +465,31 @@ func (db *DB) GetSQL() string { return stmt } +func (db *DB) GetSQL() string { + scope := db.NewScope(db.Value) + + scope.prepareQuerySQL() + + stmt := scope.SQL + for _, arg := range scope.SQLVars { + stmt = strings.Replace(stmt, "?", "'"+escape(fmt.Sprintf("%v", arg))+"'", 1) + } + + return stmt +} + +func (db *DB) GetSQLWhereClause() string { + scope := db.NewScope(db.Value) + + stmt := scope.CombinedConditionSql() + + for _, arg := range scope.SQLVars { + stmt = strings.Replace(stmt, "?", "'"+escape(fmt.Sprintf("%v", arg))+"'", 1) + } + + return stmt +} + func escape(source string) string { var j int = 0 if len(source) == 0 {