0

To connect to the database I use this example. But I can't find lessons on how to create a database.

For example:

  1. connect to server
  2. create new database
  3. do something
  4. drop database
  5. close connection

Can anybody show me how to do it?

Thanks!

dda
  • 6,030
  • 2
  • 25
  • 34
kaa
  • 1,265
  • 5
  • 22
  • 39

3 Answers3

1

Follow the manual on how to create a database cluster:

http://www.postgresql.org/docs/9.1/interactive/creating-cluster.html

The database and users are created only once and you can use the client applications for that. Or are you trying to do it automatically as part of a software install package? After that you connect to it as many times as needed.

Clodoaldo Neto
  • 118,695
  • 26
  • 233
  • 260
  • I need to create application, that should to create database on server each time when it started, and removes it, when quit. I can't find how to do this, using RealStudio. – kaa Mar 13 '12 at 11:18
1

Since you are creating a new database and then dropping it, why not use the built-in SQLite database? You can do a completely in-memory database that will be lightning fast (unless you fill up available RAM).

BKeeney Software
  • 1,299
  • 6
  • 8
  • I'm just view possibilities of Real Studio, and want to know - how it interact with build-in databases))) MySql/PostgreSql/Sqlite – kaa Mar 13 '12 at 16:24
  • They all use the generic Database class and subclass into the specific databases. All of them interact with the database using straight SQL using the database.SQLExecute statement and you can insert data using SQL or using the DatabaseRecord class. You can modify data using SQL or by using the Recordset class. The differences between the databases are pretty minimal at that point. We often do development on SQLite and then later in the process switch to a db server (like Postgres). – BKeeney Software Mar 13 '12 at 20:52
  • Yes, I'm already understood how to use Database class to manage existed database. But question is very simple - can I create new database? – kaa Mar 14 '12 at 08:30
0

I believe you can create databases by issuing standard SQL commands just as you can create tables in a database, as long as you are using a user (e.g. admin or similarly entitled user) that has permissions to create new databases.

So, all you need is to connect to the DB with the right user and then issue SQL commands with db.SQLExecute, such as "create database newDBname".

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149