I'm building a small app with a local in memory database using Delphi 10.3 with FireDAC set to SQLite.
What is de default path to the database file that SQLite uses? (i.e. Database parameter is left blank)
I want to transfer the database file to another PC. I suppose it has the .db file extension, but I'm unable to locate the file.
from http://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_SQLite_with_FireDAC:
"To create and open an SQLite in-memory database use the following
parameters:
DriverID=SQLite Database=:memory: Or just leave the Database parameter
empty:"
This made me think that there should be a file that eventually stores the data, but it turns out there is none. All data is lost after the database is free'd.
By definition "in memory" means no file. If you need a file for your data then add a filename (complete with path) to the Database value in TFDConnection's Params.
You can do it in the object inspector at design time or by code at run time it looks like:
FDConnection1.Params.Values['Database'] := 'C:\ProgramData\YourCompany\YourApp\YourFile.sqlite3';
Of course it is better to set the path by querying Windows for the location of "Program Data".
Related
I deployed a sample.s3db SqLite to my Delphi android project.
set folder to:
fdconnection1.params.Database := system.ioutils.TPath.Combine( system.ioutils.TPath.GetDocumentsPath, 'sample.s3db');
in FDConnection1BeforeConnect event.
in Project-Deployment, set folder to assets\internal\ for Android
However, when I run the app, apparently it can find the physical file, but it says my tablename "Customers" is not found.
so in the BeforeConnect code, if I add a CREATE TABLE SQL create code if not exists, then everything works well but of course the table is empty (whereas my deployed sample.s3db is not empty) ... which proves the FILE sample.s3db was found and not corrupted, but somehow the Table was not found.
Even tried to change in BeforeConnect
FDConnection1.Params.Values['OpenMode'] := 'ReadWrite';
but it still doesn't work.
Any ideas the table name does not work?
I tried to change table name to all caps, in case Android is case-sensitive but it also does not work.
I recommend deleting your app from the android. This will clear out your data. Otherwise your new sqlite file is not deployed if the file already exists. This could happen for instance if you made an error in the path at one point in time so sqlite just created an empty database.
Your connection string looks correct and so does your destination path. Just to be safe, you may also want to clear out your other values for your connection.
fdConnection1.ConnectionDefName:= '';
I have visual studio 2010 with sql express. Im trying to create a asp website that will display a file from a database, and need to insert a textfile or pdf into the database table, can this be done using the visual interface, all the intructions i have found is only using the sql insert command?
Thanks
No you can't do this. Basic UI interface means you can type it in, you can't type in an array of byte.
So that means code, it's not hard, but I would recommend you consider storing the a url / filename in the table and then putting the file on the file system instead of as a blob in the table.
Files in database blobs does have some benefits for local deployment, in that you don't have to worry about some muppet making them inaccessible. Server side though that is far less of a worry. As long as you back up database and file system and come up with a reasonable directory and file naming structure its much less of a cost than bloating a database with a load of stuff you can't use in a query, not to mention it tends to make a fair mess of volume (mdb) file.
Oh and there are persistant rumours that MS are going to drop blobs over 8000 bytes as well.
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.
How can I convert my Access database (.accdb) to an SQLite database(.sqlite)?
May be you can use several step algoritm:
1. Export (convert) Access table or query to Excel file
2. Save Excel file as CSV file.
3. Use any SQLLite manager (for example, phpLiteAdmin) to import data from CSV file to exist SQLLite table.
Except Android and IOS, that use SQLLite, there are still webhostings, that use no more database engine, except for SQLLite.
1) If you want to convert a structure of db you shoud use any DB-modeling tools:
create new model from existing Access Database
generate sql scripte for creating SQLite database
use this script in SQL helper
2) If you want to import data from Access Database to your android app. I think you can do case #1, migrate all data from Access Database to temporary SQLite database, save it to asset folder and rewrite from asset to internal SQLite database during first app. start
Where is the SQLite database stored i.e. directory path on windows 7 when created ?
A SQLite database is a regular file. It is created in your script current directory.
.databases
If you run this command inside SQLite
.databases
it lists the path of all currently connected databases. Sample output:
seq name file
--- --------------- ----------------------------------------------------------
0 main /home/me/a.db
There is no "standard place" for a sqlite database. The file's location is specified to the library, and may be in your home directory, in the invoking program's folder, or any other place.
If it helps, sqlite databases are, by convention, named with a .db file extension.
If you are running Rails (its the default db in Rails) check the {RAILS_ROOT}/config/database.yml file and you will see something like:
database: db/development.sqlite3
This means that it will be in the {RAILS_ROOT}/db directory.
When you call sqlite3_open() you specify the filepath the database is opened from/saved to, if it is not an absolute path it is specified relative to your current working directory.
It depends on how you initialized the database. If you used the command line shell for SQLite (e.g. sqlite3 ex1) to create the database, it'll be a path from the root of your local machine. If you used a Python script to create the database, it'll be a path from your project.
To check the former, run the command line shell:
sqlite3
sqlite> .databases
To check the path in your project, you can print the path in the connection. For example:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATABASE = 'db'
def get_db_connection():
print(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn = sqlite3.connect(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn.row_factory = sqlite3.Row
return conn
In my case I think it was an access issue. I saved the SQLite files to "C:/Program Files (x86)/sqlite". I CD'd there, ran sqlite3, and created a database called test.db:
As you can see, I ran .database, which told me the .db file was created in the same directory, so I went to confirm in File Explorer, and it wasn't there:
Curiously the database was working correctly in spite of this.
It was only through trial-and-error that I discovered that I could save in some locations, but not others. It appears to me that SQLite can't save to locations that require elevation. In my case, moving from Program Files to My Documents made the issue go away.
I find it quite irritating that SQLite doesn't just tell me "access denied" instead of trying to be clever and saving to some location that I can't even find.
In Windows machines (Windows 2010), by default, the new SQLite database files will be stored in the same folder where Sqlite3.EXE application is stored in your machine. However , we can create a new folder in Windows and within sqlite> prompt, you may use the .cd to change to the new working directory.
It is a good idea to give a .db file extension to the new database files that you create (even though it is not mandatory to have any file extension)
The SQLite command, .databases will show the default database "main" or currently created or currently opened database or all "attached" database files with file path. The .attach is useful to attach more than one database file to the current connection when we want to work with tables belonging to different databases.
Regards,
Biju Joseph N.,
Houston TX, USA (January 12, 2023)
the database path will be displayed, when using .databases
SQLite is created in your python directory where you installed the python.
SQLit Database is simply a file where your local data is stored on your local machine
In Windows 10 if in the prompt command the path where you start sqlite is
C:\users\USER_NAME
You can find it in the user home folder.
The .db file is stored where you start the sqlite command.
I hope this solve the issue