Comments (8)
@tobiasmuecksch First thanks for using the plugin. Which release of the plugin are you using?.
According to the readme, it should be
const result = await this._sqlite.query({statement:selectStatement, values: []});
this should work.
from sqlite.
@jepiqueau Thank you for your response. I'm using version 2.0.0-4
from sqlite.
@jepiqueau I have created a demo repository for you.
- clone this repo: https://github.com/tobiasmuecksch/capacitor-sqlite-demo
ionic cap run ios
- connect safari developer console with device or simulator
- push "Test SQLite" button
- check console output
from sqlite.
@tobiasmuecksch
The run and select methods are for one statement and not for multiple statements
so when you defined
const statement = `
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "myTable" (
"_id" TEXT,
"Type" TEXT,
"Title" TEXT
PRIMARY KEY("_id")
);
COMMIT TRANSACTION;`;
it can only be executed by the execute method
so replace
const result = await this.sql.run({statement, values: []});
with
const result = await this.sql.execute({statements:statement})
this should be better if your statement were correct but it is wrong SQL Statement
look first at the design of your database you intend to create a table "myTable" and you make a query on table "conversation" which is not existing
i have provided an app starter https://github.com/jepiqueau/angular-sqlite-app-starter you should be looking at it
finally i made the following changes and it works
async testSqlite() {
const statement = `
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "myTable" (
id TEXT PRIMARY KEY NOT NULL,
Type TEXT,
Title TEXT
);
PRAGMA user_version = 1;
COMMIT TRANSACTION;`;
await this.sql.init();
const result = await this.sql.execute({statements:statement});
console.log('RESULT', result);
const selectStatement = 'SELECT * FROM myTable';
const result1 = await this.sql.query({statement: selectStatement, values: []});
console.log('SELECT result (should be empty)', result1);
const insertStatement = `INSERT INTO myTable (id,Title) VALUES (?,?);`;
const result2 = await this.sql.run({statement: insertStatement, values: ['1234', 'Titel für 1234']});
const result3 = await this.sql.run({statement: insertStatement, values: ['4321', 'Titel für 4321']});
console.log('RESULTS', result2, result3);
// As you didn't enter the field "Type", you have to do a query
// only on non "NULL" fields current limitation that i am working on
const query1 = "SELECT id,Title from myTable"
const result4 = await this.sql.query({statement: query1, values: []});
console.log('SELECT 2 RESULTS (should have two results)', result4);
}
and in the sqlite.service
async run(query: capSQLiteOptions): Promise<capSQLiteResult> {
await this.waitForReady();
console.debug('SQL RUN:', query);
return await this.sqlite.run(query);
}
You also understand now that the transformQuery method will never work
from sqlite.
look first at the design of your database you intend to create a table "myTable" and you make a query on table "conversation" which is not existing
You are right, that's a copy-paste fault, because I copy-pasted the code from my main project.
Thank you very much for your help. I will try that and then close the issue.
from sqlite.
@tobiasmuecksch Ok you are welcome
from sqlite.
I will have a look to deal with sqlite NULL value in the next release, to day i am currently working on storing base64 image strings as Blob in sqlite3 which is not as easy
from sqlite.
Good to know. So I'd have to set empty strings instead?
from sqlite.
Related Issues (20)
- Bug(Android): Calling `run` method with `BEGIN` statement throws StringOutOfBoundIndexException HOT 16
- WAL mode with typeorm stopped working from version 0.3.18 HOT 9
- 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 29
- 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 4
- 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.