Libraries.Data.Database.CreateView Documentation
The CreateView class is a query that allows creating a table that lives on the database composed of the results of a Find query. Once the view is created it can be accessed as if it was another database table. Although you can not insert, update, or delete from a view.
Example Code
use Libraries.Data.Database.Database
use Libraries.Data.Database.CreateView
use Libraries.Data.Database.Find
Database database
database:Connect("localhost", "myDatabase", "user", "SuperSecret456")
CreateView view
Find oneColumn
oneColumn:AddColumn("employeeNumber")
oneColumn:SetTable("employees")
CreateView view
view:SetName("employNum")
view:SetQuery(oneColumn)
database:CreateView(view)
Inherits from: Libraries.Language.Object, Libraries.Data.Database.Query, Libraries.Data.Database.Support.RemappableName
Actions Documentation
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
- text newName
- Libraries.Data.Database.Support.RemappableName
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
- text name
- Libraries.Data.Database.Find
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
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)
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:
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
- 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)
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()
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()
GetName()
This action is used to return the name of the view set for this query.
Return
text: The name that will be given to the view
Example
use Libraries.Data.Database.CreateView
CreateView query
query:SetName("my_view")
text name = query:GetName()
GetNameRemaps()
Grabs the table containing all aliases that have been set in this query
Return
GetPreparedParameters()
Used at the plugin level to get all parameters that need to be set in the prepared statement
Return
GetQuery()
This action returns the Find query the view will use.
Return
Libraries.Data.Database.Find: The Find query that will be used to make up the view
Example
use Libraries.Data.Database.CreateView
use Libraries.Data.Database.Find
Find query
query:SetTable("employees")
CreateView view
view:SetName("employ_view")
view:SetQuery(query)
Find viewQuery = view:GetQuery()
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
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:
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
SetName(text name)
This action is used to set the name of the view. This name will appear in the database.
Parameters
- text name: The name to give to the view
Example
use Libraries.Data.Database.CreateView
CreateView query
query:SetName("my_view")
SetQuery(Libraries.Data.Database.Find query)
This action is used to set the Find query of the view. The result that would be returned by the find query will make up the rows of the view.
Parameters
- Libraries.Data.Database.Find: The Find query where the result of the query will make up the rows of the view
Example
use Libraries.Data.Database.CreateView
use Libraries.Data.Database.Find
Find query
query:SetTable("employees")
CreateView view
view:SetName("employ_view")
view:SetQuery(query)
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 is used to set which table the query will affect or search.
Parameters
- text table: The name of the table to set for this query
Example
use Libraries.Data.Database.Find
Find query
query:SetTable("members")
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.
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("members", "m")
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.
Parameters
- text table: The name of the table to set for this query
- text newName
Example
use Libraries.Data.Database.Find
Find query
query:SetTableWithName("members", "m")
ToText()
By default convert to structured query language.
Return
text:
On this page
Variables TableAction Documentation- AddNameRemap(text newName, Libraries.Data.Database.Support.RemappableName original)
- AddPreparedParameter(Libraries.Data.Database.Support.Parameter param)
- AddSubquery(text name, Libraries.Data.Database.Find subquery)
- AddTableNameRemap(text table, text newName)
- AddTableReference(text table)
- Compare(Libraries.Language.Object object)
- ConvertToStructuredQueryLanguage()
- EmptyPreparedParameters()
- EmptyTableReferences()
- Equals(Libraries.Language.Object object)
- Filter(text value)
- GetDatabaseMetaData()
- GetHashCode()
- GetName()
- GetNameRemaps()
- GetPreparedParameters()
- GetQuery()
- GetRawFilter()
- GetRemappedName()
- GetTable()
- GetTableReferences()
- GetTranslatedFilter()
- SetDatabaseMetaData(Libraries.Data.Database.DatabaseMetaData meta)
- SetName(text name)
- SetQuery(Libraries.Data.Database.Find query)
- SetRemappedName(text remappedName)
- SetTable(text table)
- SetTable(text table, text newName)
- SetTableWithName(text table, text newName)
- ToText()