List:Commits« Previous MessageNext Message »
From:rburnett Date:September 4 2008 9:09pm
Subject:Connector/NET commit: r1401 - in trunk/MySql.VisualStudio: DDEX Nodes
View as plain text  
Modified:
   trunk/MySql.VisualStudio/DDEX/MySqlDataViewCommandHandler.cs
   trunk/MySql.VisualStudio/Nodes/StoredProcedureNode.cs
Log:
got new function working and also using better new proc or new function text.

Modified: trunk/MySql.VisualStudio/DDEX/MySqlDataViewCommandHandler.cs
===================================================================
--- trunk/MySql.VisualStudio/DDEX/MySqlDataViewCommandHandler.cs	2008-09-04 17:52:41 UTC
(rev 1400)
+++ trunk/MySql.VisualStudio/DDEX/MySqlDataViewCommandHandler.cs	2008-09-04 19:09:05 UTC
(rev 1401)
@@ -164,8 +164,11 @@
                     TableNode.CreateNew(DataViewHierarchyAccessor);
                     return true;
                 case PkgCmdIDList.cmdCreateProcedure:
-                    StoredProcedureNode.CreateNew(DataViewHierarchyAccessor);
+                    StoredProcedureNode.CreateNew(DataViewHierarchyAccessor, false);
                     return true;
+                case PkgCmdIDList.cmdCreateFunction:
+                    StoredProcedureNode.CreateNew(DataViewHierarchyAccessor, true);
+                    return true;
                 case PkgCmdIDList.cmdCreateView:
                     ViewNode.CreateNew(DataViewHierarchyAccessor);
                     return true;
@@ -215,12 +218,14 @@
 					newNode = new TableNode(DataViewHierarchyAccessor, id);
 					break;
 				case "storedprocedure":
-				case "storedfunction":
-                case "storedprocedures":
-                case "functions":
-                    newNode = new StoredProcedureNode(DataViewHierarchyAccessor, id);
+//                case "storedprocedures":
+  //              case "functions":
+                    newNode = new StoredProcedureNode(DataViewHierarchyAccessor, id,
false);
 					break;
-				case "view":
+                case "storedfunction":
+                    newNode = new StoredProcedureNode(DataViewHierarchyAccessor, id,
true);
+                    break;
+                case "view":
 					newNode = new ViewNode(DataViewHierarchyAccessor, id);
 					break;
                 case "udf":

Modified: trunk/MySql.VisualStudio/Nodes/StoredProcedureNode.cs
===================================================================
--- trunk/MySql.VisualStudio/Nodes/StoredProcedureNode.cs	2008-09-04 17:52:41 UTC (rev
1400)
+++ trunk/MySql.VisualStudio/Nodes/StoredProcedureNode.cs	2008-09-04 19:09:05 UTC (rev
1401)
@@ -19,16 +19,17 @@
 
 namespace MySql.Data.VisualStudio
 {
-	class StoredProcedureNode : DocumentNode
+	class StoredProcedureNode : DocumentNode, IVsTextBufferProvider
 	{
 		private string sql_mode;
 		private bool isFunction;
         private TextBufferEditor editor;
 
-		public StoredProcedureNode(DataViewHierarchyAccessor hierarchyAccessor, int id) : 
+		public StoredProcedureNode(DataViewHierarchyAccessor hierarchyAccessor, int id, bool
isFunc) : 
 			base(hierarchyAccessor, id)
 		{
-            NodeId = "StoredProcedure";
+            NodeId = isFunc ? "storedfunction" : "StoredProcedure";
+            isFunction = isFunc;
             NameIndex = 3;
             editor = new TextBufferEditor();
         }
@@ -53,9 +54,9 @@
 
         #endregion
 
-        public static void CreateNew(DataViewHierarchyAccessor HierarchyAccessor)
+        public static void CreateNew(DataViewHierarchyAccessor HierarchyAccessor, bool
isFunc)
         {
-            StoredProcedureNode node = new StoredProcedureNode(HierarchyAccessor, 0);
+            StoredProcedureNode node = new StoredProcedureNode(HierarchyAccessor, 0,
isFunc);
             node.Edit();
         }
 
@@ -75,10 +76,26 @@
             return editor.Text;
         }
 
+        private string GetNewRoutineText()
+        {
+            StringBuilder sb = new StringBuilder("CREATE ");
+            sb.AppendFormat("{0} {1}\r\n", isFunction ? "FUNCTION" : "PROCEDURE", Name);
+            sb.Append("/*\r\n(\r\n");
+            sb.Append("parameter1 INT\r\nOUT parameter2 datatype\r\n");
+            sb.Append(")\r\n*/\r\n");
+            if (isFunction)
+                sb.Append("RETURNS /* datatype */\r\n");
+            sb.Append("BEGIN\r\n");
+            if (isFunction)
+                sb.Append("RETURN /* return value */\r\n");
+            sb.Append("END");
+            return sb.ToString();
+        }
+
         protected override void  Load()
         {
             if (IsNew)
-                editor.Text = "CREATE PROCEDURE " + Name + "() BEGIN END";
+                editor.Text = GetNewRoutineText(); 
             else
             {
                 try
@@ -174,5 +191,35 @@
             string procName = sql.Substring(pos, end - pos).Trim();
             Name = procName;
         }
+
+        #region IVsTextBufferProvider Members
+
+        private IVsTextLines buffer;
+
+        int IVsTextBufferProvider.GetTextBuffer(out IVsTextLines ppTextBuffer)
+        {
+            if (buffer == null)
+            {
+                Type bufferType = typeof(IVsTextLines);
+                Guid riid = bufferType.GUID;
+                Guid clsid = typeof(VsTextBufferClass).GUID;
+                buffer = (IVsTextLines)MySqlDataProviderPackage.Instance.CreateInstance(
+                                     ref clsid, ref riid, typeof(object));
+            }
+            ppTextBuffer = buffer;
+            return VSConstants.S_OK;
+        }
+
+        int IVsTextBufferProvider.LockTextBuffer(int fLock)
+        {
+            return VSConstants.S_OK;
+        }
+
+        int IVsTextBufferProvider.SetTextBuffer(IVsTextLines pTextBuffer)
+        {
+            return VSConstants.S_OK;
+        }
+
+        #endregion
     }
 }

Thread
Connector/NET commit: r1401 - in trunk/MySql.VisualStudio: DDEX Nodesrburnett4 Sep