From 2273d4117fd50ee44dcdaa28fd6444383dc403a0 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 26 Jan 2010 08:45:16 -0500
Subject: [PATCH] - Add support for MDB2's 'sqlsrv' driver (#1486395)

---
 program/lib/MDB2/Driver/Datatype/mssql.php |   66 +++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/program/lib/MDB2/Driver/Datatype/mssql.php b/program/lib/MDB2/Driver/Datatype/mssql.php
index fff343c..dcabed2 100644
--- a/program/lib/MDB2/Driver/Datatype/mssql.php
+++ b/program/lib/MDB2/Driver/Datatype/mssql.php
@@ -44,7 +44,7 @@
 // |          Daniel Convissor <danielc@php.net>                          |
 // +----------------------------------------------------------------------+
 //
-// $Id: mssql.php,v 1.65 2008/02/19 14:54:17 afz Exp $
+// $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $
 //
 
 require_once 'MDB2/Driver/Datatype/Common.php';
@@ -71,7 +71,7 @@
      */
     function _baseConvertResult($value, $type, $rtrim = true)
     {
-        if (is_null($value)) {
+        if (null === $value) {
             return null;
         }
         switch ($type) {
@@ -228,7 +228,7 @@
             if ($field['default'] === '') {
                 $field['default'] = 0;
             }
-            if (is_null($field['default'])) {
+            if (null === $field['default']) {
                 $default = ' DEFAULT (null)';
             } else {
                 $default = ' DEFAULT (' . $this->quote($field['default'], 'integer') . ')';
@@ -339,6 +339,65 @@
     }
 
     // }}}
+    // {{{ matchPattern()
+
+    /**
+     * build a pattern matching string
+     *
+     * @access public
+     *
+     * @param array $pattern even keys are strings, odd are patterns (% and _)
+     * @param string $operator optional pattern operator (LIKE, ILIKE and maybe others in the future)
+     * @param string $field optional field name that is being matched against
+     *                  (might be required when emulating ILIKE)
+     *
+     * @return string SQL pattern
+     */
+    function matchPattern($pattern, $operator = null, $field = null)
+    {
+        $db =& $this->getDBInstance();
+        if (PEAR::isError($db)) {
+            return $db;
+        }
+
+        $match = '';
+        if (null !== $operator) {
+            $field = (null === $field) ? '' : $field.' ';
+            $operator = strtoupper($operator);
+            switch ($operator) {
+            // case insensitive
+            case 'ILIKE':
+                $match = $field.'LIKE ';
+                break;
+            case 'NOT ILIKE':
+                $match = $field.'NOT LIKE ';
+                break;
+            // case sensitive
+            case 'LIKE':
+                $match = $field.'LIKE ';
+                break;
+            case 'NOT LIKE':
+                $match = $field.'NOT LIKE ';
+                break;
+            default:
+                return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
+                    'not a supported operator type:'. $operator, __FUNCTION__);
+            }
+        }
+        $match.= "'";
+        foreach ($pattern as $key => $value) {
+            if ($key % 2) {
+                $match.= $value;
+            } else {
+                $match.= $db->escapePattern($db->escape($value));
+            }
+        }
+        $match.= "'";
+        $match.= $this->patternEscapeString();
+        return $match;
+    }
+
+    // }}}
     // {{{ _mapNativeDatatype()
 
     /**
@@ -376,6 +435,7 @@
             $type[0] = 'integer';
             $length = 8;
             break;
+        case 'smalldatetime':
         case 'datetime':
             $type[0] = 'timestamp';
             break;

--
Gitblit v1.9.1