Insert string with quotes in SQLite


#1

Hi all ! I Could anyone suggest please … how to insert string with quotes ? I am using SQLite … if exists any method ?


#2

Use google on the following keywords:

insert string quotes sqlite javascript


#3

Tommertom, I am trying replace, new RegExp() , but not succeed. I always see promise error.


#4

You can use escape(), encodeURI(), encodeURIComponent() methods on your string.
These methods will encode all the special characters including spaces. Also encodeURIComponent() has some limitations on characters
But if you want to replace quote only then you can replace your (quote) with %27


#5

vaibhav915, good day ! I am trying like this … but select nothing found … My search word is - Hitch Jack - 40’, 50’, 60

this.search_options.word = encodeURI(word);

search parts SELECT * FROM model as tb1 WHERE (Description LIKE '%Hitch%20Jack%20-%2040',%2050',%2060'%' OR LocalDesc LIKE '%Hitch%20Jack%20-%2040',%2050',%2060'%') OR tCode LIKE '%Hitch%20Jack%20-%2040',%2050',%2060'%' ORDER BY tb1.Order


#6

I think you have to escape ’ with \’ so the query should be like this:

... LIKE '%Hitch Jack-40\', 50\', 60\'%' OR...

If you convert space to %20 the % will be interpreted as wildcard in your query so i dont think that will work.

Try this (untested):

searchString = searchString.replace('\'', '\\\'');

#7

I found solution to put search_options.word like parametrs … it working well with exact query …

word += " (Caption = ? OR Caption = ?)";

this.sql.query(qry,[search_options.word]).then(all_res => { ...

but when I want to search with operator like … SQLitePlugin generate exception …

(Caption LIKE ‘% ? %’ OR Caption LIKE ‘% ? %’)

message: "sqlite3_bind_text failure: bind or column index out of range"

How to put correctly % for operator like ?