Update

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

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)

Actions

Add(text column, number value)

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

Parameters

  • column text: The name of the column that will be updated
  • value number: The value the column will be updated with

Example

use Libraries.Data.Database.Update

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

Add(text column, text value)

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

Parameters

  • column text: The name of the column that will be updated
  • value text: The value the column will be updated with

Example

use Libraries.Data.Database.Update

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

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.

Parameters

Example

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)

Add(text column, integer value)

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

Parameters

  • column text: The name of the column that will be updated
  • value integer: The value the column will be updated with

Example

use Libraries.Data.Database.Update

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

Add(text column, boolean value)

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

Parameters

  • column text: The name of the column that will be updated
  • value boolean: The value the column will be updated with

Example

use Libraries.Data.Database.Update

Update query
query:SetTable("orders")
query:Add("shipped", true)

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.

Parameters

  • column text: The name of the column that will be updated
  • value text: The expression the column will be updated with

Example

use Libraries.Data.Database.Update

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

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

Returns

text

Empty()

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

Example

use Libraries.Data.Database.Update

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

query:Empty()

HasColumn(text name)

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

Parameters

  • name text: The name of the column to search for

Returns

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

Example

use Libraries.Data.Database.Update

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

boolean statusChange = query:HasColumn("status")

RemoveColumn(text name)

This action removes a specific column.

Parameters

  • name text: The name of the column that will be removed

Returns

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

Example

use Libraries.Data.Database.Update

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

query:RemoveColumn("comments")

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.

Parameters

  • filtering boolean: If true this query will not use a filter for updating rows

Example


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

UsingFilter()

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

Returns

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

Example

use Libraries.Data.Database.Update

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

boolean filtering = query:UsingFilter()

Inherited Actions

20 actions from Libraries.Data.Database.Query
2 actions from Libraries.Data.Database.Support.RemappableName
3 actions from Libraries.Language.Object