Exemple #1
0
 private void UpdateProcedure()
 {
     if (_procedure != null)
     {
         return;
     }
     _procedure = Context?.StoredFunctions[_procedureSchema, _procedureName];
 }
Exemple #2
0
        //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:SQL クエリのセキュリティ脆弱性を確認")]
        public override IDbCommand GetSqlCommand(StoredFunction function, EventHandler <LogEventArgs> logEvent, IDbConnection connection, IDbTransaction transaction)
        {
            if (connection != null && !(connection is NpgsqlConnection))
            {
                throw new ArgumentException("connectoin");
            }
            if ((transaction != null) && !(transaction is NpgsqlTransaction))
            {
                throw new ArgumentException("transaction");
            }
            StringBuilder buf = new StringBuilder();

            buf.Append("select * from ");
            buf.Append(GetEscapedIdentifier(function.SchemaName, function.Name, null, true));
            buf.Append("(");
            bool needComma           = false;
            List <NpgsqlParameter> l = new List <NpgsqlParameter>();

            foreach (Parameter p in function.Parameters)
            {
                if (p.Direction == ParameterDirection.Output)
                {
                    continue;
                }
                string pName = p.Name ?? p.Index.ToString();
                if (needComma)
                {
                    buf.Append(", ");
                }
                buf.Append(':');
                buf.Append(pName);
                buf.Append("::");
                buf.Append(p.BaseType);
                NpgsqlDbType t;
                if (!TypeToDbType.TryGetValue(p.ValueType, out t))
                {
                    t = NpgsqlDbType.Text;
                }
                NpgsqlParameter np = new NpgsqlParameter(pName, t)
                {
                    Direction = p.Direction
                };
                l.Add(np);
                needComma = true;
            }
            buf.Append(")");
            NpgsqlCommand cmd = new NpgsqlCommand(buf.ToString(), connection as NpgsqlConnection, transaction as NpgsqlTransaction)
            {
                CommandType = CommandType.Text
            };

            cmd.Parameters.AddRange(l.ToArray());
            LogConverter.NewLogConverter(cmd, logEvent);
            return(cmd);
        }
Exemple #3
0
 private void ExportStoredFunction(StringBuilder buffer, StoredFunction function)
 {
     if (function == null)
     {
         return;
     }
     AppendStrArray(buffer, DataSet.GetSQL(function, string.Empty, ";", 0, true));
     if (!string.IsNullOrEmpty(function.CommentText))
     {
         AppendStrArray(buffer, DataSet.GetSQL(function.Comment, string.Empty, ";", 0, true));
     }
 }
Exemple #4
0
 private void InvalidateProcedure()
 {
     _procedure = null;
 }
Exemple #5
0
        public override TreeNode[] GetVisualTree()
        {
            List <TreeNode> top = new List <TreeNode>();
            List <Schema>   l   = new List <Schema>(Schemas);

            l.Sort();
            foreach (Schema sc in l)
            {
                TreeNode nodeSc = new TreeNode(sc.Name, null, typeof(Schema), 0, (sc.Name == CurrentSchema), sc.IsHidden)
                {
                    Target = sc
                };
                top.Add(nodeSc);
                List <TreeNode>       lSc     = new List <TreeNode>();
                List <SchemaObject>   types   = new List <SchemaObject>();
                List <Table>          tbls    = new List <Table>();
                List <View>           views   = new List <View>();
                List <StoredFunction> funcs   = new List <StoredFunction>();
                List <StoredFunction> trFuncs = new List <StoredFunction>();
                List <Sequence>       seqs    = new List <Sequence>();
                foreach (SchemaObject obj in sc.Objects)
                {
                    if (obj is Table)
                    {
                        tbls.Add((Table)obj);
                    }
                    if (obj is View)
                    {
                        views.Add((View)obj);
                    }
                    if (obj is StoredFunction)
                    {
                        StoredFunction fn = (StoredFunction)obj;
                        if (string.Compare(fn.DataType, "trigger") == 0)
                        {
                            trFuncs.Add(fn);
                        }
                        else
                        {
                            funcs.Add(fn);
                        }
                    }
                    if (obj is Sequence)
                    {
                        seqs.Add((Sequence)obj);
                    }
                    if (obj is Type_ || obj is ComplexType)
                    {
                        types.Add(obj);
                    }
                }
                tbls.Sort();
                views.Sort();
                seqs.Sort();
                types.Sort();
                TreeNode        nodeGrp;
                List <TreeNode> lGrp;

                lGrp    = new List <TreeNode>();
                nodeGrp = new TreeNode("表", "表 ({0})", typeof(Table), 0, false, false);
                lSc.Add(nodeGrp);
                foreach (Table t in tbls)
                {
                    lGrp.Add(new TreeNode(t));
                }
                nodeGrp.Children = lGrp.ToArray();

                lGrp    = new List <TreeNode>();
                nodeGrp = new TreeNode("ビュー", "ビュー ({0})", typeof(View), 0, false, false);
                lSc.Add(nodeGrp);
                foreach (View t in views)
                {
                    lGrp.Add(new TreeNode(t));
                }
                nodeGrp.Children = lGrp.ToArray();

                lGrp    = new List <TreeNode>();
                nodeGrp = new TreeNode("型", "型 ({0})", typeof(Type_), 0, false, false);
                lSc.Add(nodeGrp);
                foreach (SchemaObject t in types)
                {
                    lGrp.Add(new TreeNode(t));
                }
                nodeGrp.Children = lGrp.ToArray();

                lGrp    = new List <TreeNode>();
                nodeGrp = new TreeNode("ストアド関数", "ストアド関数 ({0})", typeof(View), 0, false, false);
                lSc.Add(nodeGrp);
                foreach (StoredFunction fn in funcs)
                {
                    lGrp.Add(new TreeNode(fn));
                }
                nodeGrp.Children = lGrp.ToArray();

                lGrp    = new List <TreeNode>();
                nodeGrp = new TreeNode("トリガー関数", "トリガー関数 ({0})", typeof(View), 1, false, false);
                lSc.Add(nodeGrp);
                foreach (StoredFunction fn in trFuncs)
                {
                    lGrp.Add(new TreeNode(fn));
                }
                nodeGrp.Children = lGrp.ToArray();

                lGrp    = new List <TreeNode>();
                nodeGrp = new TreeNode("シーケンス", "シーケンス ({0})", typeof(Sequence), 0, false, false);
                lSc.Add(nodeGrp);
                foreach (Sequence t in seqs)
                {
                    lGrp.Add(new TreeNode(t));
                }
                nodeGrp.Children = lGrp.ToArray();

                nodeSc.Children = lSc.ToArray();
            }
            List <TreeNode> lDb    = new List <TreeNode>();
            TreeNode        nodeDb = new TreeNode(Database.Name, Database.Name, typeof(Database), 0, true, false);

            nodeDb.Target   = Database;
            nodeDb.Children = top.ToArray();
            lDb.Add(nodeDb);
            foreach (Database db in OtherDatabases)
            {
                nodeDb        = new TreeNode(db.Name, db.Name, typeof(Database), 0, false, false);
                nodeDb.Target = db;
                lDb.Add(nodeDb);
            }
            return(lDb.ToArray());
        }
Exemple #6
0
 internal ParameterCollection(StoredFunction owner)
 {
     _owner = owner;
     _items = new List <Parameter>();
 }
Exemple #7
0
 public Parameter(StoredFunction owner) : base()
 {
     Owner = owner;
     owner.Parameters.Add(this);
 }