commit 3faf3a3fa855f64fd02138b006ef3c1e0709c2ab
Author: Damien Tournoud <damien@commerceguys.com>
Date:   Tue May 24 18:31:30 2011 +0200

    Issue #1154528: Properly handle the default user schema when it is not 'dbo'.

diff --git a/sqlsrv/database.inc b/sqlsrv/database.inc
index 9e90352..802a5ae 100755
--- a/sqlsrv/database.inc
+++ b/sqlsrv/database.inc
@@ -60,6 +60,10 @@ class DatabaseConnection_sqlsrv extends DatabaseConnection {
     ));
 
     $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+    // Fetch the name of the user-bound schema. It is the schema that SQL Server
+    // will use for non-qualified tables.
+    $this->schema()->defaultSchema = $this->query("SELECT SCHEMA_NAME()")->fetchField();
   }
 
   /**
@@ -297,7 +301,7 @@ class DatabaseConnection_sqlsrv extends DatabaseConnection {
       'IF',
     );
     foreach ($functions as $function) {
-      $query = preg_replace('/\b(?<![:.])(' . preg_quote($function) . ')\(/i', 'dbo.$1(', $query);
+      $query = preg_replace('/\b(?<![:.])(' . preg_quote($function) . ')\(/i', $this->schema()->defaultSchema . '.$1(', $query);
     }
 
     $replacements = array(
diff --git a/sqlsrv/schema.inc b/sqlsrv/schema.inc
index 5f17395..9868921 100755
--- a/sqlsrv/schema.inc
+++ b/sqlsrv/schema.inc
@@ -15,7 +15,7 @@ class DatabaseSchema_sqlsrv extends DatabaseSchema {
   /**
    * Default schema for SQL Server databases.
    */
-  protected $defaultSchema = 'dbo';
+  public $defaultSchema = 'dbo';
 
   protected $additionalColumnInformation = NULL;
 
