Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not select use where in json file #1841

Open
noday opened this issue Nov 21, 2023 · 7 comments
Open

can not select use where in json file #1841

noday opened this issue Nov 21, 2023 · 7 comments

Comments

@noday
Copy link

noday commented Nov 21, 2023

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
image

both file encode utf8

@mathiasrw
Copy link
Member

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?

@noday
Copy link
Author

noday commented Nov 22, 2023

error

no error, if use letter in json file, it can search. WHERE name like '%q%'
image

@noday
Copy link
Author

noday commented Nov 22, 2023

the '中文' encode to x96x87, maybe encode type used incorrect

@noday
Copy link
Author

noday commented Nov 22, 2023

image
it is json file

@mathiasrw
Copy link
Member

Interesting. Any chance you can share the actual json file so we can try a bit?

@noday
Copy link
Author

noday commented Nov 22, 2023

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);

@bgb10
Copy link

bgb10 commented Dec 27, 2023

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! ☺️

Screenshot 2023-12-28 at 12 29 19 AM Screenshot 2023-12-28 at 12 29 34 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants