Copy table from remote sqlite database? - sqlite

Is there any way to copy data from one remote sqlite database to another? I have file replication done across two servers; however, some changes are recorded in an sqlite database local to each server. To get my file replication to work correctly, I need to copy the contents of one table and enter them into the table on the opposite system. I understand that sqlite databases are not meant for remote access; but is there any way to do what I need? I suppose I could write the contents of the table to a file, copy that file, then add the contents to the other database. This doesn't seem like the best option though, so I'm looking for another solution.

If you have access to the other database file, you can ATTACH it:
ATTACH '/some/where/else/other.db' AS remote;
INSERT INTO MyTable SELECT * FROM remote.MyTable;

Related

Opening up database and saving the queries

I would need to return a homework.
In the homework i should open up an existing database: hw2tennis.db with sqlite3 and do some basic queries and then return it as .sql file. (I assume that .sql -datafile is the same as .db that I have used to put to the end of every database)
At the moment I know how I can open up a database in sqlite3 and I know how to do basic queries. To my understanding SQLite automatically writes on disk the changes so I don't need to save or anything when I do changes to tables and so on.
But I was wondering, is there a way to save the file in a way, that when someone opens it up, they will see the Queries I have made to it.
For example, if task 1 is:
Print all players and their information
So basically, I would write to SQlite: SELECT * FROM Player;
But, when I open up the hw2tennis.db again, there is only the tables and not the queries which is of course logical.
So can I save the FILE in a way that the teacher can see the queries made?
Thanks!
Just answered to your another question at opening up a database
You can save your queries and outputs in a directory of your Windows system (per your screenshot) and send them with the SQLite DB file to your teachers
There're some nice and free GUI tools that you can use:
DB Browser for SQLite at https://sqlitebrowser.org/
SQLiteStudio at https://sqlitestudio.pl/
DBeaver at https://dbeaver.io/ (support multiple platforms)
...etc.

sqlite database location node-red

I have a Node-RED flow. It uses a sqlite node. I am using node-red-node-sqlite. My OS is Windows 10.
My sql database is configured just with name "db" :
My question is, where is located the sqlite database file?
I already search in the following places, but didn't found:
C:\Users\user\AppData\Roaming\npm\node_modules\node-red
C:\Users\user\.node-red
Thanks in advance.
Edit
I am also using pm2 with pm2-windows-service to start Node-RED.
If you don't specify a full path to the file in the Database field it will create the file in the current working directory for the process, which will be where you ran either node-red or npm start.
Use full path location with file name.
It should work i guess.
This isn't a valid answer, just a workaround for those who have the same problem.
I could't find my database file. But inside Node-RED everything worked just great. So. this is what I have done as a workaround:
In Node-RED, make some select nodes to get all data from tables
Store the tables values somewhere (in a .txt file or something like that)
Create your database outside Node-RED, somewhere like c:\sqlite\db.db. Check read/write permissions
Create the tables and insert the values stored from old database
In Node-RED, inside "Database", put the complete path of the database. For example, c:\sqlite\db.db
In my case this was easy because I only had two database with less than 10 rows.
Hope this can help others.
Anyway, still waiting for a valid answer :)

Is there anyway to "add" tables to existing database when using Code First?

I want to add a module build on Code First to a running website, which already has an database. If I set my module to run on separated database, it works fine.
But my friend want to just "add" tables created by my modules to existing database, without adding a new database.
Is there anyway to archive that?
The solution is simple and very easy:
Run the module to create a new, clean database
Use SQL Server to generate sql scripts that create tables of that database. I personally think the metadata table is not needed
Run those scripts against target database
Modify the connection string to point to target database
Now it runs flawless! I'm so happy
Thank you.

Sqlite database exception: file is encrypted or is not a database in blackberry?

I am working on a firm application in which I need to create a local database on my device.
I create my local database through create statement[ It works well]
Then I use that file and perform insert operation through fire-fox sqlite plugin, I need to insert aprox 2000 rows at a time so I can not use code. I just run insert manually through sqlite plugin in fir-fox.
After that I just use that file in my place of my local database.
When I run select query through my code, It show Exception:java.lang.Exception: Exception: In create or prepare statement in DBnet.rim.device.api.database.DatabaseException: SELECT distinct productline FROM T_Electrical ORDER BY productline: file is encrypted or is not a database
I got the solution of this problem, I was doing a silly mistake by creating a file manually by right click in my RES folder, that is not correct. We need to create the database completely from SQlite plugin, then it will work fine. "Create data base from SQLITE(FIle too) and perform insertion operation from SQLITE, then it will work fine"
This is very rare problem, but i think it might be helpful for someone like me....!:)
You should check to see if there is a version problem between the SQLite used by your Firefox installation and that on the BlackBerry. I think I had the same error when I tried to build a database file with SQLite version 2.
You also shouldn't need to create the database file on the device. To create large tables I use a Ubuntu machine and the sqlite3 command line. Create the file, create the tables, insert the data and build indexes. Then I just copy the file onto the device in the proper directory.
For me it was a simple thing. One password was set to that db. I just used it and prolem got solved.

sqlite3 virtual tables lifetime

Can someone please tell me the lifetime of the virtual tables created in sqlite3. I have an android application with a search feature, and i want to use the fast text search feature of sqlite.
I do not know how long these tables stay in the system or if i need to create the tables each time i access the application.
Any help?
The SQLite FTS module creates several 'internal' tables for every virtual table you define. Those tables are plainly visible in the database schema, so FTS virtual tables as well as their underlying data are completely contained in the database file.
This might be different with other types of virtual table; e.g. the VirtualShape extension allows ESRI shapefiles (.shp) files to be read as tables; those are (naturally) stored separately from the SQLite database file.
In any case, the definition of any virtual table itself is stored in the database file, just like a normal table; so the answer to your question is:
No, there's no need to re-create them every time you open the database.
According the SQLite3 file format specification, the virtual table definitions are stored in the schema table like any other table. Any indices for a virtual table are also stored in the DB file.
I take all this to mean that a virtual table is stored in the DB file and thus persistent. You should not have to recreate it each time you open a DB connection - it wouldn't make much sense like that, anyway.
A simple test using the sqlite3 CLI tool and an FTS3 table confirms this :-)

Resources