pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Create a database with ecpg
6+ messages / 4 participants
[nested] [flat]

* Create a database with ecpg
@ 1999-09-22 01:15  rodneyr@embratel.com.br
  0 siblings, 3 replies; 6+ messages in thread

From: rodneyr@embratel.com.br @ 1999-09-22 01:15 UTC (permalink / raw)
  To: pgsql-interfaces@hub.org

I include the following statement in my program to create a database:

"EXEC SQL CREATE DATABASE testbase;"

Then I compiled it, using ecpg, but the database was't been created.

When a try to open it with "psql" I receive the message:

Connection to database 'testbase' failed.
FATAL 1:  Database testbase does not exist in pg_database

Is there any mistake in my statement?

P.S.: I compiled the program without receiving any mistake message.

Thank you.

Rodney.





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [INTERFACES] Create a database with ecpg
@ 1999-09-22 05:52  Hannu Krosing <hannu@tm.ee>
  parent: rodneyr@embratel.com.br
  2 siblings, 0 replies; 6+ messages in thread

From: Hannu Krosing @ 1999-09-22 05:52 UTC (permalink / raw)
  To: rodneyr@embratel.com.br; +Cc: pgsql-interfaces@hub.org

rodneyr@embratel.com.br wrote:
> 
> I include the following statement in my program to create a database:
> 
> "EXEC SQL CREATE DATABASE testbase;"
> 
> Then I compiled it, using ecpg, but the database was't been created.

Did you connect (to template1 or any other existing DB) first ?

-----------
Hannu



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [INTERFACES] Create a database with ecpg
@ 1999-09-22 06:12  Michael Meskes <meskes@postgresql.org>
  parent: rodneyr@embratel.com.br
  2 siblings, 0 replies; 6+ messages in thread

From: Michael Meskes @ 1999-09-22 06:12 UTC (permalink / raw)
  To: rodneyr@embratel.com.br; +Cc: pgsql-interfaces@hub.org

On Tue, Sep 21, 1999 at 10:15:33PM -0300, rodneyr@embratel.com.br wrote:
> "EXEC SQL CREATE DATABASE testbase;"
> 
> Then I compiled it, using ecpg, but the database was't been created.
> 
> When a try to open it with "psql" I receive the message:
> 
> Connection to database 'testbase' failed.
> FATAL 1:  Database testbase does not exist in pg_database

To be honest, I never tried that. I will as soon as I find the time.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [INTERFACES] Create a database with ecpg
@ 1999-09-22 11:55  rodneyr@embratel.com.br
  0 siblings, 0 replies; 6+ messages in thread

From: rodneyr@embratel.com.br @ 1999-09-22 11:55 UTC (permalink / raw)
  To: pgsql-interfaces@hub.org

When I create the database using "createdb", everything works well. But when I
try to create it inside my program C, nothing works and I don't receive any
error messages.

It's a simple program, that I made just to learn embbed SQL in C. It creates a
database, or try, called "testbase". Then I create a table and put 3 values
inside it (1, 2 and 3).

I pre-compiled it using ecpg and then compiled using gcc.

P.S.: I'm able to connect to any other database with psql.

Thank you.

Rodney





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [INTERFACES] Create a database with ecpg
@ 1999-09-27 09:55  Michael Meskes <michael@fam-meskes.de>
  parent: rodneyr@embratel.com.br
  2 siblings, 0 replies; 6+ messages in thread

From: Michael Meskes @ 1999-09-27 09:55 UTC (permalink / raw)
  To: rodneyr@embratel.com.br; +Cc: pgsql-interfaces@hub.org

On Tue, Sep 21, 1999 at 10:15:33PM -0300, rodneyr@embratel.com.br wrote:
> "EXEC SQL CREATE DATABASE testbase;"
> 
> Then I compiled it, using ecpg, but the database was't been created.

In fact only a directory was created, right?

> When a try to open it with "psql" I receive the message:
> 
> Connection to database 'testbase' failed.
> FATAL 1:  Database testbase does not exist in pg_database
> 
> Is there any mistake in my statement?

Yes and no. The statement itself is correct. However, the usage is not. I
take it you are executing the statement inside a transaction but do not
issue a commit afterwards. Thus pg_database is not updated at all.

Please try calling EXEC SQL COMMIT; after the CREATE DATABASE call. This
should work. At least it does for me. 

Or call ecpg with parameter '-t' to switch off autotransaction mode. With
'-t' the CREATE DATABASE statement becomes a transaction for itself and thus
is committed once it returns.

Hope this helps.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: [INTERFACES] Create a database with ecpg
@ 1999-09-27 18:36  Michael Meskes <meskes@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Michael Meskes @ 1999-09-27 18:36 UTC (permalink / raw)
  To: pgsql-interfaces

On Tue, Sep 21, 1999 at 10:15:33PM -0300, rodneyr@embratel.com.br wrote:
> "EXEC SQL CREATE DATABASE testbase;"
> 
> Then I compiled it, using ecpg, but the database was't been created.

In fact only a directory was created, right?

> When a try to open it with "psql" I receive the message:
> 
> Connection to database 'testbase' failed.
> FATAL 1:  Database testbase does not exist in pg_database
> 
> Is there any mistake in my statement?

Yes and no. The statement itself is correct. However, the usage is not. I
take it you are executing the statement inside a transaction but do not
issue a commit afterwards. Thus pg_database is not updated at all.

Please try calling EXEC SQL COMMIT; after the CREATE DATABASE call. This
should work. At least it does for me. 

Or call ecpg with parameter '-t' to switch off autotransaction mode. With
'-t' the CREATE DATABASE statement becomes a transaction for itself and thus
is committed once it returns.

Hope this helps.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael@Fam-Meskes.De           | Use PostgreSQL!




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~1999-09-27 18:36 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-09-22 01:15 Create a database with ecpg rodneyr@embratel.com.br
1999-09-22 05:52 ` Hannu Krosing <hannu@tm.ee>
1999-09-22 06:12 ` Michael Meskes <meskes@postgresql.org>
1999-09-27 09:55 ` Michael Meskes <michael@fam-meskes.de>
1999-09-22 11:55 Re: [INTERFACES] Create a database with ecpg rodneyr@embratel.com.br
1999-09-27 18:36 Re: [INTERFACES] Create a database with ecpg Michael Meskes <meskes@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox