Example #1
0
		public ProcedureSchema (ProcedureSchema proc)
			: base (proc)
		{
			this.parameters = new ParameterSchemaCollection (parameters);
			this.language = proc.language;
			this.isSystemProcedure = proc.isSystemProcedure;
		}
Example #2
0
        private void BuildChildNodesThreaded(object state)
        {
            ParametersNode node    = state as ParametersNode;
            ITreeBuilder   builder = Context.GetTreeBuilder(state);

            ParameterSchemaCollection parameters = node.ConnectionContext.SchemaProvider.GetProcedureParameters(node.Procedure);

            DispatchService.GuiDispatch(delegate {
                foreach (ParameterSchema parameter in parameters)
                {
                    builder.AddChild(parameter);
                }
                builder.Expanded = true;
            });
        }
		public override ParameterSchemaCollection GetProcedureParameters (ProcedureSchema procedure)
		{
			ParameterSchemaCollection parameters = new ParameterSchemaCollection ();
			
			using (IPooledDbConnection conn = connectionPool.Request ())  {
				using (IDbCommand command = conn.CreateCommand (string.Concat (
				                                                 	"SELECT param_list FROM mysql.proc where name = '",
																	procedure.Name, "'"))) {
					try {
						if (GetMainVersion (command) >= 5) {
						    	using (IDataReader r = command.ExecuteReader()) {
						    		while (r.Read ()) {
						    			if (r.IsDBNull (0))
						    				continue;
						
										string[] field = Encoding.ASCII.GetString (
									                            (byte[])r.GetValue (0)).Split (
																				new char[] { ',' }, 
						    													StringSplitOptions.RemoveEmptyEntries);
						    			foreach (string chunk in field) {
											ParameterSchema param = new ParameterSchema (this);
											param.Definition = chunk;
							    				
											string[] tmp = chunk.TrimStart (new char[] { ' ' }).Split (new char[] { ' ' });
											int nameIndex = 0;
											if (String.Compare (tmp[0], "OUT", true) == 0) {
												nameIndex = 1;
												param.ParameterType = ParameterType.Out;
											} else if (String.Compare (tmp[0], "INOUT", true) == 0) {
												nameIndex = 1;
												param.ParameterType = ParameterType.InOut;
											} else {
												param.ParameterType = ParameterType.In;
											}
						    				param.Name = tmp[nameIndex];
						    				param.OwnerName = procedure.Name;
											param.DataTypeName = tmp[nameIndex + 1];
						    				parameters.Add (param);
						    			}
						    		}
								r.Close ();
							}
						}
					} catch (Exception e) {
						QueryService.RaiseException (e);
					} finally {
						conn.Release ();
					}			
				}
			}
			return parameters;
		}
