en:code:data:sql
Differences
This shows you the differences between two versions of the page.
| Previous revision | |||
| — | en:code:data:sql [2021/02/13 11:23] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Sql ====== | ||
| + | This object allows you to establish a connection to a SQL database like MySQL, PostgreSQL, SQLite and others. | ||
| + | ===== Functions ===== | ||
| + | |||
| + | ==== Sql ==== | ||
| + | Constructor function. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | var myObject = new Sql(driver); | ||
| + | </ | ||
| + | |||
| + | === Arguments === | ||
| + | - driver - ([[# | ||
| + | |||
| + | === Exceptions === | ||
| + | * (NoDatabaseDriverError) no database driver specified | ||
| + | |||
| + | === Example === | ||
| + | Create a Sql object operating on a MySQL database. | ||
| + | <code javascript> | ||
| + | var myObject = new Sql(Sql.MySQL); | ||
| + | </ | ||
| + | |||
| + | === Notes === | ||
| + | On Windows only the MySQL, PostgreSQL, SQLite 3, Firebird and ODBC drivers are installed by default. | ||
| + | To see all available drivers call the [[# | ||
| + | |||
| + | ==== drivers ==== | ||
| + | Returns a list of available Drivers. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | Sql.drivers(); | ||
| + | </ | ||
| + | |||
| + | ===== Methods ===== | ||
| + | |||
| + | ==== connect ==== | ||
| + | Opens a connection with a database. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | myObject.connect(parameters); | ||
| + | </ | ||
| + | |||
| + | === Arguments === | ||
| + | - parameters - (object) the connection parameters | ||
| + | * hostName - (string) the host name | ||
| + | * port - (integer) the port to use (use the default port if not specified) | ||
| + | * databaseName - (string) the database name (when using SQLite this is the filename of the database) | ||
| + | * userName - (string) the user name | ||
| + | * password - (string) the password | ||
| + | * options - (string) connection options (see [[http:// | ||
| + | |||
| + | === Returns === | ||
| + | * (Sql) this Sql | ||
| + | |||
| + | === Exceptions === | ||
| + | * (DatabaseDriverUnavailableError) this driver is not available | ||
| + | * (ConnectionError) connection failed | ||
| + | |||
| + | ==== prepare ==== | ||
| + | Prepare a request on the current database. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | myObject.prepare(queryString, | ||
| + | </ | ||
| + | |||
| + | === Arguments === | ||
| + | - queryString - (string) the query string to prepare | ||
| + | - parameters - (object) the prepare parameters | ||
| + | |||
| + | === Returns === | ||
| + | * (Sql) this Sql | ||
| + | |||
| + | === Exceptions === | ||
| + | * (PrepareQueryError) unable to prepare the query | ||
| + | |||
| + | === Example === | ||
| + | <code javascript> | ||
| + | myObject.prepare(" | ||
| + | id: 1, | ||
| + | data: "My data" | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | ==== execute ==== | ||
| + | Execute a prepared request or executes a request on the current database. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | myObject.execute(queryString); | ||
| + | </ | ||
| + | <code javascript> | ||
| + | myObject.execute(); | ||
| + | </ | ||
| + | |||
| + | === Arguments === | ||
| + | - queryString - (string) the query string to execute | ||
| + | |||
| + | === Returns === | ||
| + | * (Sql) this Sql | ||
| + | |||
| + | === Exceptions === | ||
| + | * (ExecuteQueryError) failed to execute the query | ||
| + | |||
| + | ==== fetchResult ==== | ||
| + | Retrieves the result of an executed request. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | myObject.fetchResult(indexStyle); | ||
| + | </ | ||
| + | <code javascript> | ||
| + | myObject.fetchResult(); | ||
| + | </ | ||
| + | |||
| + | === Arguments === | ||
| + | - indexStyle - ([[# | ||
| + | |||
| + | === Returns === | ||
| + | * (Sql) this Sql | ||
| + | |||
| + | === Exceptions === | ||
| + | * (FetchError) cannot fetch the result of a non-select query | ||
| + | |||
| + | ==== disconnect ==== | ||
| + | Disconnects the current database connection. | ||
| + | |||
| + | === Syntax === | ||
| + | <code javascript> | ||
| + | myObject.disconnect(); | ||
| + | </ | ||
| + | |||
| + | === Returns === | ||
| + | * (Sql) this Sql | ||
| + | |||
| + | ===== Enumerations ===== | ||
| + | |||
| + | ==== Driver ==== | ||
| + | SQL drivers. On Windows only the MySQL, PostgreSQL, SQLite 3, Firebird and ODBC drivers are installed by default. | ||
| + | |||
| + | === Values === | ||
| + | - SQLite2: [[http:// | ||
| + | - SQLite: [[http:// | ||
| + | - PostgreSQL: [[http:// | ||
| + | - MySQL: [[http:// | ||
| + | - ODBC: [[http:// | ||
| + | - InterBase: [[http:// | ||
| + | - OCI: [[http:// | ||
| + | - TDS: [[http:// | ||
| + | - DB2: [[http:// | ||
| + | |||
| + | ==== IndexStyle ==== | ||
| + | The fetch index style. | ||
| + | |||
| + | === Values === | ||
| + | - IndexNumber: | ||
| + | - IndexName: indexes the results by column name | ||
