Recent

Author Topic: [SOLVED] How to check for SQLite database existence?  (Read 9387 times)

ocpaul20

  • New Member
  • *
  • Posts: 18
[SOLVED] How to check for SQLite database existence?
« on: April 25, 2015, 01:59:53 am »
SQLite3
-------
I dont seem to be able to check for database/dataset existence. When the project form starts, the database file is created by the component. However the database file created EMPTY. This means that I cannot check if the file exists, and the program does not fail until I get to dataset open which is too late.

What is the correct sequence of checking and method to check if the database and table exist please?

In the IDE, I get system exception messages even if I wrap the open in a try/except block. Is there any way of SILENTLY checking for existence in these cases?

--------------------------------------------------------------
Puppy Linux Slacko 5.7
Lazarus 1.5 FPC version 2.6.5 Revision 48817 i396-linux-gtk2
« Last Edit: April 25, 2015, 02:08:21 pm by ocpaul20 »
=======================================
Free Pascal Compiler version 2.6.5 [2015/04/26] for i386
Puppy Linux Slacko 5.7 Frugal

LacaK

  • Hero Member
  • *****
  • Posts: 697
Re: How to check for SQLite database existence?
« Reply #1 on: April 25, 2015, 09:20:21 am »
To check for existence of Database you can use:
  FileExists('my_sqlite_db.db')

To check for existenceof any table inside database you can use f.e. (if you use sqlDB components):
  TSQLite3Connection.GetTableNames(SL) which fills TStringList SL with table names
and then you can use SL.IndexOf('my_table') to check if given table name exists in list.

ocpaul20

  • New Member
  • *
  • Posts: 18
Re: [SOLVED] How to check for SQLite database existence?
« Reply #2 on: April 25, 2015, 02:14:45 pm »
Thanks very much for the reply.
=======================================
Free Pascal Compiler version 2.6.5 [2015/04/26] for i386
Puppy Linux Slacko 5.7 Frugal

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: [SOLVED] How to check for SQLite database existence?
« Reply #3 on: April 26, 2015, 10:47:20 am »
Alternatively you can do this
Code: [Select]
CREATE TABLE IF NOT EXISTS ...since you might want to create it anyway.

http://www.sqlite.org/lang_createtable.html
Lazarus 1.7 (SVN) FPC 3.0.0

 

TinyPortal © 2005-2018