pandemonium_engine/modules/database/doc_classes/QueryBuilder.xml

703 lines
20 KiB
XML
Raw Normal View History

2022-08-21 00:40:49 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2023-01-14 13:38:58 +01:00
<class name="QueryBuilder" inherits="Reference" version="3.11">
2022-08-21 00:40:49 +02:00
<brief_description>
2022-12-27 18:20:15 +01:00
A class that helps you with building and running database backend specific sql safely.
2022-08-21 00:40:49 +02:00
</brief_description>
<description>
2022-12-27 18:20:15 +01:00
A class that helps you with building and running database backend specific sql safely.
Methods by default use escape on their parameters that can normally contain user input. For performance reasons other variants that don't do this also exist. These are prefixed with 'n'. For example [method select] vs [method nselect]. Don't use these with raw user input, as it will make your application vulnerable to sql injection attacks.
It contains helper methods that lets you run the finished query directly See [method run] and [method run_query].
You should not allocate this directly, instead get it from you active database connection, like:
[codeblock]
var conn : DatabaseConnection = DatabaseManager.ddb.get_connection()
var qb : QueryBuilder = conn.get_query_builder()
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
<tutorials>
</tutorials>
<methods>
<method name="asc">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
if (col.empty()):
result += "ASC, "
else:
result += col + " ASC, "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="begin_transaction">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "BEGIN TRANSACTION;"
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="commit">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "COMMIT;"
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="corder_by">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Closes the current [code]ORDER BY[/code] statement. (Usually by removing the last [code],[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="cset">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Closes the current [code]SET[/code] statement. (Usually by removing the last [code],[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="cstr">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Closes the current string. (Usually by adding a [code]'[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="cvalues">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Closes the current [code]VALUES[/code] statement. (Usually by replacing the last [code],[/code] with a [code])[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="del">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "DELETE FROM " + escape(params) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="desc">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
if (col.empty()):
result += "DESC, "
else:
result += col + " DESC, "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="end_command">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Closes the current sql command. (Usually by adding a [code];[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="escape">
<return type="String" />
<argument index="0" name="param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Escapes the given string and returns it. (Using the database connector's escape method.)
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="ew">
<return type="QueryBuilder" />
<argument index="0" name="str" type="String" />
<description>
2022-12-27 18:20:15 +01:00
(ew = escape write)
Equivalent to:
[codeblock]
result += escape(str)
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="from">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "FROM "
if (!params.empty()):
result += escape(params)
result += " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="insert">
<return type="QueryBuilder" />
<argument index="0" name="table_name" type="String" default="&quot;&quot;" />
2022-12-22 19:51:25 +01:00
<argument index="1" name="columns" type="String" default="&quot;&quot;" />
2022-08-21 00:40:49 +02:00
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "INSERT INTO ";
if (!table_name.empty()):
result += table_name
result += " "
if (!columns.empty()):
result += "("
result += columns
result += ") "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="land">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
(land = logical and)
Equivalent to:
[codeblock]
result += "AND "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="like">
<return type="QueryBuilder" />
<argument index="0" name="str" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
if (str.empty()):
result += "LIKE "
else:
result += "LIKE '" + escape(str) + "' "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="limit">
<return type="QueryBuilder" />
<argument index="0" name="num" type="int" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "LIMIT " + itos(num) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="lor">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
(lor = logical or)
Equivalent to:
[codeblock]
result += "OR "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="ndel">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "DELETE FROM " + params + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="next_value">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Closes the current [code]VALUES[/code] statement, and then open an another one. (Usually by replacing the last [code],[/code] with [code]"), ("[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nfrom">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "FROM "
if (!params.empty()):
result += params + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nl">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Adds a newline. This can help when debugging sql statements. (Usually [code]\n[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nlike">
<return type="QueryBuilder" />
<argument index="0" name="str" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "LIKE '" + str + "' "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nselect">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Equivalent to:
[codeblock]
result += "SELECT " + params + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nsetp">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="escape_param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Add parameters to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col + "='" + params + "', "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nupdate">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Start an [code]UPDATE[/code] statement.
Equivalent to:
[codeblock]
result += "UPDATE " + params + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nval">
<return type="QueryBuilder" />
<argument index="0" name="param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Add parameters to [code]INSERT INTO[/code] statements.
Equivalent to:
[codeblock]
result += "'" + param + "', "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nvalues">
<return type="QueryBuilder" />
<argument index="0" name="params_str" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Adds an unescaped [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += "VALUES("
if (!params_str.empty()):
result += params_str + ") "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nwhere">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Adds an unescaped [code]WHERE[/code] statement.
Equivalent to:
[codeblock]
result += "WHERE "
if (!params.empty()):
result += params + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="nwp">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="escape_param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Add an unescaped parameter to [code]WHERE[/code] statements.
Equivalent to:
[codeblock]
result += col + "='" + params + "' "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="offset">
<return type="QueryBuilder" />
<argument index="0" name="num" type="int" />
<description>
2022-12-27 18:20:15 +01:00
Adds an [code]OFFSET[/code] statement.
Equivalent to:
[codeblock]
result += "OFFSET " + str(num) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="order_by">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Adds an [code]ORDER BY[/code] statement.
Equivalent to:
[codeblock]
if (col.empty()):
result += "ORDER BY "
else:
result += "ORDER BY " + col + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="order_by_add_col">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Adds a column to an [code]ORDER BY[/code] statement.
Equivalent to:
[codeblock]
result += col + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="order_by_asc">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Adds an [code]ORDER BY ASC[/code] statement.
Equivalent to:
[codeblock]
result += "ORDER BY " + col + " ASC, ";
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="order_by_desc">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Adds an [code]ORDER BY DESC[/code] statement.
Equivalent to:
[codeblock]
result += "ORDER BY " + col + " DESC, ";
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="prepare">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Part of the unfinished prepared statement api.
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="reset">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Resets the QueryBuilder.
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="run">
<return type="QueryResult" />
<description>
2022-12-27 18:20:15 +01:00
Run the query currently stored in the result property.
Use this if your query returns values from the database (an you want to read them).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="run_query">
<return type="void" />
<description>
2022-12-27 18:20:15 +01:00
Run the query currently stored in the result property.
Use this if your query doesn't return values from the database (or you don't want to read them if it does).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="select">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Adds a [code]SELECT[/code] statement.
Equivalent to:
[codeblock]
result += SELECT " + escape(params) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="select_last_insert_id">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Adds a statement to select and return the last inserted row's id.
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="set_paramf">
<return type="QueryBuilder" />
<argument index="0" name="index" type="int" />
<argument index="1" name="value" type="float" />
<description>
2022-12-27 18:20:15 +01:00
Part of the unfinished prepared statement api.
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="set_parami">
<return type="QueryBuilder" />
<argument index="0" name="index" type="int" />
<argument index="1" name="value" type="int" />
<description>
2022-12-27 18:20:15 +01:00
Part of the unfinished prepared statement api.
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="set_params">
<return type="QueryBuilder" />
<argument index="0" name="index" type="int" />
<argument index="1" name="value" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Part of the unfinished prepared statement api.
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="setpb">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="bool" />
<description>
2022-12-27 18:20:15 +01:00
Add a bool parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
if (param):
result += col + "=1, "
else:
result += col + "=0, "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="setpd">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="float" />
<description>
2022-12-27 18:20:15 +01:00
Add a double parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col + "=" + str(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="setpf">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="float" />
<description>
2022-12-27 18:20:15 +01:00
Add a float parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col + "=" + str(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="setpi">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="int" />
<description>
2022-12-27 18:20:15 +01:00
Add an int parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col + "=" + str(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="setps">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Add an escaped string parameter to [code]UPDATE[/code] statements.
Equivalent to:
[codeblock]
result += col + "=" + escape(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="sets">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Starts a [code]SET[/code] statement.
Equivalent to:
[codeblock]
result += "SET "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="str">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Starts a string. (Usually by adding a [code]'[/code]).
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="update">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Starts an [code]UPDATE[/code] statement.
Equivalent to:
[codeblock]
result += "UPDATE " + escape(params) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="val">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Adds [code]DEFAULT[/code] to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += "DEFAULT, "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="valb">
<return type="QueryBuilder" />
<argument index="0" name="param" type="bool" />
<description>
2022-12-27 18:20:15 +01:00
Add a bool parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
if (param):
result += "1, "
else:
result += "0, "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="vald">
<return type="QueryBuilder" />
<argument index="0" name="param" type="float" />
<description>
2022-12-27 18:20:15 +01:00
Add a double parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += str(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="valf">
<return type="QueryBuilder" />
<argument index="0" name="param" type="float" />
<description>
2022-12-27 18:20:15 +01:00
Add a float parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += str(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="vali">
<return type="QueryBuilder" />
<argument index="0" name="param" type="int" />
<description>
2022-12-27 18:20:15 +01:00
Add an int parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += str(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="vals">
<return type="QueryBuilder" />
<argument index="0" name="param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Add an escaped string parameter to a [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += escape(param) + ", "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="values">
<return type="QueryBuilder" />
<argument index="0" name="params_str" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Adds an escaped [code]VALUES[/code] statement.
Equivalent to:
[codeblock]
result += "VALUES("
if (!params_str.empty()):
result += escape(params_str) + ") "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="w">
<return type="QueryBuilder" />
<argument index="0" name="str" type="String" />
<description>
2022-12-27 18:20:15 +01:00
(w = write)
Equivalent to:
[codeblock]
result += str
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="where">
<return type="QueryBuilder" />
<argument index="0" name="params" type="String" default="&quot;&quot;" />
<description>
2022-12-27 18:20:15 +01:00
Adds an escaped [code]WHERE[/code] statement.
Equivalent to:
[codeblock]
result += "WHERE "
if (!params.empty()):
result += escape(params) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="wildcard">
<return type="QueryBuilder" />
<description>
2022-12-27 18:20:15 +01:00
Gets the wildcard character for the given database backend. (Usually [code]%[/code].)
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="wpb">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="bool" />
<description>
2022-12-27 18:20:15 +01:00
Add a bool parameter to a [code]WHERE[/code] statement. (wpb = where param bool)
Equivalent to:
[codeblock]
if (param):
result += col + "=1 "
else:
result += col + "=0 "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="wpi">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="int" />
<description>
2022-12-27 18:20:15 +01:00
Add an int parameter to a [code]WHERE[/code] statement. (wpi = where param int)
Equivalent to:
[codeblock]
result += col + "=" + str(param) + " "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
<method name="wps">
<return type="QueryBuilder" />
<argument index="0" name="col" type="String" />
<argument index="1" name="param" type="String" />
<description>
2022-12-27 18:20:15 +01:00
Add an escaped string parameter to a [code]WHERE[/code] statement. (wps = where param string)
Equivalent to:
[codeblock]
result += col + "='" + escape(param) + "' "
[/codeblock]
2022-08-21 00:40:49 +02:00
</description>
</method>
</methods>
<members>
<member name="result" type="String" setter="set_result" getter="get_result" default="&quot;&quot;">
2022-12-27 18:20:15 +01:00
The current (resulting) sql statement.
2022-08-21 00:40:49 +02:00
</member>
</members>
<constants>
</constants>
</class>