Creating a new PostgreSQL database

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Creating a new PostgreSQL database

Post by Simon Knight » Thu Mar 20, 2014 10:55 am

I am working on a database driven application that will act as a client to a postgresql database running on a windows server. At present I have postgresql running on my "localhost" on my Mac OS X development machine.

I am looking for a simple, elegant and robust method of dealing with the situation where my code attempts to connect to a database that does not exist. In these circumstances the command revOpenDatabase will return with an error message along the lines of "FATAL: database "myDatabase" does not exist" which is simply trapped. My initial thoughts were to attempt to write code that creates the database but I don't know how to. I have tried the shell command and createdb but am unable to get it to work even with localhost and suspect that issuing the command from a client to a server will be difficult.

My solution at present is to issue a warning that tells the user to run pgAdmin on the server and create the database. However I am curious if there is a better way.

My attempts at using the shell command

Code: Select all

on mouseUp
   
   --shell ("createdb smkTestDb")  -- fails
   --shell ("ls -l *.txt")  -- dictionary example also fails
   --put the shell of "ls -l *.txt" into field "debug"  --fails
      put the shell of "ls" into field "debug"  --lists my applications folder
   answer "Answer: " & it
   answer the result
end mouseUp
best wishes
Skids

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Creating a new PostgreSQL database

Post by MaxV » Wed Mar 26, 2014 2:21 pm

You must supply a valid database name, the default Postrgre configuration contains a pg (?) database. So you can use it to connect then create your database using a SQL query.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply