parameterized-query

Issue with Oracle bind variables not using index properly

半城伤御伤魂 提交于 2019-11-26 21:42:11
问题 In my scenario, the following query runs fast (0.5 seconds on a table with 70 million rows): select * from Purchases where (purchase_id = 1700656396) and, it even runs fast using bind variables: var purchase_id number := 1700656396 select * from Purchases where (purchase_id = :purchase_id) These run fast because I have an index on the purchase_id column. (Keep reading...) I need to create a query that allows "filtering" on arbitrary columns. This means providing several input variables, and

How do I re-write a SQL query as a parameterized query?

China☆狼群 提交于 2019-11-26 10:03:53
问题 I have heard that I can prevent SQL injection attacks by using parameterized queries, but I do not know how to write them. How would I write the following as a parameterized query? SqlConnection con = new SqlConnection( \"Data Source=\" + globalvariables.hosttxt + \",\" + globalvariables.porttxt + \"\\\\SQLEXPRESS;\" + \"Database=ha;\" + \"Persist Security Info=false;\" + \"UID=\'\" + globalvariables.user + \"\';\" + \"PWD=\'\" + globalvariables.psw + \"\'\"); string query = \"SELECT distinct

How do parameterized queries help against SQL injection?

流过昼夜 提交于 2019-11-25 22:22:20
问题 In both queries 1 and 2, the text from the textbox is inserted into the database. What\'s the significance of the parameterized query here? Passing txtTagNumber as a query parameter SqlCommand cmd = new SqlCommand(\"INSERT INTO dbo.Cars \" +\"VALUES(@TagNbr);\" , conn); cmd.Parameters.Add(\"@TagNbr\", SqlDbType.Int); cmd.Parameters[\"@TagNbr\"].Value = txtTagNumber.Text; Converting txtTagNumber to an integer before constructing the query int tagnumber = txtTagNumber.Text.ToInt16(); /* EDITED

What is parameterized query?

坚强是说给别人听的谎言 提交于 2019-11-25 22:19:46
问题 What is a parameterized query, and what would an example of such a query be in PHP and MySQL? 回答1: A parameterized query (also known as a prepared statement ) is a means of pre-compiling a SQL statement so that all you need to supply are the "parameters" (think "variables") that need to be inserted into the statement for it to be executed. It's commonly used as a means of preventing SQL injection attacks. You can read more about these on PHP's PDO page (PDO being a database abstraction layer)