how to open sqlite database in react native - sqlite

im using sqlite database in my react native project
i made app_db database that contain users table ,
and the path of database :
/home/dina/AppointmentApp/android/app/src/main/assets/app_db
now i want to access to the users table in my project and execute some queries like select , update, insert ...etc
here is the code of open connection
var db = SQLite.openDatabase({name : "app_db", createFromLocation : "~app_db"});
db.transaction((tx)=>{
tx.executeSql("select * from users",(tx,results) => {
});
});
i dont know if this query is correct or not
it is return in console
-OPEN database: app_db
-{message: "no such table: users (Sqlite code 1): , while comp…m users, (OS error - 2:No such file or directory)", code: 0}

I know this is old, but as per the error code: your database does not have the table "users".
If you are certain that it does, then perhaps the path you point to is wrong, and the database is created automatically (without a users table).
See here for a similar problem: No Such Table error

Related

ERROR Error: Uncaught (in promise): Object: {"code":0,"message":"Error: no such table: tablename"}

I am using ionic 5 and sqlite plugin
while creating db and tables for the first time , get table data is visible. But have a process to auto login in my app and when i try to fetch tables after auto login(which clearly means i dont create db or tables again) i am not able to fetch any tables.
this.storage.create in the app.component.ts open the db successfully before executing these getData transactions.
Let me know if anyone can help me out with this.

Azure Data Explorer write query result to cosmo db

I have a azure data-explor that queries some syslogs coming-in, filters and aggregate them. The output of this query is store on my local computer in a csv file. So every time a run my Python SDK, it runs a query and saves the output in a csv file.
What I am looking for, is to push that result of the query to a cosmosdb.
Looking into azure GitHub azure-sdk-for-python, I found a library that can achieve this result with this code.
from azure.cosmos import CosmosClient
import os
url = os.environ['ACCOUNT_URI']
key = os.environ['ACCOUNT_KEY']
client = CosmosClient(url, credential=key)
database_name = 'testDatabase'
database = client.get_database_client(database_name)
container_name = 'products'
container = database.get_container_client(container_name)
for i in range(1, 10):
container.upsert_item({
'id': 'item{0}'.format(i),
'productName': 'Widget',
'productModel': 'Model {0}'.format(i)
}
)
But I am a bit confused because they mention container.
I was wondering if there is a way that I can push my query result to a database or table using Python SDK.
Thank you so much for your time and help
In Cosmos DB terminology, Container is equivalent to a Table as Container holds the data like Table. If you're coming from a relational database world, here's the mapping (kind of):
Database Server --> Cosmos DB Account
Database --> Database
Table --> Container

Error while executing sql query on database

I'm trying to read BLOB data from messages table form WhatsApp database called msgstore, I want to get the file names that are transferred. The blob data is stored in thumb_image column.
I found this query here:
SELECT dbms_lob.substr(thumb_image)
FROM messages
WHERE _id = 3;
I also tried this query from here:
SELECT utl_raw.cast_to_varchar2(dbms_lob.substr(thumb_image))
FROM messages
WHERE _id = '3;
I both cases I keep getting an error thats says:
Error while executing sql query on database 'msgstore': near "(" syntax error.
I don't understand what's wrong with the query.
How can I fix this?

Unable to create a field of type Attachement with SQL script in Access database

I'm trying to create a table in an access database.
I've tried the following query but without success:
CREATE TABLE Test ([id] COUNTER (1,1),[AttachedFile] Attachment, [FolderId] Long))
The field of type Attachment seems to be very special. Am'I wrong with the field type ?
Any ideas ?
The workaround was to embed the database in Resources

how to let users to select columns in a database table

We are trying to build an web application that allows users to select appropriate columns for given database table.
I wonder if there is any API for these - I've googled it a while in vain. Otherwise, if you can give some clues (patterns or sample codes) how to build such a component, that will be great and appreciated.
You could base your application on INFORMATION_SCHEMA views/table. This is documentation for SQL Server, but you can easily find it for other databases too:
http://msdn.microsoft.com/en-us/library/ms186778.aspx
Sample SQLs:
select * from INFORMATION_SCHEMA.TABLES
select * from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'users'
if you want to use this solution with many databases, to separate your application from db engine, you can create about defining IMetadataProvider interface and create implementations for different databases:
interface IMetadataProvider {
...GetTables();
...GetTableColumns();
...GetTableRelations();
//Other functions required by your project
}
You can also create your own query builder interface:
interface IQueryBuilder {
...From(string tableName);
...Top(int numberOfRows); //TOP for SQL SERVER, LIMIT for MySQL
}

Resources