sqlite3 virtual tables lifetime - sqlite

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 :-)

Related

Difference between .db and .sqlite file

Through the SQLite database manager I am able to generate a .sqlite file.
And through Java code I am able to generate a .db file (database file) in SQLite database.
What is difference between the two files?
Absolutely none. SQLite does not care the least what extension the file uses. It checks whether what it was given is indeed a SQLite3 database by inspecting the magic number and the header.
It's purely up to you whether you use the suffix .db, .sqlite, .dat, .mydata, .foo or whatever... or no extension at all; that is also permitted. There is no standard and the documentation does not seem to make any particular suggestion either, so everybody uses something else.
Also, if you are using SQLite as a storage backend for your application, it actually makes sense to use extension specific to your application. Because it is not just any random SQLite database, it is SQLite database with specific schema storing particular kind of data.

Copy table from remote sqlite database?

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;

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.

linq to entities 3.5 across multiple databases in same engine

What do i need to do in order to be able to query across multiple databases which are in the same db engine?
I have added the .edmx file of 1 database, but i only need 1 view from another db.
Thanks in advance!
Here are a couple of options:
Depending on your database platform, make the view from your second database available in your first database. If you're using SQL Server, you can use a linked server. If you're using Oracle, you can use a DB Link. Simply create a view in your main database where the view's select statement utilizes the linked server or db link to reference the view from your second db.
Create a second .edmx file for your second database. This is the route I chose recently. However I was dealing with one SQL Server DB and one was Oracle DB. There were also multiple tables and functions from both being used. I determined that it was cleaner in my case to create two separate data access projects, one for each DB, each with it's own .edmx.
Hope this helps.

Can I modify the dbml file, to add new database to that in asp.net?

I want to add the new tables to dbml file dynamically from another database
Thank you
You won't be able to do this. A DataContext is intended to encapsulate a single database - or part of a single database.
If this is a SQL Server database, and the second database is on the same server, I'd suggest creating a view in the first database that selects data from a table in the second one.
Yes only one database is supported with LINQ to SQL. You can use a separate data context file though for this database. But you can't use both contexts in the same query, so you can't join across both databases. You can, however, use queries in stored procedures and join across both databases there, provided they are on the same server or a link server is setup in SQL Server.
HTH.

Resources