/**
* Opens a connection to the database with the given connection-string. The `connectionString` must be
* either the virtual file-system path of an SQLite or SQL Server Compact file, or a
* prefixed [database connection-string](http://www.connectionstrings.com/). The prefixes are shown below:
*
* | Connection-type | Prefix | File-extension | Database DLLs required? |
* |---|---|---|---|
* | SQLite | sqlite:<sup>*</sup> | .sqlite3 | no |
* | SQL Server Compact | sqlserverce:<sup>*</sup> | .sdf | no |
* | SQL Server | sqlserver: | n/a | no |
* | ODBC | odbc: | n/a | no |
* | OLE DB | oledb: | n/a | yes<sup>**</sup> |
*
* <i><sup>*</sup> - Prefixes are only required for SQLite and SQL Server Compact if the listed file-extension
* isn't being used.</i>
*
* <i><sup>**</sup> - For OLE DB connections the DLLs for the specific database being accessed must be placed in the same directory
* as the CompleteFTP server executables.</i>
* @constructor
* @param {String} connectionString
*
* @classdesc
* Provides access to databases via the
* <a href="http://www.w3.org/TR/webdatabase/">WebSQLDatabase API</a>. Only the synchronous
* part of the API is implemented because asynchronous code is usually not required for
* server-side scripting.
*
* Example:
* ```
* // open a SQL Server CE database (path is in virtual file-system)
* var db = new DatabaseSync("/Databases/mydatabase.sdf");
* db.readTransaction(function(tx) {
* var result = tx.executeSql("SELECT Name FROM Company");
* for (var i in result.rows) {
* var row = result.rows[i];
* console.log(row.Name);
* }
* });
* ```
*/
DatabaseSync = function (connectionString) {
/**
* SQL statement used to obtain the ID of the most recently inserted row.
* @type {String}
*/
this.lastRowIdQuery = null;
/**
* Run the non-read transaction contained in the given callback function. A
* {@link SQLTransactionSync} object is passed as an
* argument to the callback. This may be used execute queries. The transaction is committed
* if the callback returns normally and rolled back if it throws an exception.
* @method
* @param {Function} [callback] callback function
* @param {SQLTransactionSync} [callback.transaction] Transaction object which can be used to execute SQL queries.
*/
this.transaction = function (callback) { }
/**
* Run the read transaction contained in the given callback function. A
* {@link SQLTransactionSync} object is passed as an
* argument to the callback. This may be used execute queries. The transaction is committed
* if the callback returns normally and rolled back if it throws an exception.
* @method
* @param {Function} [callback] callback function
* @param {SQLTransactionSync} [callback.transaction] Transaction object which can be used to execute SQL queries.
*/
this.readTransaction = function (callback) { }
/**
* Not implemented.
* @method
*/
this.changeVersion = function (oldVersion, newVersion) { }
}
/**
* @classdesc
* Provides methods for performing a database transaction that may consist of
* several queries. Accessed from DatabaseSync.transaction and DatabaseSync.readTransaction
* functions.
* @constructor
*/
SQLTransactionSync = function () {
/**
* Execute the given SQL and return the result as an {@link SQLResultSet} object.
* @method
* @param {String} sqlStatement SQL statement.
* @param {String[]} [parameters] Array containing the arguments to substitute into the statement.
* @return {SQLResultSet}
*/
this.executeSql = function (sqlStatement, parameters) { }
}
/**
* @classdesc
* Contains the results of an SQL query executed by
* {@link SQLTransactionSync#executeSql SQLTransactionSync.executeSql}.
* Accessed from SQLTransactionSync.executeSql function.
* @constructor
*/
SQLResultSet = function () {
/**
* ID of the row that was just inserted. This is not applicable to read transactions. In some databases, such as SQL Server Compact,
* a value is only returned if the ID was auto-incremented by the database.
* @type {number}
*/
this.insertId = null;
/**
* The number of rows affected by the query. This is not applicable to read transactions.
* @type {number}
*/
this.rowsAffected = null;
/**
* An array of objects each of which represents one row of results. Only applies to read transactions.
* Each object will have fields whose names correspond to the names of the columns returned by the query.
* @type Object[]
*/
this.rows = null;
}