Beispiel #1
0
        /// <summary>
        /// Generates the SELECT script from the selections
        /// </summary>
        /// <param name="queryBuilder"></param>
        /// <returns></returns>
        private QueryBuilderResponse getSelectScript(QueryBuilderObject queryBuilder)
        {
            string NEXT_LINE = "\r\n";
            string TAB       = "    ";

            StringBuilder query = new StringBuilder();

            StringBuilder load = new StringBuilder();

            if (queryBuilder.includePrecedingLoad)
            {
                foreach (QueryBuilderFieldObject field in queryBuilder.fields)
                {
                    if (load.Length != 0)
                    {
                        load.Append("," + NEXT_LINE + TAB);
                    }
                    load.Append(String.Format("\"{0}\"", field.displayName));
                    if (field.aliasName != "")
                    {
                        load.Append(String.Format(" AS \"{0}\"", field.aliasName));
                    }
                }
                query.Append(String.Format("LOAD {0};" + NEXT_LINE, load));
            }

            StringBuilder select = new StringBuilder();

            foreach (QueryBuilderFieldObject field in queryBuilder.fields)
            {
                if (select.Length != 0)
                {
                    select.Append("," + NEXT_LINE + TAB);
                }
                select.Append(String.Format("\"{0}\"", field.displayName));
            }

            StringBuilder from = new StringBuilder();

            from.Append(String.Format("\"{0} <{1}\\{2}>\"", queryBuilder.tableName, queryBuilder.databaseName, queryBuilder.ownerName));

            query.Append(String.Format("SQL SELECT {0}" + NEXT_LINE + "FROM {1};", select, from));

            return(new QueryBuilderResponse {
                query = query.ToString()
            });
        }
Beispiel #2
0
        /// <summary>
        /// Called by the HTML when actions are performed
        /// </summary>
        /// <param name="method">Name of the action specified in the call</param>
        /// <param name="userParameters">Parameters sent by the HTML</param>
        /// <param name="connection">Qlik connection</param>
        /// <returns></returns>
        public override string HandleJsonRequest(string method, string[] userParameters, QvxConnection connection)
        {
            #if DEBUG
            QvxLog.Log(QvxLogFacility.Application, QvxLogSeverity.Debug, "HandleJsonRequest()");
            #endif

            connection.MParameters.TryGetValue("provider", out string provider); // Set to the name of the connector by QlikView Engine
            connection.MParameters.TryGetValue("source", out string _source);    // Path to the directory set when creating new connection

            QvDataContractResponse response;
            switch (method)
            {
            case "getInfo":
                response = getInfo();
                break;

            case "getConnectionInfo":
                response = getConnectionInfo(userParameters[0]);
                break;

            case "testConnection":
                response = testConnection(userParameters[0]);
                break;

            case "getDatabases":
                response = getDatabases(connection as QvGamsConnection, _source);
                break;

            case "getOwners":
                response = getOwners(connection as QvGamsConnection, _source, userParameters[0]);
                break;

            case "getTables":
                response = getTables(connection as QvGamsConnection, _source, userParameters[0], userParameters[1]);
                break;

            case "getFields":
                response = getFields(connection as QvGamsConnection, _source, userParameters[0], userParameters[1], userParameters[2]);
                break;

            case "getPreview":
                response = getPreview(connection as QvGamsConnection, _source, userParameters[0], userParameters[1], userParameters[2]);
                break;

            case "getServerFolders":
                response = GetServerFolders(userParameters[0], userParameters[1]);
                break;

            case "getSelectScript":
                QueryBuilderObject queryBuilder = ParseJson <QueryBuilderObject>(userParameters[0]);
                response = getSelectScript(queryBuilder);
                break;

            default:
                response = new QlikView.Qvx.QvxLibrary.Info {
                    qMessage = "Unknown command"
                };
                break;
            }
            return(ToJson(response));    // serializes response into JSON string
        }