Libraries.Data.Database.Update Documentation

The Update query represents the Update command of the SQL (Structured Query Language) language. This query allows for the modification of a record that already exists in the database.

Example Code

use Libraries.Data.Database.Database
use Libraries.Data.Database.Update

Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")

Update query
query:SetTable("orders")
query:Add("status", "Shipped")
query:Add("comments", "Express shipping")

database:Update(query)

Inherits from: Libraries.Language.Object, Libraries.Data.Database.Query, Libraries.Data.Database.Support.RemappableName

Summary

Actions Summary Table

ActionsDescription
Add(text column, number value)This action is used to add which column will be modified and what value it will be set to.
Add(text column, text value)This action is used to add which column will be modified and what value it will be set to.
Add(text column, Libraries.Compute.BigInteger value)This action is used to add which column will be modified and what value it will be set to.
Add(text column, integer value)This action is used to add which column will be modified and what value it will be set to.
AddExpression(text column, text value)This action is used to add which column will be modified and what value it will be set to using an expression.
AddNameRemap(text newName, Libraries.Data.Database.Support.RemappableName original)Adds objects that have been remapped to single table for reference in actions called when building the query to text.
AddPreparedParameter(Libraries.Data.Database.Support.Parameter param)At the plugin level prepared statements are used to add a layer of security from injection attacks.
AddSubquery(text name, Libraries.Data.Database.Find subquery)Adds a subquery to this query.
AddTableNameRemap(text table, text newName)This adds a name that can be used in the place of a table.
AddTableReference(text table)Internal.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
ConvertToStructuredQueryLanguage()This action returns the query as text in Structured Query Language (SQL).
Empty()Removes all columns and values associated with them from the query.
EmptyPreparedParameters()Clears the prepared parameter list.
EmptyTableReferences()Empties the table references hash table.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Filter(text value)Some queries make use of the filter which is an expression checked against the values of the columns in the rows of a database table.
GetDatabaseMetaData()Returns the meta data object set for this query
GetHashCode()This action gets the hash code for an object.
GetNameRemaps()Grabs the table containing all aliases that have been set in this query
GetPreparedParameters()Used at the plugin level to get all parameters that need to be set in the prepared statement
GetRawFilter()Returns the filter as given by the user.
GetRemappedName()Returns the alias
GetTable()Returns the table this query is meant to be ran against
GetTableReferences()Internal.
GetTranslatedFilter()Returns the filter as translated by the quorum compiler.
HasColumn(text name)This action checks if the update query has a specific column in the set list.
RemoveColumn(text name)This action removes a specific column.
SetDatabaseMetaData(Libraries.Data.Database.DatabaseMetaData meta)Sets the DatabaseMetaData for this query.
SetIsFiltering(boolean filtering)If this flag is set to false then the query will be allowed to run with no filter which updates all rows in the table.
SetRemappedName(text remappedName)Sets the alias
SetTable(text table)This action sets the table of the query.
SetTable(text table, text newName)This action sets the table of the query.
SetTableWithName(text table, text newName)This action sets the table of the query.
ToText()By default convert to structured query language.
UsingFilter()This action returns whether or not this Update query will use a filter.

Actions Documentation

Add(text column, number value)

This action is used to add which column will be modified and what value it will be set to.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("products")
        query:Add("MSRP", 9.99)

Parameters

Add(text column, text value)

This action is used to add which column will be modified and what value it will be set to.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("products")
        query:Add("productName", "The Moon")

Parameters

Add(text column, Libraries.Compute.BigInteger value)

This action is used to add which column will be modified and what value it will be set to.

Example Code

use Libraries.Data.Database.Update
        use Libraries.Compute.BigInteger
        
        text value = "2147483648"
        BigInteger largeNumber
        largeNumber:SetValue(value)

        Update query
        query:SetTable("distances")
        query:Add("distance_in_mm", largeNumber)

Parameters

Add(text column, integer value)

This action is used to add which column will be modified and what value it will be set to.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("orders")
        query:Add("customerNumber", 42)

Parameters

AddExpression(text column, text value)

This action is used to add which column will be modified and what value it will be set to using an expression. Since the value is an expression it will be parsed and can use column names within it.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("products")
        query:AddExpression("MSRP", "MSRP + 0.10")

Parameters

AddNameRemap(text newName, Libraries.Data.Database.Support.RemappableName original)

Adds objects that have been remapped to single table for reference in actions called when building the query to text. Examples of RemappableNames are columns, tables, and subqueries.

Parameters

AddPreparedParameter(Libraries.Data.Database.Support.Parameter param)

At the plugin level prepared statements are used to add a layer of security from injection attacks. Every parameter in the prepared paramter array will be stripped from the actual query text and set appropriately at the plugin level.

Parameters

AddSubquery(text name, Libraries.Data.Database.Find subquery)

Adds a subquery to this query. Only Find queries are supported for now. A Subquery is a query that exists another outer query. An example could be a Find where the table to search through is actually the result of another query.

