Recent

Author Topic: Location database in designmode  (Read 2347 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Location database in designmode
« on: November 27, 2017, 10:05:07 am »
Using TSQLiteconnection and TSQUery. In TSQLiteconnection.database the following value is set: ./databasename.db3. TSQLiteconnection.connected is set to true; database connected. Now opening TSQLquery whith propert active to true results an error :

TSQLiteconnection: no such table <teblename>

But running the application the table is found with the same value set in property database.

How is this possible. Is TSQLiteconnection still looking in the lazarus installation directory?
If I'm using a full path the the database, it's working fine.

I know './' tells to look in the current directory, but if it is the database should not be connected at all.   
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Location database in designmode
« Reply #1 on: November 27, 2017, 10:11:54 am »
At designtime the "./" usually refers to the folder in which lazarus.exe is found. Therefore, don't use relative paths at designtime. And: after you set up your database delete the path to the db file from the object inspector and set it at runtime. Otherwise your program will run only if the destination computer has the exact folder structure as your development computer, and if you'll decide to rearragne folders on your deveopment computer some time later you will not even be able to load the project any more.

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
Re: Location database in designmode
« Reply #2 on: November 27, 2017, 10:57:22 am »
Therefore, don't use relative paths at designtime.
Yukk...  Absolutely not.... introduces bugs....
Always use relative paths to your intended installation. NEVER use hardcoded paths.
In this case set an environment variable during development.
wp is fired. He knows why.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Location database in designmode
« Reply #3 on: November 27, 2017, 11:22:48 am »

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Location database in designmode
« Reply #4 on: November 28, 2017, 08:36:17 am »
@wp

Ususally I do, but for my demo not.
I find it strange that a connection is made to the SQLite database, but the table is not found.
That's my question.

Or it looks like TSQListeconnection opens a file if not exist and then the table is not found because of an empty database.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Location database in designmode
« Reply #5 on: November 28, 2017, 08:37:46 am »
@wp

Ususally I do, but for my demo not.
I find it strange that a connection is made to the SQLite database, but the table is not found.
That's my question.

Or it looks like TSQListeconnection opens a file if not exist and then the table is not found because of an empty database.
1)SQLite will create the database if it is not found on the disk. It is part of the C code not the pascal bindings.
2) if you do not specify your base directory for your relative paths then windows will auto expand the global system param currentDir which might or might not be your application's directory. Append manually at run time your base directory to all relative paths eg
Code: Pascal  [Select][+][-]
  1. function BaseDir :String
  2. begin
  3.   result := IncludeTeailingPathDelimiter(ExtractFileDir(paramstr(0)));
  4. end;
  5.  
and change your property to the database as TSQLiteconnection.database := basedir+TSQLiteconnection.database; This should solve all of your database problems.
« Last Edit: November 28, 2017, 08:43:02 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018