parameterized-query

Passing parameters not being recognized and throws SQL error when executing raw query (on SQL-Server database and Pymssql) with SqlAlchemy

泪湿孤枕 提交于 2021-02-05 11:22:09
问题 I'm trying to execute simple raw SQL query, on SQL-Server db with SqlAlchemy (and Pymssql as provider). Here is my first try (using execute method of connection and passing parameters in **kwargs way): provider = DataProvider().engine q = "select url from Crawler.CrawlSource where source=@source" query = text(q) result = provider.connect().execute(query, source ='mysource') I passed the parameters in any way shown in tutorials (passing as kwargs and passing as dict) but neither of them worked

Unable to select values when using a parameter for the column name

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 18:46:51
问题 Try Using connection As New SqlConnection(ConnectionString) connection.Open() SQL = "SELECT @PARAM FROM SystemOps" sqlCmd = New SqlClient.SqlCommand(SQL, connection) sqlCmd.Parameters.Add(New SqlClient.SqlParameter("@PARAM", SqlDbType.VarChar)).Value = "SystemNavn" ' .. and so on... When I run the code, it returns with a result of "SystemNavn" (which is the name of the column in the table), instead of the value of that column in the current row. What am I doing wrong? 回答1: You cannot use

Can I bind a parameter to a PDO statement as a comparison operator?

你说的曾经没有我的故事 提交于 2020-03-26 07:25:47
问题 Is this code class opinion { private $dbh; var $opinionid,$opinion,$note,$actorid,$dateposted; var $isnew=FALSE; function loadby($column,$value,$operator="="){ $dbh = new PDO(I deleted parameters here); $statement=$dbh->prepare("select * from fe_opinion where :column :operator :value"); $statement->bindParam(":column", $column); $statement->bindParam(":value", $value); $statement->bindParam(":operator", $operator); //UNSURE, DOUBTFUL $statement->bindColumn("opinionid", $this->opinionid);

Is it safe to not parameterize an SQL query when the parameter is not a string?

戏子无情 提交于 2020-01-22 04:29:12
问题 In terms of SQL injection, I completely understand the necessity to parameterize a string parameter; that's one of the oldest tricks in the book. But when can it be justified to not parameterize an SqlCommand ? Are any data types considered "safe" to not parameterize? For example: I don't consider myself anywhere near an expert in SQL, but I can't think of any cases where it would be potentially vulnerable to SQL injection to accept a bool or an int and just concatenate it right into the

Parameterized query from Excel with IN clause

倾然丶 夕夏残阳落幕 提交于 2020-01-16 20:55:13
问题 I have a MS Query connection from Excel 2016 sheet to IBM DB2 database. I use parameterized query and link parameter values to Excel cell. While "singular value" clauses such as = < > like work, I can't get IN clause to work with multiple values but otherwise super simple query. Here's a simple demo dataset how I produce the parameter values: Column D formula is =IF(C2>5,A2&",","") which checks column C value for higher than 5 and populates ID in column D if TRUE . I'm expecting to use a

Method Optimisation - C#

眉间皱痕 提交于 2020-01-15 05:22:28
问题 I've developed a method that allows me to pass in a table (string), array of columns (string) and array of values (object) through the parameters which I then use to create a parameterized query. Although it works fine the length of the code as well as the multiple for loops gave off a code smell, in particular I feel the method I use to insert a comma between the columns and values can be done a different and better way. public static int Insert(string source, string[] column, object[]

Update postgreql database with Node.js

ぐ巨炮叔叔 提交于 2020-01-06 06:36:29
问题 I try to Update a table on postgresql so for that i'm creating two arrays var name_ = []; var id_ = []; then i creat a forEach loop where MyRow is the query that contain different data MyRow.rows.forEach(function(row){ name_.push(row.name); id_.push(row.id); }); var updateAccount = 'UPDATE myTable SET myRow =$1 '+ 'where id = $2' client.query(updateAccount,[name_.toString(),id_.toString()],false).then(function(err,result){ if (err) { console.log(err.stack); } else { console.log(name_) } });

ADODB.Recordset error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another

梦想与她 提交于 2020-01-03 06:35:12
问题 I've got an old website that is using ASP Classic and I have recently been asked remove the SQL injection attack threat. I'm trying to use parameterized queries, but it's all a little above my head. here is my code: <% whatSector = request.querystring("whatSector")%> <% adoCon.Open cString dim rs_client if whatSector="" then strSQL="SELECT * FROM clients ORDER BY alphabet" else Set objCommand = Server.CreateObject("ADODB.COMMAND") strCmd1 = "SELECT * FROM clients Where industrySector=? ORDER

Parameterized query binding in ON clause for a LEFT JOIN in Laravel Eloquent / Query Builder

穿精又带淫゛_ 提交于 2020-01-02 06:41:09
问题 Let's say I want to show a full list of awards with type="color": Awards Type 2013 Winner ====== ==== =========== Blue Award color Tom Red Award color Green Award color Dan To achieve this result I could have a query in Laravel like this: $year = '2013'; $awards = DB::table('awards') ->leftJoin('winners', function($join) use ($year) { $join->on('awards.id','=','winners.award_id'); $join->on('winners.year','=',DB::raw("'".$year."'")); } ->where('awards.type','color') ->get(); If you output the