我正在开发一个解析多个文本文件的Web应用程序,将数据存储在SQLite3数据库中并在浏览器中显示数据。然后我向我的Node.js服务器发出HTTP请求以查询数据库。数据将转换为JSON并发送回浏览器。最后,JSON被转换回字符串并解析它以供显示。
我的程序适用于200MB以下的小文件,但在解析和显示方面却非常缓慢。当它达到300MB +时,我无法解析文件并得到此错误。
ProgrammingError:除非使用a,否则不得使用8位字节串 text_factory,可以解释8位字节串(如text_factory = STR)。强烈建议您只需切换即可 应用于Unicode字符串。
我尝试了text_factory,它摆脱了错误代码。当我查询数据库时,它什么都不返回,程序挂起。我是新手。我究竟做错了什么?我该怎么做才能让它解析更大尺寸的文件更快?
#parsing some files and insert them into a sqlite database
#create database in python
conn = sqlite3.connect('MyDB.db')
conn.text_factory = str # didn't work, the program hang
c = conn.cursor()
c.execute('''CREATE TABLE actions (dates text, names text, methods text)''')
c.execute('''CREATE TABLE people (names text, ID text)''')
# insert in different function
dataB.execute("INSERT INTO people VALUES(?, ?)", (value[index], id))
dataB.execute("INSERT INTO action VALUES(?, ?, ?)", (date, value[index], someaction ))
//seperate file
//retrieve the data from javascript
var sqlite3 = require("sqlite3");
var logDB = new sqlite3.Database("log.db");
query = "SELECT DISTINCT id, name FROM people p, action a where p.name = a.name and p.id Not IN (SELECT DISTINCT id FROM someothertable);";
function queryTheServer(query, response) {
logDB.all(query, function(error, thing){
serveFromDatabase(error, thing, query, response);
});
}
//pass by as JSON
response.writeHead(200, {"Content-Type": "application/json"});
response.write(JSON.stringify(result));
response.end();