Libraries.Data.Database.CreateTable Documentation

The CreateTable class is a query make a new table on a database. To create a table you need to give it a name using SetTable and then the table needs at least one column.

Example Code

use Libraries.Data.Database.CreateTable

CreateTable table
table:SetTable("Users")
table:AddIntegerColumn("id")

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

Actions Documentation

AddBooleanColumn(text name)

This action adds a 32 bit integer column to the table.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddIntegerColumn("id")

AddDateColumn(text name)

This action adds a Date column to the table. Similar to a DateTime column but stores no time portion.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddDateColumn("birthday")

AddDateTimeColumn(text name, boolean autoInitialize)

This action adds a DateTime column to the table. A datetime column can also be set that when a new record is inserted or updated the datetime column will be set to the current time removing the need for the user to find and set the time.

Parameters

  • text name: the name of the column
  • boolean autoInitialize: if true this will make a datetime column that on insert will automatically be a timestamp of the current time

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddDateTimeColumn("start_date", true)

AddDateTimeColumn(text name)

This action adds a DateTime column to the table.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddDateTimeColumn("start_date")

AddDefaultConstriant(text name, boolean default)

Parameters

  • text name
  • boolean default

AddDefaultConstriant(text name, number default)

This action adds a text column to the table. If the value is less than 0, this throws an error. If the value is greater than 0 and less than 65,535, a VARCHAR is created on the database. If the value is greater than this, a LONGTEXT is created, which has a maximum value of 4,294,967,295. If the version of this action is called with fixed = true, then the integer can have a maximum size of 255 characters and the text is always of fixed length.

Parameters

  • text name: the name of the column
  • number default

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTextColumn("LastName", 400)

AddDefaultConstriant(text name, text default)

This action adds a DateTime column to the table.

Parameters

  • text name: the name of the column
  • text default

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddDateTimeColumn("start_date")

AddDefaultConstriant(text name, integer default)

This action adds a text column to the table. This column can hold a string with a maximum length of 65,535 characters.

Parameters

  • text name: the name of the column
  • integer default

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTextColumn("description")

AddDefaultNullConstriant(text name)

This action adds a text column to the table. If the value is less than 0, this throws an error. If the value is greater than 0 and less than 65,535, a VARCHAR is created on the database. If the value is greater than this, a LONGTEXT is created, which has a maximum value of 4,294,967,295. If the version of this action is called with fixed = true, then the integer can have a maximum size of 255 characters and the text is always of fixed length.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTextColumn("LastName", 255, true)

AddForeignKey(text name, text reference)

This action adds a DateTime column to the table. A datetime column can also be set that when a new record is inserted or updated the datetime column will be set to the current time removing the need for the user to find and set the time.

Parameters

  • text name: the name of the column
  • text reference

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddDateTimeColumn("start_date", true)

AddIntegerColumn(text name, boolean autoIncrement)

This action adds a 32 bit integer column to the table and allows for specifiying if this column automatically increments by 1 on each insertion. An auto increment column does not need to be set when doing an insert, usually this is reserved for an 'id' column where the number does not matter but each record needs a integer id.

Parameters

  • text name: the name of the column
  • boolean autoIncrement: sets whether or not this integer column automatically increments on insertion

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddIntegerColumn("id")

AddIntegerColumn(text name)

This action adds a 32 bit integer column to the table.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddIntegerColumn("id")

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

AddNotNullConstraint(text name)

This action adds a Date column to the table. Similar to a DateTime column but stores no time portion.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddDateColumn("birthday")

AddNumberColumn(text name)

This action adds a 32 bit integer column to the table and allows for specifiying if this column automatically increments by 1 on each insertion. An auto increment column does not need to be set when doing an insert, usually this is reserved for an 'id' column where the number does not matter but each record needs a integer id.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddIntegerColumn("id")

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.

Parameters

  • text table: The name of the table to set for this query
  • text newName

Example

use Libraries.Data.Database.Find

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

AddTableReference(text table)

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

Parameters

  • text table

AddTextColumn(text name, integer size)

This action adds a text column to the table. If the value is less than 0, this throws an error. If the value is greater than 0 and less than 65,535, a VARCHAR is created on the database. If the value is greater than this, a LONGTEXT is created, which has a maximum value of 4,294,967,295. If the version of this action is called with fixed = true, then the integer can have a maximum size of 255 characters and the text is always of fixed length.

Parameters

  • text name: the name of the column
  • integer size: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTextColumn("LastName", 400)

AddTextColumn(text name, integer size, boolean fixed)

This action adds a text column to the table. If the value is less than 0, this throws an error. If the value is greater than 0 and less than 65,535, a VARCHAR is created on the database. If the value is greater than this, a LONGTEXT is created, which has a maximum value of 4,294,967,295. If the version of this action is called with fixed = true, then the integer can have a maximum size of 255 characters and the text is always of fixed length.

Parameters

  • text name: the name of the column
  • integer size: the name of the column
  • boolean fixed

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTextColumn("LastName", 255, true)

AddTextColumn(text name)

This action adds a text column to the table. This column can hold a string with a maximum length of 65,535 characters.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTextColumn("description")

AddTimestampColumn(text name)

This action adds a Timestamp column to the table. A timestamp column is very similar to a DateTime column in that the values make look the same but the range of a timestamp is smaller and on a database a timestamp will be converted and stored as UTC rather than the system timezone. When retrieving timestamps they will be converted back to the system timezone.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTimestampColumn("last_modified")

AddTimestampColumn(text name, boolean autoInitialize)

This action adds a Timestamp column to the table. A timestamp column is very similar to a DateTime column in that the values make look the same but the range of a timestamp is smaller and on a database a timestamp will be converted and stored as UTC rather than the system timezone. When retrieving timestamps they will be converted back to the system timezone. A timestamp column can also be set that when a new record is inserted or updated the timestamp column will be set to the current time removing the need for the user to find and set the time.

Parameters

  • text name: the name of the column
  • boolean autoInitialize: if true this will make a timestamp column that on insert will automatically be a timestamp of the current time

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTimestampColumn("last_modified", true)

AddUniqueConstraint(text name)

This action adds a Timestamp column to the table. A timestamp column is very similar to a DateTime column in that the values make look the same but the range of a timestamp is smaller and on a database a timestamp will be converted and stored as UTC rather than the system timezone. When retrieving timestamps they will be converted back to the system timezone. A timestamp column can also be set that when a new record is inserted or updated the timestamp column will be set to the current time removing the need for the user to find and set the time.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTimestampColumn("last_modified", true)

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

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)

ConvertToStructuredQueryLanguage()

No matter the data type, this action removes the previously added column from the create query.

Return

text:

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:RemoveColumn("LastName")

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.

Parameters

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)

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.

Parameters

  • text value: The expression to be used in the query

Example

use Libraries.Data.Database.Delete

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

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.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

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:

RemoveColumn(text name)

No matter the data type, this action removes the previously added column from the create query.

Parameters

  • text name: the name of the column

Return

text:

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:RemoveColumn("LastName")

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

SetPrimaryKey(text name)

This action adds a Timestamp column to the table. A timestamp column is very similar to a DateTime column in that the values make look the same but the range of a timestamp is smaller and on a database a timestamp will be converted and stored as UTC rather than the system timezone. When retrieving timestamps they will be converted back to the system timezone.

Parameters

  • text name: the name of the column

Example

use Libraries.Data.Database.CreateTable

CreateTable mine
mine:AddTimestampColumn("last_modified")

SetRemappedName(text remappedName)

Sets the alias

Parameters

  • text remappedName

SetTable(text table)

This action sets the table of the query. Most queries run against a single table and this action