Creating a new PostgreSQL database
Posted: 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
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