escaping

SQL escape with sqlite in C#

一笑奈何 提交于 2019-11-30 12:07:20
I have a text field and its breaking my sql statement. How do i escape all the chars in that field? I am using sqlite with http://sqlite.phxsoftware.com/ in C# You should be using a parameter as in: SQLiteCommand cmd = _connection.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM MyTable WHERE MyColumn = @parameter"; cmd.Parameters.Add( new SQLiteParameter( "@parameter", textfield ) ); SQLiteDataReader reader = cmd.ExecuteReader(); Using a parametrised SQL will escape all input values and help protect you from SQL injection attacks. You can also replace all

How to escape URL-encoded data in POST with HttpWebRequest

て烟熏妆下的殇ゞ 提交于 2019-11-30 12:04:27
I am trying to send an URL-encoded post to a REST API implemented in PHP. The POST data contains two user-provided strings: WebRequest request = HttpWebRequest.Create(new Uri(serverUri, "rest")); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.Headers.Add("Content-Transfer-Encoding", "binary"); // Form the url-encoded credentials we'll use to log in StringBuilder builder = new StringBuilder(); builder.Append("user="); builder.Append(user); builder.Append("&password="); builder.Append(password); byte[] credentials = Encoding.UTF8

htaccess rewrite rule with escaped ampersand in $_GET fails

二次信任 提交于 2019-11-30 11:39:14
I am encountering a problem with a get parameter in conjunction with a htaccess rewrite rule. Below is the urlencode()'ed link; the rewrite rule I use to redirect to index.php, and lastly, a print_r($_GET) on the index.php. As you can see, the urlescaped ampersand is not part of the value for variable static, but instead and contrary to my expectation gets interpreted as a variable seperator. Why? Initial link: <a href="static/Game-Tech-%26-Arts-Lab">link</a> .htaccess: RewriteRule ^static/(.*)$ /index.php?static=$1 [L] index.php: Array ( [static] => Game-Tech- [-Arts-Lab] => ) mario Ah, okay.

Format a string that has extra curly braces in it

蓝咒 提交于 2019-11-30 11:26:22
I have a LaTeX file I want to read in with Python 3 and format a value into the resultant string. Something like: ... \textbf{REPLACE VALUE HERE} ... But I have not been able to figure out how to do this since the new way of doing string formatting uses {val} notation and since it is a LaTeX document, there are tons of extra {} characters. I've tried something like: '\textbf{This and that} plus \textbf{{val}}'.format(val='6') but I get KeyError: 'This and that' Method 1, which is what I'd actually do: use a string.Template instead. >>> from string import Template >>> Template(r'\textbf{This

PowerShell script not accepting $ (dollar) sign

落爺英雄遲暮 提交于 2019-11-30 11:11:05
问题 I am trying to open an SQL data connection using a PowerShell script and my password contains a $ sign: $cn = new-object system.data.SqlClient.SqlConnection("Data Source=DBNAME;Initial Catalog=Catagory;User ID=User;Password=pass$word;") When I try to open a connection it says: Login failed 回答1: Escape it by using backtick (`) as an escape character for the dollar sign ($). Also, try to enclose the statement in single-quotes instead of the double-quotes you are using now. 来源: https:/

How to escape underscore character in PATINDEX pattern argument?

痞子三分冷 提交于 2019-11-30 10:42:48
问题 I've found a solution for finding the position of an underscore with PATINDEX : DECLARE @a VARCHAR(10) SET @a = '37_21' PRINT PATINDEX('%_%', @a) -- return 1 (false) PRINT PATINDEX('%!%', REPLACE(@a, '_', '!')) -- return 3 (correct) Have you other ideas? Like a way to escape the underscore character? 回答1: I've always done it with brackets: '%[_]%' 回答2: To match two underscores, each must be bracketed '%[__]%' -- matches single _ with anything after '%[_][_]%' -- matches two consecutive _ 回答3:

How do I escape double quotes in attributes in an XML String in T-SQL?

空扰寡人 提交于 2019-11-30 10:26:56
问题 Pretty simple question - I have an attribute that I would like to have double quotes in. How do I escape them? I've tried \" "" \\" And I've made the @xml variable both xml type and varchar(max) for all of them. declare @xml xml --(or varchar(max) tried both) set @xml = '<transaction><item value="hi "mom" lol" ItemId="106" ItemType="2" instanceId="215923801" dataSetId="1" /></transaction>' declare @xh int exec sp_xml_preparedocument @xh OUTPUT, @xml insert into @commits --I declare the table,

How can I escape text for an XML document in Perl?

不打扰是莪最后的温柔 提交于 2019-11-30 10:24:56
Anyone know of any Perl module to escape text in an XML document? I'm generating XML which will contain text that was entered by the user. I want to correctly handle the text so that the resulting XML is well formed. zakovyrya I personally prefer XML::LibXML - Perl binding for libxml. One of the pros - it uses one of the fastest XML processing library available. Here is an example for creating text node: use XML::LibXML; my $doc = XML::LibXML::Document->new('1.0',$some_encoding); my $element = $doc->createElement($name); $element->appendText($text); $xml_fragment = $element->toString(); $xml

Is the char literal '\“' the same as '”' ?(backslash-doublequote vs only-doublequote)

限于喜欢 提交于 2019-11-30 09:39:03
问题 Is there's any difference between char literals '\"' and '"' ? 回答1: There is absolutely no difference. The two char are == . System.out.println('\"' == '"'); // prints "true" Strictly speaking it's not necessary to escape a double quote in a char literal, but it doesn't change this fact that \" denotes the double quote character \u0022 . References JLS 3.10.6 Escape Sequences for Character and String Literals String analog We also have the analogous situation for String literals: System.out

How to use ESC (&#27;) character in XML?

守給你的承諾、 提交于 2019-11-30 09:24:43
问题 I'm trying this: <root> text: &#27; </root> But parser says: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 12; Character reference "&#27" is an invalid XML character. at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) How to use it there? 回答1: You cannot ( in XML 1.0). In XML 1.1 there is a slightly larger range of characters you can