Libraries.Data.Database.Connection Documentation
The Connection class stores information needed to create a connection to a database. The database class has actions where the information stored here will be used to establish a connection and make it possible to query the database.
Example Code
use Libraries.Data.Database.Database
use Libraries.Data.Database.Connection
Database db
Connection connection
connection:SetUsername("root")
connection:SetPassword("secret")
connection:SetLocation("localhost")
connection:SetPort(3306)
connection:SetDatabase("myDB")
db:Connect(connection)
Inherits from: Libraries.Language.Object
Actions Documentation
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
GetDatabase()
This action returns the name of database set for this connection.
Return
text: Returns the set location for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetDatabase("myDB")
output connection:GetDatabase()
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetLocation()
This action returns the location set for this connection. The location would be the name of the server that is running the database. For example, "localhost" would be a common location when the database server is running on the same machine that will be running the queries.
Return
text: Returns the set location for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetLocation("secret")
output connection:GetLocation()
GetPassword()
This action returns the password set for this connection.
Return
text: Returns the set password for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetPassword("secret")
output connection:GetPassword()
GetPort()
This action returns the port used to make a connection. By default the port will be set to 3306.
Return
integer: Returns the set port for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
output connection:GetPort()
GetUsername()
This action returns the username set for this connection
Return
text: Returns the set username for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetUsername("root")
output connection:GetUsername()
SetDatabase(text database)
This action sets name of the database to connect to.
Parameters
- text database: The name of the database to connect to
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetDatabase("myDB")
SetLocation(text location)
This action sets the location for this connection. The location would be the name of the server that is running the database. For example, "localhost" would be a common location when the database server is running on the same machine that will be running the queries.
Parameters
- text location: The location to set for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetLocation("localhost")
SetPassword(text password)
This action sets the password for this connection. Remember that password that would be set will be in plain text so if the password is not meant to be seen on others make sure to not expose that if sharing code.
Parameters
- text password: The password to set for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetPassword("secret")
SetPort(integer port)
This action sets the port for the database connection. By default the port is set to 3306 since that is the default port for MySQL servers.
Parameters
- integer port: The port to set for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetPort(3306)
SetUsername(text username)
This action sets the username for this connection
Parameters
- text username: The username to set for this connection
Example
use Libraries.Data.Database.Connection
Connection connection
connection:SetUsername("root")