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

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetDatabase()This action returns the name of database set for this connection.
GetHashCode()This action gets the hash code for an object.
GetLocation()This action returns the location set for this connection.
GetPassword()This action returns the password set for this connection.
GetPort()This action returns the port used to make a connection.
GetUsername()This action returns the username set for this connection
SetDatabase(text database)This action sets name of the database to connect to.
SetLocation(text location)This action sets the location for this connection.
SetPassword(text password)This action sets the password for this connection.
SetPort(integer port)This action sets the port for the database connection.
SetUsername(text username)This action sets the username for this connection

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.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetDatabase()

This action returns the name of database set for this connection.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetDatabase("myDB")

    output connection:GetDatabase()

Return

text: Returns the set location for this connection

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

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.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetLocation("secret")

    output connection:GetLocation()

Return

text: Returns the set location for this connection

GetPassword()

This action returns the password set for this connection.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetPassword("secret")

    output connection:GetPassword()

Return

text: Returns the set password for this connection

GetPort()

This action returns the port used to make a connection. By default the port will be set to 3306.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    output connection:GetPort()

Return

integer: Returns the set port for this connection

GetUsername()

This action returns the username set for this connection

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetUsername("root")

    output connection:GetUsername()

Return

text: Returns the set username for this connection

SetDatabase(text database)

This action sets name of the database to connect to.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetDatabase("myDB")

Parameters

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.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetLocation("localhost")

Parameters

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.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetPassword("secret")

Parameters

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.

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetPort(3306)

Parameters

SetUsername(text username)

This action sets the username for this connection

Example Code

use Libraries.Data.Database.Connection

    Connection connection
    connection:SetUsername("root")

Parameters