EN
Ta zawartość nie jest dostępna w wymaganym języku. Wersja w języku angielskim znajduje się tutaj.
Ten temat nie został jeszcze oceniony - Oceń ten temat

mssql object

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

The feature described in this topic is available only in preview. To use this feature and other new Windows Azure capabilities, sign up for the free preview.


Provides functionality for working directly with tables in the SQL Database using Transact-SQL.

This object contains the following members:

Methods

open

Syntax Description

mssql.open(options)

Opens a SQL connection. The connection is passed as an argument to the success handler.

query

Syntax Description

mssql.query(sql, options)

Executes the specified sql. Results are passed to the success callback on the options object.

mssql.query(sql, params, options)

Executes the specified sql, with question mark (?) placeholders replaced with values from the params array. Results are passed to the success callback on the options object.

queryRaw

Syntax Description

mssql.queryRaw(sql, options)

Executes the specified sql. Results are passed to the success callback on the options object in a raw format.

mssql.queryRaw(sql, params, options)

Executes the specified sql, with question mark (?) placeholders replaced with values from the params array. Results are passed to the success callback on the options object in a raw format.

The global mssql object differs from the Microsoft Driver for Node.js for SQL Server in the following ways

  • You do not need to pass the connection string; Windows Azure Mobile Services does this for you.

  • Success and error callbacks are separate and specified as properties of an options object.

The following example executes a query that returns a single record form the statusupdates table

mssql.query('select top 1 * from statusupdates', {
    success: function(results) {
        console.log(results);
    }
});

The following example implements custom authorization by reading permissions for each user from the permissions table. The placeholder (?) is replaced with the supplied parameter when the query is executed.

function insert(item, user, request) {
    var sql = "SELECT _id FROM permissions WHERE userId = ? AND permission = 'submit order'";
    mssql.query(sql, [user.userId], {
        success: function(results) {
            if (results.length > 0) {
                // Permission record was found. Continue normal execution. 
                request.execute();
            } else {
                console.log('User %s attempted to submit an order without permissions.', user.userId);
                request.respond(statusCodes.FORBIDDEN, 'You do not have permission to submit orders.');
            }
        }
    });
}

The following example manually opens a connection to the SQL Database. The connection is passed as an argument to the success handler.

function insert(item, user, request) {
    mssql.open({
        success: function(connection) {
            connection.query(//query to execute);
            connection.query(//query to execute)
            // etc 
        }
    }
}

Oceniasz te materiały jako pomocne?
(Pozostało znaków: 1500)
© 2013 Microsoft. Wszelkie prawa zastrzeżone.
facebook page visit twitter rss feed newsletter