I have encountered some issues when importing data from SQL dumps through the sqlitePorter.importSqlToDb function
Reproduction steps:
version: 1.1.1
Try to ingest
CREATE TRIGGER IF NOT EXISTS update_person_updated_at AFTER UPDATE ON person
BEGIN
UPDATE person SET updated_at = (strftime('%Y-%m-%d %H:%M:%f', 'now', 'utc')) WHERE id = OLD.id;
END;
Error
"Failed to import SQL; message=sqlite3_prepare_v2 failure: incomplete input","code":5,"statement":"CREATE TRIGGER update_person_updated_at UPDATE ON person\nBEGIN\n UPDATE person SET updated_at = (strftime('%Y-%m-%d %H:%M:%f', 'now', 'utc')) WHERE id = OLD.id"}
I believe that the bug is caused by the removeComments(sql) function, which I have inspected and shows that the SQL command is interpreted as two different statements:
- First statement:
BEGIN UPDATE person SET updated_at = (strftime('%Y-%m-%d %H:%M:%f', 'now', 'utc')) WHERE id = OLD.id
- Second statement:
END
This of course is not right since it must be interpreted as a single SQL statement.
I have made a temporary fix with:
sqlitePorter.importSqlToDb = function (db, sql, opts){
opts = opts || {};
if(!isValidDB(db, opts)) return;
db.transaction(function(tx) {
try {
//Clean SQL + split into statements
var totalCount, currentCount;
var tempStatements = removeComments(sql).match(statementRegEx);;
var statements = [];
for (let i = 0; i < tempStatements.length; i++) {
if (tempStatements[i].toUpperCase() === 'END') {
statements[statements.length - 1] += ';\nEND';
} else {
statements.push(tempStatements[i]);
}
}
# ...
Which works, but it the best approach is solving it directly inside the removeComments function.
It would be nice to have an official fix. Let me know if more details are needed.
I have encountered some issues when importing data from SQL dumps through the
sqlitePorter.importSqlToDbfunctionReproduction steps:
version:
1.1.1Try to ingest
Error
I believe that the bug is caused by the
removeComments(sql)function, which I have inspected and shows that the SQL command is interpreted as two different statements:BEGIN UPDATE person SET updated_at = (strftime('%Y-%m-%d %H:%M:%f', 'now', 'utc')) WHERE id = OLD.idENDThis of course is not right since it must be interpreted as a single SQL statement.
I have made a temporary fix with:
Which works, but it the best approach is solving it directly inside the
removeCommentsfunction.It would be nice to have an official fix. Let me know if more details are needed.