prepared-statement

Go sql - prepared statement scope

允我心安 提交于 2019-12-02 02:47:13
I'm building an API using the Go (1.6.x) sql package along with with PostGres (9.4). Should my prepared statements have application or request scope? Having read the docs it would seem more efficient to scope them at the application level to reduce the number of preparation phases. However, perhaps there are other considerations and prepared statements are not designed to live that long? Prepared statements are so that you can execute repetitive SQL commands which may only differ in parameter values for example. They are not meant to live "long" as a prepared statement may (they do if called

why do I get a syntax error for prepared statement? [duplicate]

点点圈 提交于 2019-12-02 02:24:21
This question already has an answer here: preparedStatement syntax error 2 answers I have written a prepared statement but its giving a syntax error at ?. I am not able to understand whats wrong.It should pass a movie name and get the result as directors of that movie stmt=getConnection().createStatement(); String sql="SELECT directors FROM moviedata WHERE moviedata.title = ?"; PreparedStatement preparedStatement=conn.prepareStatement(sql); preparedStatement.setString(1,movieName); rs=preparedStatement.executeQuery(sql); The problem is here: rs=preparedStatement.executeQuery(sql); You shouldn

SQL 1064 Syntax Error using a JDBC prepared statement

扶醉桌前 提交于 2019-12-02 01:48:34
I have: String query = "INSERT INTO Basestations VALUES(?, ?, ?, ?, ?, ?, ?," + "?, ?, ?, ?, ?, ?, ?, ?)"; PreparedStatement prep = conn.prepareStatement(query); prep.setInt(1, profile.getNetworkId()); prep.setInt(2, profile.getBaseStationId()); prep.setInt(8, profile.getLoadLevel()); prep.setInt(11, profile.getPositionX()); prep.setInt(12, profile.getPositionY()); prep.setInt(13, profile.getPort()); prep.setDouble(3, profile.getSignalStrength()); prep.setDouble(4, profile.getFrequency()); prep.setDouble(6, profile.getMaxBitrate()); prep.setDouble(7, profile.getGuaranteedBitrate()); prep

condition for creating a prepared statement using cfqueryparam?

假如想象 提交于 2019-12-02 01:37:20
Does cfquery becomes a prepared statement as long as there's 1 cfqueryparam ? Or are there other conditions? What happen when the ORDER BY clause or FROM clause is dynamic? Would every unique combination becomes a prepared statement? And what happen when we're doing cfloop with INSERT , with every value cfqueryparam'ed, and invoke the cfquery with different number of iterations? Any potential problems with too many prepared statements? How does DB handle prepared statement? Will they be converted into something similar to store procedure? Under what circumstances should we Not use prepared

why do I get a syntax error for prepared statement? [duplicate]

早过忘川 提交于 2019-12-02 01:35:58
问题 This question already has answers here : preparedStatement syntax error (2 answers) Closed 12 months ago . I have written a prepared statement but its giving a syntax error at ?. I am not able to understand whats wrong.It should pass a movie name and get the result as directors of that movie stmt=getConnection().createStatement(); String sql="SELECT directors FROM moviedata WHERE moviedata.title = ?"; PreparedStatement preparedStatement=conn.prepareStatement(sql); preparedStatement.setString

How to use mysqli::bind_param with an array as the second parameter

时光毁灭记忆、已成空白 提交于 2019-12-02 01:11:33
问题 This query is supposed to insert a new user into the 'users' table $user = DB::getInstance()->insert('users', array( 'username' => 'jim', 'password' => 'pass', 'salt' => 'salt' ) ); Corresponding insert() public function insert($table, $fields = array()) { if (count($fields)) { $keys = array_keys($fields); $values = null; $x = 1; foreach ($fields as $field) { $values .= "?"; if ($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO users (`" . implode('`,`', $keys) . "`)

Java PreparedStatement setString changes characters

荒凉一梦 提交于 2019-12-01 23:55:11
问题 As in title: to be sure, I was debugging my application, and so in line, where I put strings into PreparedStatement variable, special characters are changing to "?". I actually don't know where to search for things that should repair it, so I don't know if code is required.. Anyway, I'll put some here: PreparedStatement stm = null; String sql = ""; try{ sql = "INSERT INTO methods (name, description) VALUES (?, ?)"; stm = connection.prepareStatement(sql); stm.setString(1, method.getName());

Java PreparedStatement setString changes characters

牧云@^-^@ 提交于 2019-12-01 22:37:36
As in title: to be sure, I was debugging my application, and so in line, where I put strings into PreparedStatement variable, special characters are changing to "?". I actually don't know where to search for things that should repair it, so I don't know if code is required.. Anyway, I'll put some here: PreparedStatement stm = null; String sql = ""; try{ sql = "INSERT INTO methods (name, description) VALUES (?, ?)"; stm = connection.prepareStatement(sql); stm.setString(1, method.getName()); stm.setString(2, method.getDescription()); //... }catch(Exception e){} while debugging 'name' field was

Does pg_prepare() prepared statement (not PDO) prevent SQL-Injection?

依然范特西╮ 提交于 2019-12-01 22:15:25
PDO ist not supported in target system I'm working on and though I seek a solution for preventing SQL-Injection using PHP 5.1.x on a PostGres-DB 8.2+ . There is at the moment no chance of switching to PDO. My solution at the moment is pg_prepare-prepared statement: // Trying to prevent SQL-Injection $query = 'SELECT * FROM user WHERE login=$1 and password=md5($2)'; $result = pg_prepare($dbconn, "", $query); $result = pg_execute($dbconn, "", array($_POST["user"], $_POST["password"])); if (pg_num_rows($result) < 1) { die ("failure"); } But pg_prepare-documentation lacks about an important

Why do I get this function call error on an non-object when I am calling a function on an object?

浪子不回头ぞ 提交于 2019-12-01 22:07:44
Error: Fatal error: Call to a member function bind_param() on a non-object in /var/www/web55/web/pdftest/events.php on line 76 Code: public function countDaysWithoutEvents(){ $sql = "SELECT 7 - COUNT(*) AS NumDaysWithoutEvents FROM (SELECT d.date FROM cali_events e LEFT JOIN cali_dates d ON e.event_id = d.event_id WHERE YEARWEEK(d.date) = YEARWEEK(CURRENT_DATE()) AND c.category_id = ? GROUP BY DAY(d.date) ) AS UniqueDates"; $stmt = $this->link->prepare($sql); $stmt->bind_param('i', $this->locationID); $stmt->execute(); $stmt->bind_result($count); $stmt->close(); return $count; } $this->link-