Parameters

AddTableNameRemap(text table, text newName)

This adds a name that can be used in the place of a table. This action does not set the table of this query but only a name that can be referenced if the table is added.

Example Code

use Libraries.Data.Database.Find

        Find query
        query:SetTable("orders", "o")
        query:AddTableNameRemap("members", "m")
        query:AddInnerJoin("m", "o:name = m:name")

Parameters

AddTableReference(text table)

Internal. Queries keep track of what tables are referenced to check for ambiguous column names

Parameters

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.

ConvertToStructuredQueryLanguage()

This action returns the query as text in Structured Query Language (SQL). Not intended to be used directly by the user, this is more for internals of the API to make calls to the database

Return

text:

Empty()

Removes all columns and values associated with them from the query.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("orders")
        query:Add("status", "Shipped")
        query:Add("comments", "Express shipping")

        query:Empty()

EmptyPreparedParameters()

Clears the prepared parameter list. Necessary because running a query again without emptying the list will cause the list of parameters to not shrink

EmptyTableReferences()

Empties the table references hash table.

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.

Filter(text value)

Some queries make use of the filter which is an expression checked against the values of the columns in the rows of a database table. The filter is written using Quorum syntax and will be type checked to see if it's valid. Column names can be used and the names made by the user using name remaps. An example filter would be "priority < 4" where priority is a column that exists and can be mapped to an integer.

Example Code

use Libraries.Data.Database.Delete

        Delete query
        query:SetTable("orders")
        query:Filter("priority < 4")

Parameters

GetDatabaseMetaData()

Returns the meta data object set for this query

Return

Libraries.Data.Database.DatabaseMetaData:

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.

GetNameRemaps()

Grabs the table containing all aliases that have been set in this query

Return

Libraries.Containers.HashTable:

GetPreparedParameters()

Used at the plugin level to get all parameters that need to be set in the prepared statement

Return

Libraries.Containers.Array:

GetRawFilter()

Returns the filter as given by the user. The filter will be converted to a syntax accepted by the database server and this action returns whatever the user originally typed

Return

text:

GetRemappedName()

Returns the alias

Return

text:

GetTable()

Returns the table this query is meant to be ran against

Return

text:

GetTableReferences()

Internal. Used by other actions to grab what tables are referenced to check if column names are valid.

Return

Libraries.Containers.HashTable:

GetTranslatedFilter()

Returns the filter as translated by the quorum compiler. The filter will be converted to a syntax accepted by the database server and this action returns whatever the user originally typed

Return

text:

HasColumn(text name)

This action checks if the update query has a specific column in the set list.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("orders")
        query:Add("status", "Shipped")
        query:Add("comments", "Express shipping")
        
        boolean statusChange = query:HasColumn("status")

Parameters

Return

boolean: Returns true if the column was found, false otherwise

RemoveColumn(text name)

This action removes a specific column.

Example Code

use Libraries.Data.Database.Update

        Update query
        query:SetTable("orders")
        query:Add("status", "Shipped")
        query:Add("comments", "Express shipping")

        query:RemoveColumn("comments")

Parameters

Return

boolean: Returns true if the column was removed, false otherwise

SetDatabaseMetaData(Libraries.Data.Database.DatabaseMetaData meta)

Sets the DatabaseMetaData for this query. This is necessary for checking things like if a table referenced exists or if a filter has valid column references.

Parameters

SetIsFiltering(boolean filtering)

If this flag is set to false then the query will be allowed to run with no filter which updates all rows in the table.

Example Code

use Libraries.Data.Database.Update
        
        Update query
        query:SetTable("tasks")
        query:Add("status", "Delayed")
        
        query:SetIsFiltering(true)

Parameters

SetRemappedName(text remappedName)

Sets the alias

Parameters

SetTable(text table)

This action sets the table of the query. Most queries run against a single table and this action is used to set which table the query will affect or search.

Example Code

use Libraries.Data.Database.Find

        Find query
        query:SetTable("members")

Parameters

SetTable(text table, text newName)

This action sets the table of the query. Most queries run against a single table and this action is used to set which table the query will affect or search. This action also lets you rename the table so in filters a different name can be used.

Example Code

use Libraries.Data.Database.Find

        Find query
        query:SetTable("members", "m")

Parameters

SetTableWithName(text table, text newName)

This action sets the table of the query. Most queries run against a single table and this action is used to set which table the query will affect or search. This action also lets you rename the table so in filters a different name can be used.

Example Code

use Libraries.Data.Database.Find

        Find query
        query:SetTableWithName("members", "m")

Parameters

ToText()

By default convert to structured query language.

Return

text:

UsingFilter()

This action returns whether or not this Update query will use a filter.

Example Code

use Libraries.Data.Database.Update

        Delete query
        query:SetTable("tasks")
        query:Add("status", "Delayed")
        query:SetIsFiltering(false)

        boolean filtering = query:UsingFilter()

Return

boolean: Returns true if not using a filter and false if it will