C++Builder table exist

From: Charl Roux <charl(dot)roux(at)hotmail(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: C++Builder table exist
Date: 2013-03-13 10:59:34
Message-ID: DUB103-W643C88CC74C4BF90FD7FEB85E30@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi,

I have migrated from MySQL to PostgreSQL. I am running on WindowsXP SP3, C++Builder6, PostgreSQL9.2, pgExpress4.6(database driver)
I have the following scenarion. If my applications starts up, it will test if a certain table exists within the database. If not, it will create the table, else it will not re-create the table. This worked fine when I used MySQL, but with PostgreSQL not. The first time that I run the application, I do not get an error and the table is created. The second time I run the application, the application gives an error that the table already exists. This means that my method of testing if the table does exist, does not work with PostgreSQL, with the following message: ERROR: relation "querybackup" already exists
My code is as follows:

void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
int errorCode;
TStringList *tableList = new TStringList;
frmDataModule->eyeConnection->GetTableNames(tableList);

// create queryBackup table if does not exist
AnsiString SQL = "CREATE TABLE queryBackup( queryName VARCHAR(30) PRIMARY KEY,query VARCHAR(10000))";
if( tableList->IndexOf("queryBackup") < 0 )
errorCode = frmDataModule->eyeConnection->ExecuteDirect(SQL);
}

Thanks for the time.

Charl

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2013-03-13 11:07:54 Re: C++Builder table exist
Previous Message Alban Hertroys 2013-03-13 09:38:39 Re: table spaces