Page 1 of 1

How to create database?

Posted: Wed 20 Oct 2010 17:35
by SanyaXYZ
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...

Posted: Thu 21 Oct 2010 06:52
by AlexP
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.

Posted: Thu 21 Oct 2010 14:06
by SanyaXYZ
Thank you, AlexP ^^

Posted: Fri 22 Oct 2010 17:03
by SanyaXYZ
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 :(

Posted: Mon 25 Oct 2010 07:20
by AlexP
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]);

Posted: Mon 25 Oct 2010 14:44
by SanyaXYZ
Thanks !!!