Revert "PERF: remove double checked empty params (#18)"

Revert “PERF: remove double checked empty params (#18)”

This reverts commit 86071d688210ed7ed34587659e645e1afd774074.

This commit broke the interface which Discourse consumed, to avoid double checking I will amend inline encoder

diff --git a/lib/mini_sql/mysql/connection.rb b/lib/mini_sql/mysql/connection.rb
index aee5781..51e6de7 100644
--- a/lib/mini_sql/mysql/connection.rb
+++ b/lib/mini_sql/mysql/connection.rb
@@ -50,7 +50,9 @@ module MiniSql
       private
 
       def run(sql, as, params)
-        sql = param_encoder.encode(sql, *params)
+        if params && params.length > 0
+          sql = param_encoder.encode(sql, *params)
+        end
         raw_connection.query(
           sql,
           as: as,
diff --git a/lib/mini_sql/postgres/connection.rb b/lib/mini_sql/postgres/connection.rb
index d56f787..188a157 100644
--- a/lib/mini_sql/postgres/connection.rb
+++ b/lib/mini_sql/postgres/connection.rb
@@ -97,7 +97,9 @@ module MiniSql
 
       def query_each(sql, *params)
         raise StandardError, "Please supply a block when calling query_each" if !block_given?
-        sql = param_encoder.encode(sql, *params)
+        if params && params.length > 0
+          sql = param_encoder.encode(sql, *params)
+        end
 
         raw_connection.send_query(sql)
         raw_connection.set_single_row_mode
@@ -128,7 +130,9 @@ module MiniSql
 
       def query_each_hash(sql, *params)
         raise StandardError, "Please supply a block when calling query_each_hash" if !block_given?
-        sql = param_encoder.encode(sql, *params)
+        if params && params.length > 0
+          sql = param_encoder.encode(sql, *params)
+        end
 
         raw_connection.send_query(sql)
         raw_connection.set_single_row_mode
@@ -191,7 +195,9 @@ module MiniSql
       private
 
       def run(sql, params)
-        sql = param_encoder.encode(sql, *params)
+        if params && params.length > 0
+          sql = param_encoder.encode(sql, *params)
+        end
         raw_connection.async_exec(sql)
       end
 
diff --git a/lib/mini_sql/postgres_jdbc/connection.rb b/lib/mini_sql/postgres_jdbc/connection.rb
index ef12181..d2f665e 100644
--- a/lib/mini_sql/postgres_jdbc/connection.rb
+++ b/lib/mini_sql/postgres_jdbc/connection.rb
@@ -89,7 +89,7 @@ module MiniSql
       private
 
       def run(sql, params)
-        sql = param_encoder.encode(sql, *params)
+        sql = param_encoder.encode(sql, *params) if params && params.length > 0
         conn = raw_connection
         conn.typemap = self.class.typemap
         conn.execute(sql)
diff --git a/lib/mini_sql/sqlite/connection.rb b/lib/mini_sql/sqlite/connection.rb
index 611ad41..d293049 100644
--- a/lib/mini_sql/sqlite/connection.rb
+++ b/lib/mini_sql/sqlite/connection.rb
@@ -63,7 +63,9 @@ module MiniSql
       private
 
       def run(sql, *params)
-        sql = param_encoder.encode(sql, *params)
+        if params && params.length > 0
+          sql = param_encoder.encode(sql, *params)
+        end
         if block_given?
           stmt = SQLite3::Statement.new(raw_connection, sql)
           yield stmt.execute

GitHub sha: d7e7b381