Author: fxjr
Date: 2006-10-20 01:23:44 -0400 (Fri, 20 Oct 2006)
New Revision: 66825

Modified:
   trunk/mcs/class/Npgsql/Npgsql/NpgsqlCommand.cs
Log:

2006-10-20  Francisco Figueiredo Jr.  <[EMAIL PROTECTED]>

        * NpgsqlCommand.cs:  Updated to 1.0 final.




Modified: trunk/mcs/class/Npgsql/Npgsql/NpgsqlCommand.cs
===================================================================
--- trunk/mcs/class/Npgsql/Npgsql/NpgsqlCommand.cs      2006-10-20 05:21:40 UTC 
(rev 66824)
+++ trunk/mcs/class/Npgsql/Npgsql/NpgsqlCommand.cs      2006-10-20 05:23:44 UTC 
(rev 66825)
@@ -29,6 +29,7 @@
 using System.Resources;
 using System.ComponentModel;
 using System.Collections;
+using System.IO;
 
 using NpgsqlTypes;
 
@@ -384,8 +385,23 @@
         {
             NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Cancel");
 
-            // [TODO] Finish method implementation.
-            throw new NotImplementedException();
+            try
+            {
+                // get copy for thread safety of null test
+                NpgsqlConnector connector = Connector;
+                if (connector != null)
+                {
+                    connector.CancelRequest();
+                }
+            }
+            catch (IOException)
+            {
+                Connection.ClearPool();
+            }   
+            catch (NpgsqlException)
+            {
+                // Cancel documentation says the Cancel doesn't throw on 
failure
+            }
         }
         
         /// <summary>
@@ -679,6 +695,7 @@
 
             ExecuteCommand();
 
+
             // Now get the results.
             // Only the first column of the first row must be returned.
 
@@ -798,6 +815,10 @@
                     
                     bind = new NpgsqlBind("", planName, new 
Int16[Parameters.Count], null, resultFormatCodes);
                 }    
+                catch (IOException e)
+                {
+                    ClearPoolAndThrowException(e);
+                }
                 catch
                 {
                     // See ExecuteCommand method for a discussion of this.
@@ -1028,8 +1049,12 @@
         
         private Boolean CheckFunctionReturn(String ReturnType)
         {
-            String returnRecordQuery = "select count(*) > 0 from pg_proc p 
left join pg_namespace n on p.pronamespace = n.oid where prorettype = ( select 
oid from pg_type where typname = :typename ) and proargtypes=:proargtypes and 
proname=:proname and n.nspname=:nspname";
+            // Updated after 0.99.3 to support the optional existence of a 
name qualifying schema and allow for case insensitivity
+            // when the schema or procedure name do not contain a quote.
+            // The hard-coded schema name 'public' was replaced with code that 
uses schema as a qualifier, only if it is provided.
 
+            String returnRecordQuery;
+
             StringBuilder parameterTypes = new StringBuilder("");
 
             
@@ -1051,17 +1076,22 @@
             String procedureName = String.Empty;
             
             
-            String[] schemaProcedureName = CommandText.Split('.');
+            String[] fullName = CommandText.Split('.');
             
-            if (schemaProcedureName.Length == 2)
+            if (fullName.Length == 2)
             {
-                schemaName = schemaProcedureName[0];
-                procedureName = schemaProcedureName[1];
+                returnRecordQuery = "select count(*) > 0 from pg_proc p left 
join pg_namespace n on p.pronamespace = n.oid where prorettype = ( select oid 
from pg_type where typname = :typename ) and proargtypes=:proargtypes and 
proname=:proname and n.nspname=:nspname";
+
+                schemaName = (fullName[0].IndexOf("\"") != -1) ? fullName[0] : 
fullName[0].ToLower();
+                procedureName = (fullName[1].IndexOf("\"") != -1) ? 
fullName[1] : fullName[1].ToLower();
             }
             else
             {
-                schemaName = "public";
-                procedureName = CommandText;
+                // Instead of defaulting don't use the nspname, as an 
alternative, query pg_proc and pg_namespace to try and determine the nspname.
+                //schemaName = "public"; // This was removed after build 
0.99.3 because the assumption that a function is in public is often incorrect.
+                returnRecordQuery = "select count(*) > 0 from pg_proc p where 
prorettype = ( select oid from pg_type where typname = :typename ) and 
proargtypes=:proargtypes and proname=:proname";
+                
+                procedureName = (CommandText.IndexOf("\"") != -1) ? 
CommandText : CommandText.ToLower();
             }
                 
             
@@ -1072,12 +1102,16 @@
             c.Parameters.Add(new NpgsqlParameter("typename", 
NpgsqlDbType.Text));
             c.Parameters.Add(new NpgsqlParameter("proargtypes", 
NpgsqlDbType.Text));
             c.Parameters.Add(new NpgsqlParameter("proname", 
NpgsqlDbType.Text));
-            c.Parameters.Add(new NpgsqlParameter("nspname", 
NpgsqlDbType.Text));
             
             c.Parameters[0].Value = ReturnType;
             c.Parameters[1].Value = parameterTypes.ToString();
             c.Parameters[2].Value = procedureName;
-            c.Parameters[3].Value = schemaName;
+
+            if (schemaName != null && schemaName.Length > 0)
+            {
+                c.Parameters.Add(new NpgsqlParameter("nspname", 
NpgsqlDbType.Text));
+                c.Parameters[3].Value = schemaName;
+            }
             
 
             Boolean ret = (Boolean) c.ExecuteScalar();
@@ -1418,6 +1452,9 @@
 
         private void ExecuteCommand()
         {
+            try
+            {
+                
             // Check the connection state first.
             CheckConnectionState();
 
@@ -1474,6 +1511,13 @@
                 }
             }
 
+            }
+
+            catch(IOException e)
+            {
+                ClearPoolAndThrowException(e);
+            }
+
         }
 
         private void SetCommandTimeout()
@@ -1484,6 +1528,13 @@
                 timeout = ConnectionStringDefaults.CommandTimeout;
         }
 
+        private void ClearPoolAndThrowException(Exception e)
+        {
+            Connection.ClearPool();
+            throw new 
NpgsqlException(resman.GetString("Exception_ConnectionBroken"), e);
+
+        }
+
         
          
         

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to