Comments (9)
@CosminCraciun this is a known error. Someone has modify the driver wrongly it has been reported to the typeOrm team. See the close issue @capacitor-community/sqlite #512 PRAMA table_info throws an error. I suggested a script to postinstall in waiting the fix from the typeOrm team.
from sqlite.
I had already included that in the post-install. Also the error only occurs in WAL mode, not on any of the others.
The error does not occur in CapacitorQueryRunner.js
.
It's actually in CapacitorDriver.js
, when journal mode is set. That calls directly .run from the sqlite driver, rather than using the capacitor query runner
from sqlite.
@CosminCraciun you could try to modify the script modify-typeorm.cjs
like this
const fs = require('fs');
const modTypeOrmCapacitor = (filePath, lineToModify, replacementText) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
// Split data by line
const lines = data.split('\n');
// Modify the specific line
if (lines.length >= lineToModify) {
lines[lineToModify - 1] = replacementText; // Line numbers are 1-based
} else {
console.error('Line number to modify is out of range.');
return;
}
// Join lines back together
const modifiedData = lines.join('\n');
// Write the modified data back to the file
fs.writeFile(filePath, modifiedData, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('File modified successfully.');
});
});
}
/* Moddify CapacitorQueryRunner.js */
let filePath = './node_modules/typeorm/driver/capacitor/CapacitorQueryRunner.js';
let lineToModify = 61;
let replacementText = ' else if (["INSERT", "UPDATE", "DELETE"].indexOf(command) !== -1) {';
modTypeOrmCapacitor(filePath, lineToModify, replacementText)
/* Moddify CapacitorDriver.js */
filePath = './node_modules/typeorm/driver/capacitor/CapacitorDriver.js';
lineToModify = 62;
replacementText = ' await connection.execute(`PRAGMA foreign_keys = ON`);';
modTypeOrmCapacitor(filePath, lineToModify, replacementText)
/* Moddify CapacitorDriver.js */
filePath = './node_modules/typeorm/driver/capacitor/CapacitorDriver.js';
lineToModify = 65;
replacementText = ' await connection.execute(`PRAGMA journal_mode = ${this.options.journalMode}`);';
modTypeOrmCapacitor(filePath, lineToModify, replacementText)
if it works you must report the error on the typeorm package
from sqlite.
There is a problem with modifying CapacitorDriver.js
in this way.
Because the operations are asyncronous, the modifications are done in parallel, so we hit a concurency issue. I end up with just the second modification instead of both. Also, looking into the API section, .execute
still does stuff in a transaction as default. I did some changes to the script:
const fs = require('fs');
const modTypeOrmCapacitor = (filePath, lineToModify, replacementText) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
// Split data by line
const lines = data.split('\n');
// Modify the specific line
if (lines.length >= lineToModify) {
lines[lineToModify - 1] = replacementText; // Line numbers are 1-based
} else {
console.error('Line number to modify is out of range.');
return;
}
// Join lines back together
const modifiedData = lines.join('\n');
// Write the modified data back to the file
fs.writeFile(filePath, modifiedData, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('File modified successfully.');
});
});
}
const correctBugInCapacitorDriver = (file) => {
if (fs.existsSync(file)) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
const index = data.indexOf('await connection.run(`PRAGMA foreign_keys = ON`);');
if (index === -1) {
console.warn('Line not found. Package probably fixed.');
return;
}
var result = data.replace(
'await connection.run(`PRAGMA foreign_keys = ON`);',
'await connection.execute(`PRAGMA foreign_keys = ON`);'
);
result = result.replace(
'await connection.run(`PRAGMA journal_mode = ${this.options.journalMode}`);',
'await connection.execute(`PRAGMA journal_mode = ${this.options.journalMode}`, false);'
);
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.error(err);
});
});
} else {
utils.warn(`Couldn't find file ${file}`);
}
}
/* Moddify CapacitorQueryRunner.js */
let filePath = './node_modules/typeorm/driver/capacitor/CapacitorQueryRunner.js';
let lineToModify = 61;
let replacementText = ' else if (["INSERT", "UPDATE", "DELETE"].indexOf(command) !== -1) {';
modTypeOrmCapacitor(filePath, lineToModify, replacementText)
/* Moddify CapacitorDriver.js */
correctBugInCapacitorDriver('./node_modules/typeorm/driver/capacitor/CapacitorDriver.js');
correctBugInCapacitorDriver('./node_modules/typeorm/browser/driver/capacitor/CapacitorDriver.js');
The problem is, I'm still getting the error on WAL
. I'm still investigating why. I've tried removing the lines alltogether instead of replacing, and I still get the error. Which doesn't make sense at all.
from sqlite.
Apparently, angular was caching my node_modules files.
The script above works fine.
So we need the .execute(..., false)
and editing the file in one go.
from sqlite.
@CosminCraciun ok i modify the script based on your proposal
const fs = require('fs');
const modTypeOrmCapacitor = (filePath, lineToModify, replacementText) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
// Split data by line
const lines = data.split('\n');
// Modify the specific line
if (lines.length >= lineToModify) {
lines[lineToModify - 1] = replacementText; // Line numbers are 1-based
} else {
console.error('Line number to modify is out of range.');
return;
}
// Join lines back together
const modifiedData = lines.join('\n');
// Write the modified data back to the file
fs.writeFile(filePath, modifiedData, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('File modified successfully.');
});
});
}
/* Moddify CapacitorQueryRunner.js */
let filePath = './node_modules/typeorm/driver/capacitor/CapacitorQueryRunner.js';
const correctBugInCapacitorQueryRunner = (file) => {
if (fs.existsSync(file)) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
const index = `"DROP",`
if (index === -1) {
console.warn('Line not found. Package probably fixed.');
return;
}
var result = data.replace(
` "DROP",`,
` "DROP",
"PRAGMA"`
);
result = result.replace(
'else if (["INSERT", "UPDATE", "DELETE", "PRAGMA"].indexOf(command) !== -1) {',
'else if (["INSERT", "UPDATE", "DELETE"].indexOf(command) !== -1) {'
);
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.error(err);
});
});
} else {
utils.warn(`Couldn't find file ${file}`);
}
}
/* Moddify CapacitorDriver.js */
const correctBugInCapacitorDriver = (file) => {
if (fs.existsSync(file)) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
return console.error(err);
}
const index = data.indexOf('await connection.run(`PRAGMA foreign_keys = ON`);');
if (index === -1) {
console.warn('Line not found. Package probably fixed.');
return;
}
var result = data.replace(
'await connection.run(`PRAGMA foreign_keys = ON`);',
'await connection.execute(`PRAGMA foreign_keys = ON`, false);'
);
result = result.replace(
'await connection.run(`PRAGMA journal_mode = ${this.options.journalMode}`);',
'await connection.execute(`PRAGMA journal_mode = ${this.options.journalMode}`, false);'
);
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.error(err);
});
});
} else {
utils.warn(`Couldn't find file ${file}`);
}
}
correctBugInCapacitorQueryRunner('./node_modules/typeorm/driver/capacitor/CapacitorQueryRunner.js');
correctBugInCapacitorQueryRunner('./node_modules/typeorm/browser/driver/capacitor/CapacitorQueryRunner.js');
correctBugInCapacitorDriver('./node_modules/typeorm/driver/capacitor/CapacitorDriver.js');
correctBugInCapacitorDriver('./node_modules/typeorm/browser/driver/capacitor/CapacitorDriver.js');
i remove the cache files of the browser close it and reopen it
i run
npm run build --force
npm run dev
Now it is working
from sqlite.
@CosminCraciun Sorry i did not see your previous answer yes it was a cash issue. I add PRAMA to the list for execute command. I test it on a react-ionic-vite-app
from sqlite.
Perfect!
Thanks a lot!
For me, I actually had to delete the .angular
folder to remove the cache.
from sqlite.
@CosminCraciun OK i close the issue then
from sqlite.
Related Issues (20)
- Bug(Android): Calling `run` method with `BEGIN` statement throws StringOutOfBoundIndexException HOT 16
- Is this plugin still maintained in 2024? HOT 2
- "CapacitorSQLite" plugin is not implemented on ios HOT 4
- ionic7-angular-sqlite-app tutorial ionic.config.json type angular-standalone doesn't exist HOT 1
- ionic7-angular-sqlite-app tutorial fails on v5.7.1 HOT 6
- GetFromHTTPRequest not working HOT 3
- Multi Row Statement does not escape characters HOT 4
- Multiple Row Statement Values case insensitive HOT 3
- Multirow statements inserts wrong semicolon HOT 2
- foreign key ON DELETE CASCADE HOT 1
- Create CapacitorJS v6 package compatibility HOT 43
- ExecuteTransaction with values throws exception for statements performing no actual changes HOT 5
- Memory leak using .saveToStore() HOT 18
- Migration not working on iOS HOT 3
- executeSet not inserting rows HOT 8
- Multi Value Statement error with spaces inbetween ? HOT 1
- Multi row statement should fail if no values are replaced HOT 5
- Can I use this plugin inside the background runner capacitor plugin? HOT 2
- Update Capacitor dependencies to version >6 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlite.