0

I have the following query to select a list of vocabulary from a Japanese dictionary.

SELECT * FROM dictionary WHERE from_local = 1 AND (word like '%後%' or reading like '%後%')

Running this program in HeidiSQL, it works as expected. I feel like it could be a charset issue but I don't think it would work at all if this were the case. (See screenshot)

HeidiSQL screenshot

My problem occours when I try to run this query in my Node.js app. The results return empty.

I am using npm's mysql library. The dbQuery method is a helper function I made (Pastebin link)

import { dbQuery } from '../db'

const search = async(query) => {
    try {
        let sql = 'SELECT * FROM dictionary WHERE'
        sql += ' from_local = ? AND'
        sql += ' (word = ? OR reading = ?)'
        const params = [1, '%'+query+'%', '%'+query+'%']

        console.log('dictionary DB', {query, sql, params})

        return await dbQuery(sql, params)
    }
    catch(err) {
        console.log('search Error', err)
    }
}
4
  • Check your JavaScript encoding. Commented Feb 25, 2019 at 6:35
  • How would I go about doing that? Commented Feb 25, 2019 at 6:38
  • Have a look here, and also read about using prepared statements in your Node JS code. Commented Feb 25, 2019 at 6:42
  • I'll have a look thanks. Also I am using prepared statements via my helper method (Check pastebin link) Commented Feb 25, 2019 at 6:43

1 Answer 1

0

Soultion I was being stupid

I had forgot to change the = to LIKE in my query

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.