I currently have a web app that has an SQLite database controlling user SQLite databases. When new users subscribe, a new SQLite databases file is added using sqlClientDB.CreateDatabaseFile & then sqlClientDB.SQLExecute ("create table… to create the tables & fields etc.
My question is, how, using Xojo, do you add a new PostgreSQL data file for a new user? I am fine with tables & fields etc, but unless I missing something, Xojo doesn’t have CreateDatabaseFile method like it does for SQLite.
Thanks for any help or pointers
PostgreSQL is a server; it doesn’t use files like SQLite does. You typically use a admin tool of some kind to add new databases to the server.
LIke nearly all database systems, you can create any object using sql. Use the CREATE DATABASE command to create a new database. You’ll need to refer to the postgresql documentation for the full syntax/options.
Hi Paul & Jay thanks for getting back quickly.
Paul thanks for the links I will check them out.
Guys I need to workout how todo this from within the Xojo web app when a new user registers.
The documentation states to create a new database, in this example named mydb, you use the following command: $ createdb mydb
How do I execute this from within Xojo?
I have been playing around with code similar to add tables & fields but no luck.
mDb = New PostgreSQLDatabase
mDb.Host = "localhost"
mDb.UserName = "postgres"
mDb.Password = "mdSd@13Imh" // "dbexample"
Dim sql As String
'sql = "CREATE DATABASE mydb"
'sql = "CREATE DATABASE: mydb;"
'sql = "create database mydb;"
'sql = "create database: mydb;"
'sql = "createdb: mydb;"
sql = "$ createdb: mydb;"
it should work with
sql = "CREATE DATABASE mydb"
is mdb connected ?
createdb is a command line utility that just runs the CREATE DATABASE sql query.
You don’t have a Connect line in your sample code (If mDB.Connect Then…).
You will need to connect to an existing database first before executing any queries. You can connect to the default postgres db, then create the new db, then start a new connection to that database.
See https://www.postgresql.org/docs/9.1/static/sql-createdatabase.html for full syntax of the CREATE DATABASE command.
Thanks everyone will try the suggestions