Re: C++Builder table exist

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Charl Roux <charl(dot)roux(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: C++Builder table exist
Date: 2013-03-13 11:07:54
Message-ID: 51405E0A.2020204@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 13/03/2013 10:59, Charl Roux wrote:
> 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:

Well, if the table already exists and you try to create it, you're
naturally going to get an error; so you'll need to check for its
existence first. You probably want to do:

create table if not exists querybackup ....

>
> 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))";

You could just use the "text" type for the "query" column, and then you
don't have to worry about the length of data going into it; the downside
is that in Delphi/C++ Builder I think it gets mapped to a memo type
rather than a string.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2013-03-13 12:04:15 Re: C++Builder table exist
Previous Message Charl Roux 2013-03-13 10:59:34 C++Builder table exist