• Welcome, Guest. Please login.
October 25, 2021, 09:50:12 PM


Welcome to the SQLitening support forums!

Does the table exist??

Started by Fim, February 12, 2011, 04:06:11 PM

Previous topic - Next topic


I know that I can use 'slExe "Create Table If Not Exists ART(...."'
But I want to do other things in PowerBasic when a table does not exist.
Is there a good way to test if a table exist or not?
/Fim W
Fim W

R Robinson

February 12, 2011, 05:20:56 PM #1 Last Edit: February 13, 2011, 11:41:27 AM by R Robinson
The following will return the list of TABLES, this is also listed in the SQLitening help file

slcmd = "SELECT name FROM (SELECT * FROM sqlite_master UNION ALL "
  mslcmd = mslcmd + "SELECT * FROM sqlite_temp_master) WHERE type='table' "
  mslcmd = mslcmd + "ORDER BY name"
  slSel mslcmd
  mi = 1
   DO WHILE slgetrow
      mstrAnswer =  slFN("name") + CHR$(0)
      mTable_Names = mTable_Names + mstrAnswer
      INCR mi

Local tblNames         as String
Local tblNum             as Long
Local i                        as Long

tblNames = slGetTableNames("sample.db3")

'Get number of tabel
tblNum = ParseCount(tblNames, Chr$(0))

For i = 1 to tblNum
            Listbox Add hDlg, %ID_LISTBOX, Parse$(tblNames, Chr$(0), i)

Fred Meier

There are several ways to determine if a table exists:
1.  Use the code in the prior post.
2.  Use the slGetTableNames function and check if your table name is returned
3.  Use the Pragma table_info.  This is my favorite used as follows:
      if len (slSelStr("Pragma table_info(PurYourTableNameHere)")) then TableExists


1 Is too complex for mee
2 Have tested, works fine
3 Is perfect, I use i now.

/ Fim W.
Fim W