How to create database?

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
SanyaXYZ
Posts: 11
Joined: Wed 20 Oct 2010 17:22

How to create database?

Post by SanyaXYZ » Wed 20 Oct 2010 17:35

Hi,
sorry my english is bad
I download demo MyDac for Delphi 2010
and I download PgDacDemo
... but, this programm very difficult for me

I'm fish :cry:

I have Delphi 2010 and postgresql 8.3
How to create database?


I have placed PgConnection1 on my form and add procedure

1)
procedure TForm1.Button1Click(Sender: TObject);
begin
PgConnection1.username:=edit1.text;
PgConnection1.password:=edit2.text;
PgConnection1.database:=edit3.text;
PgConnection1.connected:=true;
end;


Please, prompt what next steps ?
2)...
3)...
4)...

Help me, please...

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 21 Oct 2010 06:52

Hello,

To create a database you can use the following code:

PgConnection1.Server:= 'YOUR_SERVER';
PgConnection1.Port:=5432;//<-- your port number
PgConnection1.Username:= 'your_user_name';
PgConnection1.Password:= 'your_password';
PgConnection1.Connect;
PgConnection1.ExecSQL('CREATE DATABASE test_db WITH OWNER = your_owner ENCODING = ''UTF8''',[null]);

Or you can use the standard PostgreSQL tool PgAdmin.

SanyaXYZ
Posts: 11
Joined: Wed 20 Oct 2010 17:22

Post by SanyaXYZ » Thu 21 Oct 2010 14:06

Thank you, AlexP ^^

SanyaXYZ
Posts: 11
Joined: Wed 20 Oct 2010 17:22

Post by SanyaXYZ » Fri 22 Oct 2010 17:03

AlexP wrote:Hello,

To create a database you can use the following code:

PgConnection1.Server:= 'YOUR_SERVER';
PgConnection1.Port:=5432;//<-- your port number
PgConnection1.Username:= 'your_user_name';
PgConnection1.Password:= 'your_password';
PgConnection1.Connect;
PgConnection1.ExecSQL('CREATE DATABASE test_db WITH OWNER = your_owner ENCODING = ''UTF8''',[null]);

Or you can use the standard PostgreSQL tool PgAdmin.

sorry,
what is "your_owner" ?

Please, write this string for example" PgConnection1.ExecSQL('CREATE DATABASE test_db WITH OWNER = your_owner ENCODING = ''UTF8''',[null]);"

I don't sleep two days :(

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 25 Oct 2010 07:20

Hello,

OWNER is the username of the new owner of the table.

You can read more information about PostgreSQL commands at the official PostgreSQL site or in the PostgreSQL documentation.

For example, your username is "sanya", then you can use the following code to create a database:

PgConnection1.ExecSQL('CREATE DATABASE test_db WITH OWNER = sanya ENCODING = ''UTF8''',[null]);

SanyaXYZ
Posts: 11
Joined: Wed 20 Oct 2010 17:22

Post by SanyaXYZ » Mon 25 Oct 2010 14:44

Thanks !!!

Post Reply