Questions tagged [prepared-statement]

A Prepared Statement (or parameterized statement) is a precompiled SQL statement that serves to improve performance and mitigate SQL injection attacks. Prepared statements are used in many popular Relational Database Management Systems.

Prepared statements separate data binding from execution. Separating statement preparation from execution can be more efficient for statements that are executed multiple times, because the preparation phase need be done only once. For example, if you need to insert a bunch of rows, you can prepare an INSERT statement once and then execute it repeatedly, binding successive row values to it for each execution. A prepared statement can contain placeholders to indicate where data values should appear. After you prepare the statement, bind specific values to the placeholders (either before or at statement-execution time), then substitute the values into the statement before sending it to the database server.

Also see: ,

6193 questions
19
votes
4 answers

Node-postgres: named parameters query (nodejs)

I used to name my parameters in my SQL query when preparing it for practical reasons like in php with PDO. So can I use named parameters with node-postgres module? For now, I saw many examples and docs on internet showing queries like…
AnomalySmith
  • 597
  • 2
  • 5
  • 16
19
votes
6 answers

This PDO prepared statement returns false but does not throw an error

This code does not throw an error but the query fails, that is, the execute method returns false. How could that be? require_once("Abstracts/DBManager.php"); require_once("UI/UI.Package.php"); class BlogDBM extends DBManager { private $table =…
Simsevu
  • 210
  • 1
  • 2
  • 6
19
votes
3 answers

Rails 3.2 frequent postgres prepared statement already exists errors

I've been digging around stackoverflow trying to find others who get these prepared statements already exists errors. In most cases configuring unicorn properly with the after/before fork resolves these issues. However in my case we are still…
19
votes
2 answers

Inserting into custom SQL types with prepared statements in java

I have some custom types. They are all basically enums. Here is an example of what they look like: CREATE TYPE card_suit AS ENUM ('spades', 'clubs', 'hearts', 'diamonds'); And I have some prepared statements in Java, which look…
Tom Carrick
  • 6,349
  • 13
  • 54
  • 78
18
votes
2 answers

Cannot pass parameter by reference in MySQLi

I am trying to pass a string into my MySQLi prepared statement but it gives me the error: Cannot pass parameter by reference in MySQLi Here is the relevant code: $kv = json_encode(array($key => $value)); $stmt->prepare("insert into rules…
chustar
  • 12,225
  • 24
  • 81
  • 119
18
votes
4 answers

How do I use pdo's prepared statement for order by and limit clauses?

I want to use a prepared statement in which the passed-in parameters are for the ORDER BY and LIMIT clauses, like so: $sql = 'SELECT * FROM table ORDER BY :sort :dir LIMIT :start, :results'; $stmt = $dbh->prepare($sql); $stmt->execute(array( …
user198729
  • 61,774
  • 108
  • 250
  • 348
17
votes
3 answers

Are Prepared statements supported in embedded MySQL

I normally develop with a live server, but for the first time I figured I'd make the leap and see if I could get all my (C++) mysql code working as an embedded server. Particularly, I'm very fond of prepared statements as they are (IMHO) "generally"…
Sass
  • 560
  • 4
  • 17
17
votes
1 answer

Queries with prepared statements in Android?

In Android, android.database.sqlite.SQLiteStatement allows me to use prepared statements in SQLite to avoid injection attacks. Its execute method is suitable for create/update/delete operations, but there does not seem to be any method for queries…
shadowmatter
  • 1,352
  • 2
  • 18
  • 30
17
votes
4 answers

Are the parameter values automatically cleared after executing a batch of SQL commands with a Java PreparedStatemen?

I have the following code snippet: PreparedStatement preparedStatement = connection.prepareStatement(sql); for (int i = 0; i < 100000; i++) { preparedStatement.setObject(1, someValue); preparedStatement.addBatch(); if ((i + 1) % 100 ==…
Clara
  • 2,935
  • 6
  • 34
  • 49
17
votes
4 answers

"ORA-01008: not all variables bound" error

I am using following method for calculating payroll by using jdbc but "ORA-01008: not all variables bound" error is not removing. Any idea please? I am using following code public double getPayroll(){ ResultSet rs = null; …
Adnan
  • 4,517
  • 15
  • 44
  • 54
17
votes
1 answer

MySQL : named parameters with PREPARE command?

Is it possible in MySQL to use the PREPARE command with named parameters such as PDO in PHP: Here is my example: SET @s = 'SELECT * FROM MY_TABLE WHERE my_column_1 = ? AND my_column_2 = ? '; PREPARE stmt2 FROM @s; SET @a = 54; SET @b = 89'; …
Ricou
  • 946
  • 3
  • 11
  • 22
17
votes
4 answers

When should I use prepared statements?

Originally I used mysql_connect and mysql_query to do things. Then I learned of SQL injection, so I am trying to learn how to use prepared statements. I understand how the prepare and execute functions of the PDO class are useful to prevent SQL…
G.SINGH
  • 389
  • 2
  • 3
  • 8
17
votes
1 answer

Cassandra Java Driver- QueryBuilder API vs PreparedStatements

Datastax Java driver (cassandra-driver-core 2.0.2) for Cassandra supports PreparedStatements as well as QueryBuilder API. Any specific advantages using one over the other? Disadvantages? Documentation:…
17
votes
2 answers

How to use prepared statement for select query in Java?

I had tried several times using prepared statements but it returns SQL exception. here is my code: public ArrayList name(String mobile, String password) { ArrayList getdata = new ArrayList(); PreparedStatement stmt =…
jasim
  • 459
  • 1
  • 6
  • 24
17
votes
3 answers

mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables

So I have this massive headache inducing query that I need to perform involving 65 form inputs needing to be injected into a database using mysqli prepared statements. The issue I'm running into is that it says the # of variables I am attempting to…
Samuel Stiles
  • 2,118
  • 5
  • 22
  • 27