From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Used to connect to a PostgreSQL database.
In order to use this class, you must have the PostgreSQLPlugin database plug-in in your plugins folder.
The PostgreSQL plug-in supports MD5 password authentication.
A field specified as type Float is actually implemented by PostgreSQL as a double (8 bytes).
PostgreSQL dates: field types Date, Time, and TimeStamp are supported by using the DatabaseColumn.DateTimeValue method for a date representation of this data, or use StringValue to get a human-readable date and/or time.
The PostgreSQLDatabase engine supports only the MoveNext RowSet navigation method.
Also be sure to refer to the official PostgreSQL documentation.
Xojo Cloud includes built-in support for PostgreSQL databases, which you can enable in your UserGuide:Xojo Cloud Control Panel.
To access an external PostgreSQL databases from web apps running on Xojo Cloud, you will first have to use the FirewallPort class to open the port used to connect to PostgreSQL, which is usually 5432.
fwp.Open // This call is synchronous
If fwp.IsOpen Then
// Do what you need to do
Refer to the UserGuide:Xojo_Cloud_Control_Panel#PostgreSQL and MySQL Usage topic for more information about using PostgreSQL with Xojo Cloud.
PostgreSQLDatabase implements PostgreSQL's large objects. PostgreSQL requires that all large object operations be performed inside of a transaction. Therefore, you must start a transaction before you perform your first large object operation:
After you have performed your last large object operation, you should close the transaction, like this:
Please see the PostgreSQLLargeObject class for information on how to work with large objects.
Listen and Notify Protocol
The PostgreSQLDatabase class implements the listen and notify protocol of PostgreSQL databases.
To send a notification, call the PostgreSQLDatabase.Notify method with the name of the notification you want to send. For example, if you wanted to send a notification called "Hello World", you would call Notify like this:
To check for notifications, call the PostgreSQLDatabase.CheckForNotifications method. You will receive notifications as a PostgreSQLDatabase.ReceivedNotification event. The ReceivedNotification event is called with three arguments: the name of the notification as a String, the ID of the process sending the notification as an Integer, and an extra argument that the PostgreSQL documentation says is not used at this time. The name parameter is the same name that you used with the Notify method.
If you would like to check for notifications automatically, at some set interval, then use a Timer and call CheckForNotifications in its Action event.
This code connects to an existing PostgreSQL database.
db.Host = "192.168.1.172"
db.Port = 5432
db.DatabaseName = "myDatabase"
db.AppName = "MyApp"
db.Username = "Charlie"
db.Password = "mashie"
//proceed with database operations
Catch error As DatabaseException
MessageBox("The connection failed.")
- Example Projects/Database/PostgreSQL/LargeObjects
- Example Projects/Database/PostgreSQL/ListenAndNotify