Open noday opened 10 months ago
Are you getting anything from console.error?
Is /test.json
the correct path its absolute - are you sure you did not mean ./test.json? Can you load the file manually from the browser?
error
no error, if use letter in json file, it can search. WHERE name like '%q%'
the '中文' encode to x96x87, maybe encode type used incorrect
it is json file
Interesting. Any chance you can share the actual json file so we can try a bit?
test.json version "alasql": "^4.2.2", code
import alasql from "alasql";
alasql.promise("SELECT * FROM json('/test.json') WHERE name like '%q%'").then(function (results) {
console.log(results);
}).catch(console.error);
// let arr = [{ "name": "中文", "addr": "中文" }, { "name": "文", "addr": "文" }];
// let res = alasql("SELECT * FROM ? WHERE name like '%文%'", [arr]);
// console.log(res);
I wanted to solve this issue, so I tried to reproduce the error. But, it seems to work well in the same situation. Below is the single test.js file for reproducing bug, and I included test.json in the same directory. Only included alasql dependency.
const alasql = require('alasql')
let arr = [
{ name: '中文', addr: '中文' },
{ name: '文', addr: '文' }
]
let res = alasql("SELECT * FROM ? WHERE name like '%文%'", [arr])
console.log(res)
alasql
.promise("SELECT * FROM json('./test.json') WHERE name like '%文%'")
.then(function (results) {
console.log(results)
})
.catch(console.error)
I think there's no encoding problem or error occured. I only encountered an error if I write the file location in absolute path way (like /test.json). I think that could be the problem. If I'm missing an error, please let me know. Thank you! ☺️
vue3 ts ··· // it is work, and console print [{...}] let arr = [{ "name": "中文", "addr": "中文" }, { "name": "文", "addr": "文" }]; let res = alasql("SELECT * FROM ? WHERE name like '%文%'", [arr]);
// but use json file, not work, console print [] alasql.promise("SELECT * FROM json('/test.json') WHERE name like '%文%'").then(function (results) { console.log(results); }).catch(console.error); ··· test.json
both file encode utf8