Example #4
0
        public override ParameterSchemaCollection GetProcedureParameters(ProcedureSchema procedure)
        {
            ParameterSchemaCollection parameters = new ParameterSchemaCollection();

            using (IPooledDbConnection conn = connectionPool.Request())  {
                using (IDbCommand command = conn.CreateCommand(string.Concat(
                                                                   "SELECT param_list FROM mysql.proc where name = '",
                                                                   procedure.Name, "'"))) {
                    try {
                        if (GetMainVersion(command) >= 5)
                        {
                            using (IDataReader r = command.ExecuteReader()) {
                                while (r.Read())
                                {
                                    if (r.IsDBNull(0))
                                    {
                                        continue;
                                    }

                                    string[] field = Encoding.ASCII.GetString(
                                        (byte[])r.GetValue(0)).Split(
                                        new char[] { ',' },
                                        StringSplitOptions.RemoveEmptyEntries);
                                    foreach (string chunk in field)
                                    {
                                        ParameterSchema param = new ParameterSchema(this);
                                        param.Definition = chunk;

                                        string[] tmp       = chunk.TrimStart(new char[] { ' ' }).Split(new char[] { ' ' });
                                        int      nameIndex = 0;
                                        if (String.Compare(tmp[0], "OUT", true) == 0)
                                        {
                                            nameIndex           = 1;
                                            param.ParameterType = ParameterType.Out;
                                        }
                                        else if (String.Compare(tmp[0], "INOUT", true) == 0)
                                        {
                                            nameIndex           = 1;
                                            param.ParameterType = ParameterType.InOut;
                                        }
                                        else
                                        {
                                            param.ParameterType = ParameterType.In;
                                        }
                                        param.Name         = tmp[nameIndex];
                                        param.OwnerName    = procedure.Name;
                                        param.DataTypeName = tmp[nameIndex + 1];
                                        parameters.Add(param);
                                    }
                                }
                                r.Close();
                            }
                        }
                    } catch (Exception e) {
                        QueryService.RaiseException(e);
                    } finally {
                        conn.Release();
                    }
                }
            }
            return(parameters);
        }
		
		private ParameterSchemaCollection GetParams (string names, string directions, string types, IPooledDbConnection conn)
		{
			ParameterSchemaCollection pars = new ParameterSchemaCollection ();
			
			if (names == string.Empty || directions == string.Empty || types == String.Empty)
				return pars;
			
			// Array always start with { and end with }
			if (!names.StartsWith ("{") || !names.EndsWith ("}"))
				throw new ArgumentOutOfRangeException ("names");
			
			string[] namesArray = names.Substring(1, names.Length -2).Split (',');
			string[] directionsArray = directions.Substring(1, directions.Length -2).Split (',');
			string[] typesArray = types.Substring(1, types.Length -2).Split (',');
			
			for (int idx = 0; idx < namesArray.Length; idx++) {
				ParameterSchema ps = new ParameterSchema (this);
				// Name
				if (namesArray[idx] != "\"\"") 
					ps.Name = namesArray[idx];
				
				// Direction
				string d = directionsArray[idx];
				if (d == "i")
					ps.ParameterType = ParameterType.In;
				else if (d == "o")
					ps.ParameterType = ParameterType.Out;
				else
					ps.ParameterType = ParameterType.InOut;
				
				// Type
				using (IDbCommand cmd = conn.CreateCommand (string.Format (
					"select format_type(oid, null) from pg_type WHERE oid = '{0}'::oid", typesArray[idx]))) {
					using (IDataReader r = cmd.ExecuteReader()) 
						if (r.Read ())
							ps.DataTypeName = r.GetString (0);
				}
				pars.Add (ps);
			}
			return pars;
		public virtual ParameterSchemaCollection GetProcedureParameters (ProcedureSchema procedure)
		{
			ParameterSchemaCollection collection = new ParameterSchemaCollection ();
			
			IPooledDbConnection conn = connectionPool.Request ();
			try {
				//restrictions: database, schema, name, type, parameter
				DataTable dt = conn.GetSchema (procedureParametersCollectionString, null, procedure.SchemaName, procedure.Name);
				for (int r = 0; r < dt.Rows.Count; r++) {
					DataRow row = dt.Rows[r];
					collection.Add (GetProcedureParameter (row, procedure));
				}
			} catch (Exception e) {
				QueryService.RaiseException (e);
			}
			conn.Release ();
			
			return collection;
		}
Example #7
0
 public string GetFunctionParameters( ParameterSchemaCollection parameters)
 {
     string output = "";
     for (int i = 0; i < parameters.Count; i++)
     {
         output += GetCSType(parameters[i]) + " ";
         output +=  GetPrivateName(parameters[i].Name);
         if (i < parameters.Count - 1)
         {
             output += ", ";
         }
     }
     return output;
 }
Example #8
0
        /// <summary>
        /// Transform the list of sql parameters to a list of comment param for a method
        /// </summary>
        public string TransformStoredProcedureInputsToMethodComments(ParameterSchemaCollection inputParameters)
        {
            string temp = string.Empty;
            for(int i=0; i<inputParameters.Count; i++)
            {
                temp += string.Format("{2}\t/// <param name=\"{0}\"> A <c>{1}</c> instance.</param>", GetPrivateName(inputParameters[i].Name.Substring(1)), GetCSType(inputParameters[i]), Environment.NewLine);
            }

            return temp;
        }
Example #9
0
        /// <summary>
        /// Transform the list of sql parameters to a list of method parameters.
        /// </summary>
        public string TransformStoredProcedureInputsToMethod(bool startWithComa, ParameterSchemaCollection inputParameters)
        {
            string temp = string.Empty;
            for(int i=0; i<inputParameters.Count; i++)
            {
                temp += (i>0) || startWithComa ? ", " : "";
                temp += GetCSType(inputParameters[i]) + " " + GetPrivateName(inputParameters[i].Name.Substring(1));
            }

            return temp;
        }
Example #10
0
 /// <summary>
 /// Transform the list of sql parameters to a list of method parameters.
 /// </summary>
 public string TransformStoredProcedureInputsToMethod(ParameterSchemaCollection inputParameters)
 {
     return TransformStoredProcedureInputsToMethod(false, inputParameters);
 }
Example #11
0
        /// <summary>
        /// Transform the list of sql parameters to a list of ExecuteXXXXX parameters.
        /// </summary>
        public string TransformStoredProcedureInputsToDataAccess(bool alwaysStartWithaComa, ParameterSchemaCollection inputParameters)
        {
            string temp = string.Empty;
            for(int i=0; i<inputParameters.Count; i++)
            {
                temp += (i>0) || alwaysStartWithaComa ? ", " : "";
                temp += GetPrivateName(inputParameters[i].Name.Substring(1));
            }

            return temp;
        }
		
		public override ParameterSchemaCollection GetProcedureParameters (ProcedureSchema procedure)
		{
			ParameterSchemaCollection parameters = new ParameterSchemaCollection ();
			
			// FIXME: Won't work properly with overload functions.
			// Maybe check the number of columns in the parameters for
			// proper match.
			IPooledDbConnection conn = connectionPool.Request ();
			IDbCommand command = conn.CreateCommand (String.Format (
				"SELECT format_type (prorettype, NULL) "
				+ "FROM pg_proc pc, pg_language pl "
				+ "WHERE pc.prolang = pl.oid "
				+ "AND pc.proname = '{0}';", procedure.Name
			));
			try {
			using (command) {
			    	using (IDataReader r = command.ExecuteReader()) {
			    		while (r.Read ()) {	
						ParameterSchema param = new ParameterSchema (this);

						param.DataTypeName = r.GetString (0);
						param.Name = r.GetString (0);
						parameters.Add (param);
			    		}
					r.Close ();
				}
			}
			} catch (Exception e) {
				QueryService.RaiseException (e);
			}
			conn.Release ();
			
			return parameters;