Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Struggling with testing if a table exists
Mon, Dec 21 2020 12:08 PMPermanent Link

bpolky

I am a new user of Elevate DB, trying to convert my existing system from another database manager. I want to create a separate table in a database for each user (same fields). If that user is new, it must create a table for them. That means testing to see if a table already exists. I am using the code from this forum for testing the table exists.

My test code looks like....

Var
SQLString : String;
TableName : String;
Const
RetStr : string = ''#13#10'';

begin
TableName := 'Test1';
TabTest.TableName := TableName;
SQLString := 'CREATE TABLE "' + TableName + '"' + RetStr;
SQLString := SQLString + '(' + RetStr;
SQLString := SQLString + '"Studio" INT' + RetStr;
SQLString := SQLString + ')';
EDB.Execute(SQLString);
ShowMessage('Check Manager for table');
EDB.Execute('SELECT Version FROM Information.Tables WHERE Name = "Test1"');
end;

At the ShowMessage point I can see that the table 'Test1' exists in the database.  But when I test for it, I get the error 'The column Test1 does not exist in the temporary table Tables".
Am I testing for the wrong thing?
Can someone explain where my error is?
Mon, Dec 21 2020 1:00 PMPermanent Link

Raul

Team Elevate Team Elevate

On 12/21/2020 12:08 PM, bpolky wrote:
> EDB.Execute('SELECT Version FROM Information.Tables WHERE Name = "Test1"');
> end;
>
> At the ShowMessage point I can see that the table 'Test1' exists in the database.  But when I test for it, I get the error 'The column Test1 does not exist in the temporary table Tables".
> Am I testing for the wrong thing?
> Can someone explain where my error is?
>

The Test1 is this case is a string literal (field value and not a db
object) so you need to use single quotes :

SELECT Version FROM Information.Tables WHERE Name = 'Test1'

Raul


Mon, Dec 21 2020 1:12 PMPermanent Link

bpolky

Raul wrote:

The Test1 is this case is a string literal (field value and not a db
object) so you need to use single quotes :

SELECT Version FROM Information.Tables WHERE Name = 'Test1'

Raul

Thanks.  I thought I had tried everything, but missed the obvious stuff.
Image