gpt4 book ai didi

javascript - AlaSQL 从 CSV 插入表不起作用

转载 作者:行者123 更新时间:2023-12-03 05:50:45 24 4
gpt4 key购买 nike

尝试将 CSV 数据复制到 AlaSQL 的内表。但是 SELECT * INTO tab FROM CSV() 根本不起作用。此后一切都没有改变。表 tab 仍然是空的,但直接选择工作正常。我做错了什么?

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="res1"></div>
<div id="res2"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/alasql/0.3.3/alasql.min.js"></script>

<script type="text/sql" id='sql'>
CREATE table tab(c1 integer);

select count(*) as c1
INTO tab
from CSV("https://rawgit.com/thephpleague/csv/master/examples/data/prenoms.csv");
-- tab still empty!

select *
into HTML("#res1",{headers:true})
from tab;

--direct select works
select count(*) as c1
into HTML("#res2",{headers:true})
from CSV("https://rawgit.com/thephpleague/csv/master/examples/data/prenoms.csv");

</script>
<script type="text/javascript">
alasql('SOURCE "#sql"')
</script>

</body>
</html>

最佳答案

与文件交互将使请求异步。目前,lib 无法弄清楚如何在多语句命令中等待异步语句的响应。

要解决这个问题,您可以对总语句的每个异步卡盘使用 promise 符号:

<script type="text/sql" id='sql'>
CREATE table tab(c1 integer);

select count(*) as c1
INTO tab
from CSV("https://rawgit.com/thephpleague/csv/master/examples/data/prenoms.csv");
-- tab still empty!
</script>
<script type="text/sql" id='sql2'>
select *
into HTML("#res1",{headers:true})
from tab;

--direct select works
select count(*) as c1
into HTML("#res2",{headers:true})
from CSV("https://rawgit.com/thephpleague/csv/master/examples/data/prenoms.csv");

</script>
<script type="text/javascript">
alasql.promise(['SOURCE "#sql"','SOURCE "#sql2"'])
</script>

关于javascript - AlaSQL 从 CSV 插入表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40167060/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com