====== Sql ======
This object allows you to establish a connection to a SQL database like MySQL, PostgreSQL, SQLite and others.
===== Functions =====
==== Sql ====
Constructor function.
=== Syntax ===
var myObject = new Sql(driver);
=== Arguments ===
- driver - ([[#driver|Driver]]) the database driver to use
=== Exceptions ===
* (NoDatabaseDriverError) no database driver specified
=== Example ===
Create a Sql object operating on a MySQL database.
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|drivers]] function.
==== drivers ====
Returns a list of available Drivers.
=== Syntax ===
Sql.drivers();
===== Methods =====
==== connect ====
Opens a connection with a database.
=== Syntax ===
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://doc.qt.nokia.com/latest/qsqldatabase.html#setConnectOptions]])
=== Returns ===
* (Sql) this Sql
=== Exceptions ===
* (DatabaseDriverUnavailableError) this driver is not available
* (ConnectionError) connection failed
==== prepare ====
Prepare a request on the current database.
=== Syntax ===
myObject.prepare(queryString, parameters);
=== 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 ===
myObject.prepare("INSERT INTO myTable (id, data) VALUES(:id, :data)", {
id: 1,
data: "My data"
});
==== execute ====
Execute a prepared request or executes a request on the current database.
=== Syntax ===
myObject.execute(queryString);
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 ===
myObject.fetchResult(indexStyle);
myObject.fetchResult();
=== Arguments ===
- indexStyle - ([[#indexstyle|IndexStyle]]) the fetch index style
=== Returns ===
* (Sql) this Sql
=== Exceptions ===
* (FetchError) cannot fetch the result of a non-select query
==== disconnect ====
Disconnects the current database connection.
=== Syntax ===
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://www.sqlite.org/|SQLite 2]]
- SQLite: [[http://www.sqlite.org/|SQLite 3]]
- PostgreSQL: [[http://www.postgresql.org/|PostgreSQL]] (versions 7.3 and above)
- MySQL: [[http://www.mysql.com/|MySQL]]
- ODBC: [[http://msdn.microsoft.com/en-us/library/ms710252(v=vs.85).aspx|Open Database Connectivity]] (ODBC) - Microsoft SQL Server and other ODBC-compliant databases
- InterBase: [[http://www.borland.com/fr/products/interbase/index.html|Borland InterBase]] ([[http://www.firebirdsql.org/|Firebird]])
- OCI: [[http://www.oracle.com/technetwork/database/features/oci/index.html|Oracle Call Interface Driver]]
- TDS: [[http://www.sybase.com/products/databasemanagement/adaptiveserverenterprise|Sybase Adaptive Server]] (obsolete)
- DB2: [[http://www-01.ibm.com/software/data/db2/|IBM DB2]] (version 7.1 and above)
==== IndexStyle ====
The fetch index style.
=== Values ===
- IndexNumber: indexes the results by number
- IndexName: indexes the results by column name