0
我有一個.txt
文件,插入查詢大約有10,000條記錄。這裏有一個例子:如何讀取.txt文件並運行查詢以插入記錄?
INSERT INTO tblVeiculo (VeiculoId, Codigo, Fabricante, Modelo, AnoInicial, AnoFinal, Portas, Combustivel, NrMotorObstruido) VALUES
(1, '001034066', 'AGRALE', 'MT 12.0 4X2 SB(E-TRONIC)(URB.) DIES 2P BASICO', 2005, 2013, 2, 'DIES', 1),
(2, '001034078', 'AGRALE', 'MT 12.0 4X2 LE(E-TRONIC)(RODOV.) DIES 1P BASICO', 2005, 2013, 1, 'DIES', 0),
(3, '001034080', 'AGRALE', 'MT 12.0 4X2 LE(E-TRONIC)(RODOV.C/AR) DIES 1P BASICO', 2005, 2013, 1, 'DIES', 0),
(4, '001034091', 'AGRALE', 'MT 12.0 4X2 LE(E-TRONIC)(URBANO) DIES 2P BASICO', 2005, 2013, 2, 'DIES', 0) ...
我想讀的.txt
文件並運行該查詢到的所有記錄插入到SQLite數據庫。
我創建一個表是這樣的:
db.openDatabase({
name: "data.db",
location: "default"
}).then(() => {
db.executeSql("CREATE TABLE IF NOT EXISTS tblVeiculo ("
+ "VeiculoId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ "Codigo VARCHAR (512), "
+ "Fabricante VARCHAR (256), "
+ "Modelo VARCHAR (512), "
+ "AnoInicial DATETIME, "
+ "AnoFinal DATETIME, "
+ "[Portas] INT (1), "
+ "Combustivel VARCHAR (256), "
+ "[NrMotorObstruido] INT (1)); ", {}).then((data) => {
console.log("TABLE CREATED: ", data);
}, (error) => {
console.error("Unable to execute sql teste", error);
})
}, (error) => {
console.error("Unable to open database", error);
});
如何閱讀.txt
文件並運行查詢插入SQLite中的記錄?
也許[** this **](http://stackoverflow.com/questions/38998559/how-to-read-a-text-file-that-was-downloaded-locally-ionic-2-and-科爾多瓦)或[**這**](https://forum.ionicframework.com/t/load-a-text-file-as-a-string-in-ionic-2/73180/2)可以幫助你。 – developer033