-
Notifications
You must be signed in to change notification settings - Fork 4
Connection
Connection objects are used by SQL Yoga to connect to databases that have the same schema. The object properties tell SQL Yoga where the database is located, which credentials to use to connect, etc.
A Database object can have multiple connections. For example, you can define one connection that connects to a database used for testing and another that connects to the live database.
The default connection that SQL Query and SQL Record objects use can be changed at any time by setting the default connection property (see dbobject_set) of the Database object. Whenever you call a handler that takes a connection object as a parameter you can leave the parameter empty to use the default connection.
If you are using SQL Yoga with Levure then you can configure connections using YAML.
If you are not using Levure, or you want to configure your connections using the API, then look at dbconn_createObject and dbconn_set
To connect to a database using a pre-configured connection object use [dbconn_connect](SQL-Yoga-API#dbconn_connect). If a connection fails then an error is thrown. This allows you to handle the error globally in your application by adding your own errorDialog handler to a script in the message path (e.g. a library).
# Card script
on openCard
...
dbconn_connect
...
end openCard
# library script
on errorDialog pError
# Let the IDE display the error in development
if the environment is "development" then pass errorDialog
switch item 1 of pError
case "sqlyoga_connection_err"
# handle connection error here
break
end switch
end errorDialog
You can also wrap the call to dbconn_disconnect using a try/catch block:
try
dbconn_connect
catch e
answer "An error occurred while connecting to the database:" && e
end try
SQL Yoga USER GUIDE
- Home
- SQL Yoga Objects
- Database Objects
- Connection Objects
- SQL Query Objects
- SQL Record Objects
- Table Objects
- Table Object Behaviors
- Relationships
- Scopes
- Schema
- Working with User Search Strings
- SQL Query Template Objects
- Error Handling
- Migrating from SQL Yoga 1.x
- Integrating with the Levure Application Framework