0

以下のエクスプレスコードの一部で、テーブルの名前をSQLクエリに動的に渡そうとしています

背景情報::

  • 私が(キー、値)として渡しているのは、SQLデータベースのテーブルの名前になる文字列です
  • 動的クライアント要求に基づいてテーブルを動的に選択するのはなぜですか

私が直面している問題::

  • 明らかに、SQLクエリを正しく実行していません
  • これを解決する方法

[エクスプレスコード]

app.get('/RestaurantDesc/:Key',function(request,response,next){

    var keyName=request.params.Key;
    var name_of_restaurants, RestaurantTimings;
    async.series( [
        // Get the first table contents
        function ( callback ) {
            connection.query('SELECT * FROM keyName', function(err, rows, fields)
                {
                        console.log('Connection result error '+err);
                        name_of_restaurants = rows;
                        callback();
                });
        },
        // Get the second table contents
        function ( callback ) {
        connection.query('SELECT * FROM RestaurantTimings', function(err, rows, fields)

            {
                    console.log('Connection result error '+err);
                    RestaurantTimings = rows;
                    callback();
            });
        }

   // Send the response
], function ( error, results ) {
    response.json({
        'restaurants' : name_of_restaurants,
        'RestaurantTimings' : RestaurantTimings
    });
} );
} );
4

1 に答える 1

0

テーブル名としてkeynameandを考慮します。RestaurantTimingsこれを試して:-

app.get('/RestaurantDesc/:Key',function(request,response,next){

    var keyName=request.params.Key;
    var name_of_restaurants, RestaurantTimings;

    async.series( [
        // Get the first table contents
        function ( callback ) {
            connection.query('SELECT * FROM ', keyName, function(err, rows, fields)
                {
                        console.log('Connection result error '+err);
                        name_of_restaurants = rows;
                        callback();
                });
        },
        // Get the second table contents
        function ( callback ) {
        connection.query('SELECT * FROM ', RestaurantTimings, function(err, rows, fields)

            {
                    console.log('Connection result error '+err);
                    RestaurantTimings = rows;
                    callback();
            });
        }

   // Send the response
], function ( error, results ) {
    response.json({
        'restaurants' : name_of_restaurants,
        'RestaurantTimings' : RestaurantTimings
    });
} );
} );
于 2013-08-28T19:03:32.760 に答える