Search Postgresql Archives

Re: C++Builder table exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux