示例#1
0
        private OracleCommand CreateCommand(string xml, Func <string, OracleParameter> paramUpdater, string actionName)
        {
            OracleCommand cmd = _conn.CreateCommand();

            cmd.CommandText = xml;

            XmlToSql.BuildCommand(cmd, paramUpdater, (elem) =>
            {
                if (_proxyTagValue == null)
                {
                    return(false);
                }
                elem.Value = _proxyTagValue;
                return(true);
            });
            if (_conn.State == ConnectionState.Closed)
            {
                _conn.Open();
            }
            cmd.BindByName           = true;
            cmd.InitialLONGFetchSize = 1024;    // Retrieve first 1K chars from a long column
            _conn.ActionName         = actionName;
            QueryLogging.TraceOracleCommand(_traceContext, cmd, actionName);
            return(cmd);
        }
示例#2
0
        protected override void OnUpdating(SqlDataSourceCommandEventArgs e)
        {
            e.Command.CommandText = string.IsNullOrWhiteSpace(_owner.UpdateSql) ? this.UpdateCommand : _owner.UpdateSql;
            // Event handlers get the first chance to manipulate command
            base.OnUpdating(e);

            if (e.Cancel || string.IsNullOrWhiteSpace(e.Command.CommandText))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(_owner.UpdateSql))
            {
                // RaiseCommandParsingEvents is obsolete
//#pragma warning disable 612,618
//                RaiseCommandParsingEvents(e);
//#pragma warning restore 612,618
                throw new HttpException("UpdateSql must be specified");
            }
            else
            {
                XmlToSql.BuildCommand((OracleCommand)e.Command, null, p => false);
            }
            return;
        }
示例#3
0
        //"PATCH/Resources//Name='Milan'/Name='Marko'"
        public void TestGeneratePatch()
        {
            Request  request  = new Request("PATCH", "Resources/", "Name='Milan'", "Name='Marko'");
            string   json     = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.Indented);
            XmlToSql xmlToSql = new XmlToSql();
            string   sql      = xmlToSql.Convert(JsonConvert.DeserializeXNode(json, "Request"));
            string   expected = "UPDATE Resources SET Name='Marko' WHERE Name='Milan';";

            Assert.AreEqual(sql, expected);
        }
示例#4
0
        //DELETE/Resources//Name='Milan';Description='opis'
        public void TestGenerateDelete()
        {
            Request  request  = new Request("DELETE", "Resources/", "Name='Milan';Description='opis", null);
            string   json     = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.Indented);
            XmlToSql xmlToSql = new XmlToSql();
            string   sql      = xmlToSql.Convert(JsonConvert.DeserializeXNode(json, "Request"));
            string   expected = "DELETE FROM Resources WHERE Name='Milan' and Description='opis;";

            Assert.AreEqual(sql, expected);
        }
示例#5
0
        //POST/Resources//Name;Description/'Milan';'Description'
        public void TestGeneratePost()
        {
            Request  request  = new Request("POST", "Resources/", "Name;Description", "'Milan';'Description'");
            string   json     = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.Indented);
            XmlToSql xmlToSql = new XmlToSql();
            string   sql      = xmlToSql.Convert(JsonConvert.DeserializeXNode(json, "Request"));
            string   expected = "INSERT Into Resources (Name, Description) VALUES ('Milan', 'Description');";

            Assert.AreEqual(sql, expected);
        }
示例#6
0
        //GET/Resources//Name='Petar';Description='opis'"
        public void TestGenerateGet3()
        {
            Request  request  = new Request("GET", "Resources/", "Name='Petar';Description='opis'", null);
            string   json     = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.Indented);
            XmlToSql xmlToSql = new XmlToSql();
            string   sql      = xmlToSql.Convert(JsonConvert.DeserializeXNode(json, "Request"));
            string   expected = "SELECT * FROM Resources WHERE Name='Petar' and Description='opis';";

            Assert.AreEqual(sql, expected);
        }
示例#7
0
        //GET/Resources/1
        public void TestGenerateGet()
        {
            Request  request  = new Request("GET", "Resources/1", null, null);
            string   json     = JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.Indented);
            XmlToSql xmlToSql = new XmlToSql();
            string   sql      = xmlToSql.Convert(JsonConvert.DeserializeXNode(json, "Request"));
            string   expected = "SELECT * FROM Resources WHERE Id = 1;";

            Assert.AreEqual(sql, expected);
        }
示例#8
0
        protected override void OnSelecting(SqlDataSourceSelectingEventArgs e)
        {
            e.Command.CommandText = string.IsNullOrWhiteSpace(_owner.SelectSql) ? this.SelectCommand : _owner.SelectSql;

            //SetCommandType(e.Command, this.SelectCommandType);

            // Event handlers get the first chance to manipulate command
            base.OnSelecting(e);

            if (e.Cancel)
            {
                Trace.TraceWarning("Datasource {0} is cancelling query in OnSelecting because event handler set e.Cancel = true",
                                   _owner.ID);
                return;
            }

            if (string.IsNullOrWhiteSpace(_owner.SelectSql))
            {
                // RaiseCommandParsingEvents is obsolete
//#pragma warning disable 612,618
//                RaiseCommandParsingEvents(e);
//#pragma warning restore 612,618
                throw new HttpException("SelectSql must be specified");
            }
            else
            {
                //BuildCommandFromXml(e);
                XmlToSql.BuildCommand((OracleCommand)e.Command, null, p => false);
            }

            if (string.IsNullOrWhiteSpace(e.Command.CommandText))
            {
                Trace.TraceWarning("Datasource {0} is cancelling query in OnSelecting because CommandText evaluated to empty",
                                   _owner.ID);
                e.Cancel = true;
            }

            return;
        }