From 8e78223584ec1445303f968a61401aa28d16f33f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Sat, 18 Apr 2009 16:14:35 +0200
Subject: [PATCH] Added support for NULL values for %s-parameters.

Rev: lib/modules/Sql.pmod/Sql.pike:1.95
---
 lib/modules/Sql.pmod/Sql.pike | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/lib/modules/Sql.pmod/Sql.pike b/lib/modules/Sql.pmod/Sql.pike
index 2d471a122f..65c23d8d70 100644
--- a/lib/modules/Sql.pmod/Sql.pike
+++ b/lib/modules/Sql.pmod/Sql.pike
@@ -1,5 +1,5 @@
 /*
- * $Id: Sql.pike,v 1.94 2009/04/18 12:27:15 grubba Exp $
+ * $Id: Sql.pike,v 1.95 2009/04/18 14:14:35 grubba Exp $
  *
  * Implements the generic parts of the SQL-interface
  *
@@ -405,6 +405,26 @@ string|object compile_query(string q)
   return q;
 }
 
+//! Wrapper to handle zero.
+protected class ZeroWrapper
+{
+  //! @returns
+  //!   Returns the following:
+  //!   @string
+  //!     @value "NULL"
+  //!       If @[fmt] is @expr{'s'@}.
+  //!     @value "ZeroWrapper()"
+  //!       If @[fmt] is @expr{'O'@}.
+  //!   @endstring
+  //!   Otherwise it formats a zero.
+  protected string _sprintf(int fmt, mapping(string:mixed) params)
+  {
+    if (fmt == 's') return "NULL";
+    if (fmt == 'O') return "ZeroWrapper()";
+    return sprintf(sprintf("%%*%c", fmt), params, 0);
+  }
+}
+
 //! Handle @[sprintf]-based quoted arguments
 //!
 //! @param query
@@ -435,7 +455,7 @@ protected array(string|mapping(string|int:mixed))
       continue;
     }
     if (intp(s) || floatp(s)) {
-      args[j]=s;
+      args[j] = s || ZeroWrapper();
       continue;
     }
     ERROR("Wrong type to query argument #"+(j+1)+".\n");
-- 
GitLab