I have a .txt
file containing an insert query with around 10,000 records. Below is an example:
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) ...
I need to extract the data from this .txt
file and execute the query to insert all the records into an SQLite database.
The table I am trying to create looks like this:
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);
});
Is there a way to read the content of the .txt
file and execute the insert query in SQLite?