Reputation: 107
I am making a sql Query I try to find if a similar name already exists into dabs , but its keeping dispatching error saying that no such column David exists , could please help
const texts = 'David'
tx.executeSql('SELECT * FROM friends WHERE name LIKE '+texts+';', [], (tx, results)
Upvotes: 0
Views: 433
Reputation: 222472
As it is, the query that your code produces is :
SELECT * FROM friends WHERE name LIKE David;
sqlite does consider unquoted David
as a column name, hence the error you are getting.
You probably want this instead :
SELECT * FROM friends WHERE name LIKE 'David';
LIKE
without wildcard on the right side does not really make sense, so that could be either of the following queries, depending if you want exact match or not
SELECT * FROM friends WHERE name LIKE '%David%';
SELECT * FROM friends WHERE name = 'David';
To generate the query, you could use the following code :
"SELECT * FROM friends WHERE name LIKE '%" + texts + "%';"
"SELECT * FROM friends WHERE name = '" + texts + "';"
Upvotes: 3