/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="log">The logger to use for this metadata source.</param>
        public BCatalogOnlyMetadataSource(ILogger log, BProperties properties)
        {
            LogUtilities.LogFunctionEntrance(log, log);
            Log          = log;
            m_Properties = properties;

            try
            {
                //get the client connection
                using (var client = ExternalServiceClient.GetClient(m_Properties.Server))
                {
                    //get the catalogs
                    string[] catalogs = client.GetMetadataCatalogs();

                    //copy results
                    m_Catalogs.AddRange(catalogs);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }

            //m_Catalogs.Add(Driver.B_CATALOG);
        }
示例#2
0
 public SpliceConnection(
     IEnvironment environment)
     : base(environment)
 {
     LogUtilities.LogFunctionEntrance(Log, environment);
     SetConnectionProperties();
 }
示例#3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="log">The logger to use for this metadata source.</param>
        public BColumnsMetadataSource(ILogger log, BProperties properties)
        {
            LogUtilities.LogFunctionEntrance(log, log);
            Log          = log;
            m_Properties = properties;

            //InitializeData();
            //List<ColumnInfo> column_infos = new List<ColumnInfo>();
            //column_infos.AddRange(m_Columns);
            //m_Columns.Clear();

            try
            {
                //get the client connection
                using (var client = ExternalServiceClient.GetClient(m_Properties.Server))
                {
                    //get the columns
                    ColumnMetadataResult[] columns = client.GetMetadataColumns();

                    //copy results
                    columns.ToList().Where(c => c.Visible).ToList().ForEach(c =>
                    {
                        //if(c.Table == "Mentions" &&
                        //    (
                        //        c.Column == "Id" ||
                        //        c.Column == "Name" ||
                        //        c.Column == "Description" ||
                        //        c.Column == "Type" ||
                        //        c.Column == "Sentiment" ||
                        //        c.Column == "Influence" ||
                        //        c.Column == "IsDisabled" ||
                        //        c.Column == "OccurredOn" ||
                        //        c.Column == "CreatedOn" ||
                        //        c.Column == "UpdatedOn" ||
                        //        c.Column == "Guid" ||
                        //        c.Column == "Author" ||
                        //        c.Column == "Followers" ||
                        //        c.Column == "Klout" ||
                        //        c.Column == "Comments"
                        //    ))
                        {
                            m_Columns.Add(
                                GetColumnInfo(
                                    c.Catalog,
                                    c.Table,
                                    c.Column,
                                    c.DataType,
                                    c.ColumnLength,
                                    c.Nullable,
                                    c.OrdinalPosition,
                                    c.ColumnPrecision));
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
        }
示例#4
0
        public BQueryExecutor(ILogger log, BProperties properties, string sql)
        {
            //get function data
            LogUtilities.LogFunctionEntrance(log, log, sql);
            Log          = log;
            m_Properties = properties;
            Sql          = sql;

            // Create the prepared results.
            Results = new List <IResult>();

            // Create the parameters.
            ParameterMetadata = new List <ParameterMetadata>();

            //create our data
            IResult result = BResultTableFactory.CreateResultTable(log, sql, properties);

            if (result != null)
            {
                Results.Add(result);
            }
            else
            {
                throw new Exception("Failed to create the result table.");
            }
        }
示例#5
0
        /// <summary>
        /// Cancels the currently executing query.
        /// </summary>
        public void CancelExecute()
        {
            LogUtilities.LogFunctionEntrance(Log);

            // It's not possible to cancel execution in the UltraLight driver, as there is no actual
            // 'execution', everything is already hardcoded within the driver.
        }
示例#6
0
        /// <summary>
        /// Checks and updates settings for this connection.
        ///
        /// This method is called when attempting to establish a connection to check if the input
        /// connection settings are valid. This method DOES NOT establish a connection, instead
        /// Connect() should be called to attempt to establish a connection. This method should
        /// inspect the input settings and return any modified and additional requested connection
        /// settings.
        ///
        /// If any connection settings have been modified, then a WarningCode.OPT_VAL_CHANGED
        /// warning must be posted. If a key in the map is unrecognized or does not belong in this
        /// stage of connection, then a WarningCode.INVALID_CONN_STR_ATTR warning must be posted.
        /// </summary>
        /// <param name="requestSettings">Connection settings specified for this connection attempt.</param>
        /// <returns>
        ///     Connection settings that have been modified, and additional connection settings
        ///     requested that are not present in the input settings.
        /// </returns>
        public override Dictionary <string, ConnectionSetting> UpdateConnectionSettings(
            Dictionary <string, object> requestSettings)
        {
            // TODO(ODBC) #03: Check connection settings.
            // TODO(ADO)  #05: Check connection settings.
            LogUtilities.LogFunctionEntrance(Log, requestSettings);
            Utilities.NullCheck("requestSettings", requestSettings);

            Dictionary <string, ConnectionSetting> responseSettings = new Dictionary <string, ConnectionSetting>();

            // This method will receive all incoming connection settings as specified in the
            // connection string. Iterate over the connectionSettings and ensure that values are
            // specified for each of the keys required to establish a connection.
            //
            // If a key is missing, then add it to the returned Dictionary.
            //
            // Data validation for the keys should be done in Connect()
            //
            // This driver has the following settings:
            //      Required Key: UID - represents a name of a user, could be anything.
            //      Required Key: PWD - represents the password, could be anything.
            //      Optional Key: LNG - represents the language. (NOT USED)

            VerifyRequiredSetting(Driver.B_SERVER_KEY, requestSettings, responseSettings);
            VerifyRequiredSetting(Driver.B_UID_KEY, requestSettings, responseSettings);
            VerifyRequiredSetting(Driver.B_PWD_KEY, requestSettings, responseSettings);
            VerifyRequiredSetting(Driver.B_CATALOG_KEY, requestSettings, responseSettings);
            VerifyRequiredSetting(Driver.B_ROWS_TO_FETCH_KEY, requestSettings, responseSettings);
            VerifyOptionalSetting(Driver.B_RESULT_TYPE_KEY, requestSettings, responseSettings);



            return(responseSettings);
        }
示例#7
0
        /// <summary>
        /// Indicates that the cursor should be moved to before the first row.
        /// </summary>
        /// <returns>True if there are more rows; false otherwise.</returns>
        public bool MoveToBeforeFirstRow()
        {
            LogUtilities.LogFunctionEntrance(Log);
            m_IsFetching = true;
            m_Current    = 0;

            return(m_Current < m_Columns.Count);
        }
示例#8
0
        /// <summary>
        /// Attempts to establish a connection to the data source, using connection settings
        /// generated by a call to UpdateConnectionSettings().
        /// </summary>
        /// <param name="connectionSettings">Connection settings used to authenticate the connection.</param>
        public override void Connect(Dictionary <string, object> connectionSettings)
        {
            // TODO(ODBC) #04: Establish a connection.
            // TODO(ADO)  #06: Establish a connection.
            LogUtilities.LogFunctionEntrance(Log, connectionSettings);
            Utilities.NullCheck("connectionSettings", connectionSettings);

            // The SimbaEngine SDK will call UpdateConnectionSettings() prior to calling this method.
            // This will ensure that all valid keys required to create a connection have been specified
            // and are stored within in_connectionSettings.
            //
            // This method should validate each of the incoming values and throw an error in the event
            // of an invalid value.

            // This driver doesn't validate the given settings, it just requires them.
            string server  = GetRequiredSetting(Driver.B_SERVER_KEY, connectionSettings).ToString();
            string uid     = GetRequiredSetting(Driver.B_UID_KEY, connectionSettings).ToString();
            string pwd     = GetRequiredSetting(Driver.B_PWD_KEY, connectionSettings).ToString();
            string catalog = GetRequiredSetting(Driver.B_CATALOG_KEY, connectionSettings).ToString();

            string strRows = GetRequiredSetting(Driver.B_ROWS_TO_FETCH_KEY, connectionSettings).ToString();
            int    rows    = 1000;

            Int32.TryParse(strRows, out rows);

            object objResultType;

            BProperties.ResultTypes result_type = BProperties.ResultTypes.Normal;
            GetOptionalSetting(Driver.B_RESULT_TYPE_KEY, connectionSettings, out objResultType);
            if (objResultType == null)
            {
                Enum.TryParse <BProperties.ResultTypes>(objResultType.ToString(), true, out result_type);
            }

            if (string.IsNullOrWhiteSpace(uid) ||
                string.IsNullOrWhiteSpace(pwd) ||
                string.IsNullOrWhiteSpace(catalog) ||
                string.IsNullOrWhiteSpace(server))
            {
                throw new Exception("required parameters were not supplied or invalid");
            }


            SetProperty(ConnectionPropertyKey.DSI_CONN_SERVER_NAME, server);
            SetProperty(ConnectionPropertyKey.DSI_CONN_CURRENT_CATALOG, catalog);
            SetProperty(ConnectionPropertyKey.DSI_CONN_USER_NAME, uid);

            m_Properties = new BProperties()
            {
                Server      = server,
                UserName    = uid,
                Password    = pwd,
                Catalog     = catalog,
                RowsToFetch = rows,
                ResultType  = result_type
            };
        }
示例#9
0
        public SpliceDriver()
        {
            LogUtilities.LogFunctionEntrance(Log);
            SetDriverPropertyValues();

            // SAMPLE: Adding resource managers here allows you to localize the Simba DotNetDSI and/or ADO.Net components.
            //Simba.DotNetDSI.Properties.Resources.ResourceManager.AddResourceManager(
            //    new System.Resources.ResourceManager("Simba.UltraLight.Properties.SimbaDotNetDSI", GetType().Assembly));
        }
示例#10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="log">The logger to use for this metadata source.</param>
        public BTypeInfoMetadataSource(ILogger log)
        {
            LogUtilities.LogFunctionEntrance(log, log);

            Log = log;

            // Not using the restrictions, allow the SQLEngine to do filtering.
            InitializeDataTypes();
        }
示例#11
0
        /// <summary>
        /// Executes the prepared statement for each parameter set provided, or once if there are
        /// no parameters supplied.
        /// </summary>
        /// <param name="contexts">
        ///     Holds ExecutionContext objects and parameter metadata for execution. There is one
        ///     ExecutionContext for each parameter set to be executed.
        /// </param>
        /// <param name="warningListener">Used to post warnings about the execution.</param>
        public void Execute(ExecutionContexts contexts, IWarningListener warningListener)
        {
            LogUtilities.LogFunctionEntrance(Log, contexts, warningListener);

            //mark all context as success
            foreach (ExecutionContext context in contexts)
            {
                context.Succeeded = true;
            }
        }
示例#12
0
        /// <summary>
        /// Indicates that the cursor should be moved to the next row.
        /// </summary>
        /// <returns>True if there are more rows; false otherwise.</returns>
        public bool MoveToNextRow()
        {
            LogUtilities.LogFunctionEntrance(Log);
            if (m_IsFetching)
            {
                return(false);
            }

            m_IsFetching = true;
            return(true);
        }
示例#13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="log">The logger to use for logging.</param>
        public BResultTable(ILogger log, string sql, BProperties properties)
            : base(log)
        {
            //get the parameters
            LogUtilities.LogFunctionEntrance(Log, log);
            m_Properties = properties;
            Sql          = sql;

            //execute the first fetch
            ExecuteFetch(m_CurrentPage);
        }
示例#14
0
 /// <summary>
 /// Indicates that the cursor should be moved to the next row.
 /// </summary>
 /// <returns>True if there are more rows; false otherwise.</returns>
 public bool MoveToNextRow()
 {
     LogUtilities.LogFunctionEntrance(Log);
     if (m_IsFetching)
     {
         m_Current++;
     }
     else
     {
         m_IsFetching = true;
         m_Current    = 0;
     }
     return(m_Current < m_Tables.Count);
 }
示例#15
0
        /// <summary>
        /// Initialize the column metadata for the result set.
        /// </summary>
        public void InitializeColumns(object obj)
        {
            LogUtilities.LogFunctionEntrance(Log);

            //get the info the build the columns
            ResultEntityType = obj.GetType();
            ResultFields     = ResultEntityType.GetFields().ToList();

            //fields to remove that we do not want in results
            List <FieldInfo> remove = new List <FieldInfo>();

            //parse the fields
            foreach (var field in ResultFields)
            {
                //make sure this not collection type
                if (field.FieldType.GetInterface("ICollection") != null)
                {
                    //remove this field
                    remove.Add(field);
                }
                else
                {
                    //create the column
                    DSIColumn column = new DSIColumn(TypeMetadataHelper.CreateTypeMetadata(field.FieldType));
                    column.IsNullable = Nullability.Nullable;
                    column.Catalog    = m_Properties.Catalog;
                    column.Schema     = Driver.B_SCHEMA;
                    column.TableName  = "Results";
                    column.Name       = field.Name;
                    column.Label      = column.Name;
                    if (field.FieldType == typeof(string))
                    {
                        column.Size         = 1000;
                        column.IsSearchable = Searchable.Searchable;
                    }
                    else
                    {
                        column.IsSearchable = Searchable.PredicateBasic;
                    }
                    m_Columns.Add(column);
                }
            }
            //remove the fields
            foreach (var field in remove)
            {
                ResultFields.Remove(field);
            }
        }
示例#16
0
        /// <summary>
        /// Fills in out_data with the data for a given column in the current row.
        /// </summary>
        /// <param name="columnTag">The column to retrieve data from.</param>
        /// <param name="offset">The number of bytes in the data to skip before copying.</param>
        /// <param name="maxSize">The maximum number of bytes of data to return.</param>
        /// <param name="out_data">The data to be returned.</param>
        /// <returns>True if there is more data in the column; false otherwise.</returns>
        public bool GetMetadata(
            MetadataSourceColumnTag columnTag,
            long offset,
            long maxSize,
            out object out_data)
        {
            LogUtilities.LogFunctionEntrance(Log, columnTag, offset, maxSize, "out_data");

            switch (columnTag)
            {
            case MetadataSourceColumnTag.CATALOG_NAME:
            {
                out_data = m_Tables[m_Current].Catalog;
                return(false);
            }

            case MetadataSourceColumnTag.SCHEMA_NAME:
            {
                out_data = m_Tables[m_Current].Schema;
                return(false);
            }

            case MetadataSourceColumnTag.TABLE_NAME:
            {
                out_data = m_Tables[m_Current].Table;
                return(false);
            }

            case MetadataSourceColumnTag.TABLE_TYPE:
            {
                out_data = m_Tables[m_Current].TableType;
                return(false);
            }

            case MetadataSourceColumnTag.REMARKS:
            {
                out_data = m_Tables[m_Current].Remarks;
                return(false);
            }

            default:
            {
                throw ExceptionBuilder.CreateException(
                          "Column Metadata Not Found",
                          columnTag.ToString());
            }
            }
        }
示例#17
0
        public override void Connect(
            Dictionary <String, Object> connectionSettings)
        {
            LogUtilities.LogFunctionEntrance(Log, connectionSettings);
            Utilities.NullCheck("connectionSettings", connectionSettings);

            _drdaConnection = new DrdaConnection(new DrdaConnectionOptions
            {
                Port     = Convert.ToInt32(GetRequiredSetting("PORT", connectionSettings)),
                HostName = Convert.ToString(GetRequiredSetting("HOST", connectionSettings)),
                UserName = Convert.ToString(GetRequiredSetting("UID", connectionSettings)),
                Password = Convert.ToString(GetRequiredSetting("PWD", connectionSettings))
            });

            _drdaConnection.ConnectAsync().Wait();
        }
示例#18
0
        public override Dictionary <String, ConnectionSetting> UpdateConnectionSettings(
            Dictionary <String, Object> requestSettings)
        {
            // TODO(ADO)  #05: Check connection settings.

            LogUtilities.LogFunctionEntrance(Log, requestSettings);
            Utilities.NullCheck("requestSettings", requestSettings);

            var responseSettings = new Dictionary <String, ConnectionSetting>();

            VerifyRequiredSetting("HOST", requestSettings, responseSettings);
            VerifyRequiredSetting("PORT", requestSettings, responseSettings);
            VerifyRequiredSetting("UID", requestSettings, responseSettings);
            VerifyRequiredSetting("PWD", requestSettings, responseSettings);

            return(responseSettings);
        }
示例#19
0
        public SpliceQueryExecutor(
            ILogger log)
        {
            // TODO(ADO)  #09: Implement a QueryExecutor.

            LogUtilities.LogFunctionEntrance(log, log);
            _log = log;

            // Create the prepared results.
            Results = new List <IResult>();

            Results.Add(new DSIRowCountResult(12));

            // TODO(ADO)  #10: Provide parameter information.

            ParameterMetadata = new List <ParameterMetadata>();
        }
示例#20
0
        /// <summary>
        /// Fills in out_data with the data for a given column in the current row.
        /// </summary>
        /// <param name="column">The column to retrieve data from, 0 based.</param>
        /// <param name="offset">The number of bytes in the data to skip before copying.</param>
        /// <param name="maxSize">The maximum number of bytes of data to return.</param>
        /// <param name="out_data">The data to be returned.</param>
        /// <returns>True if there is more data in the column; false otherwise.</returns>
        public override bool GetData(
            int column,
            long offset,
            long maxSize,
            out object out_data)
        {
            LogUtilities.LogFunctionEntrance(Log, column, offset, maxSize, "out_data");

            out_data = null;
            try
            {
                out_data = m_Data[(int)CurrentRow][column];
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
            return(false);
        }
示例#21
0
        /// <summary>
        /// Displays a dialog box that prompts the user for settings for this connection.
        ///
        /// The connection settings from io_connectionSettings are presented as key-value string
        /// pairs. The input connection settings map is the initial state of the dialog box.  The
        /// input connection settings map will be modified to reflect the user's input to the
        /// dialog box.
        ///
        /// The return value for this method indicates if the user completed the process by
        /// clicking OK on the dialog box (return true), or if the user aborts the process by
        /// clicking CANCEL on the dialog box (return false).
        ///
        /// This dialog is only used for an ODBC driver built with .NET.
        /// </summary>
        ///
        /// <param name="connResponseMap">
        /// The connection settings map updated to reflect the user's input.
        /// </param>
        /// <param name="connectionSettings">
        /// The connection settings map updated with settings that are still needed and were not
        /// supplied.
        /// </param>
        /// <param name="parentWindow">
        /// Handle to the parent window to which this dialog belongs
        /// </param>
        /// <param name="promptType">
        /// Indicates what type of connection settings to request - either both required and
        /// optional settings or just required settings.
        /// </param>
        /// <returns>True if the user clicks OK on the dialog box; false if the user clicks CANCEL.
        /// </returns>
        public override bool PromptDialog(
            Dictionary <string, ConnectionSetting> connResponseMap,
            Dictionary <string, object> connectionSettings,
            System.Windows.Forms.IWin32Window parentWindow,
            PromptType promptType)
        {
            LogUtilities.LogFunctionEntrance(
                Log,
                connResponseMap,
                connectionSettings,
                parentWindow);

            BConnectionDlg dialog = new BConnectionDlg(
                connectionSettings,
                promptType == PromptType.PROMPT_REQUIRED);

            System.Windows.Forms.DialogResult result = dialog.ShowDialog(parentWindow);
            return(result == System.Windows.Forms.DialogResult.OK);
        }
示例#22
0
        /// <summary>
        /// Creates a custom metadata source which filters out unneeded rows according to the given
        /// filters.
        ///
        /// Note that filtering must be implemented by the custom result set.
        ///
        /// This function works in conjunction with SConnection.GetCustomSchemas().
        /// Override GetCustomSchemas() in SConnection to return the list of custom schemas.
        /// Note that this is only available when using the Simba.NET components.
        /// </summary>
        /// <param name="metadataID">Identifier to create the appropriate metadata source.</param>
        /// <param name="filterValues">
        ///     Filters to be applied to the metadata table. Appear in column order, with null
        ///     values for columns that are not filtered on.
        /// </param>
        /// <param name="escapeChar">Escape character used in filtering.</param>
        /// <param name="identifierQuoteChar">Character used as a quote around identifiers.</param>
        /// <param name="filterAsIdentifier">Indicates if string filters are treated as identifiers.</param>
        /// <returns>A result set object representing the requested metadata.</returns>
        public override IResultSet MakeNewCustomMetadataResult(
            string metadataID,
            IList <object> filterValues,
            string escapeChar,
            string identifierQuoteChar,
            bool filterAsIdentifier)
        {
            LogUtilities.LogFunctionEntrance(
                Log,
                metadataID,
                filterValues,
                escapeChar,
                identifierQuoteChar,
                filterAsIdentifier);


            throw ExceptionBuilder.CreateException(
                      Simba.DotNetDSI.Properties.Resources.INVALID_METADATA_ID,
                      metadataID);
        }
示例#23
0
        public void Execute(
            ExecutionContexts contexts,
            IWarningListener warningListener)
        {
            // TODO(ADO)  #11: Implement Query Execution.

            LogUtilities.LogFunctionEntrance(_log, contexts, warningListener);

            // The contexts argument provides access to the parameters that were not pushed.
            // Statement execution is a 3 step process:
            //      1. Serialize all input parameters into a form that can be consumed by the data
            //         source. If your data source does not support parameter streaming for pushed
            //         parameters, then you will need to re-assemble them from your parameter cache.
            //         See PushParamData.
            //      2. Send the Execute() message.
            //      3. Retrieve all output parameters from the server and update the contexts with
            //         their contents.

            // No action needs to be taken here since the results are static and encapsulated in
            // ULPersonTable and DSISimpleRowCountResult.
        }
示例#24
0
        /// <summary>
        /// Fills in out_data with the data for a given column in the current row.
        /// </summary>
        /// <param name="column">The column to retrieve data from, 0 based.</param>
        /// <param name="offset">The number of bytes in the data to skip before copying.</param>
        /// <param name="maxSize">The maximum number of bytes of data to return.</param>
        /// <param name="out_data">The data to be returned.</param>
        /// <returns>True if there is more data in the column; false otherwise.</returns>
        public override bool GetData(
            int column,
            long offset,
            long maxSize,
            out object out_data)
        {
            LogUtilities.LogFunctionEntrance(Log, column, offset, maxSize, "out_data");

            //check paging cache
            if (CurrentRow < m_CurrentPage * m_Properties.RowsToFetch || CurrentRow > ((m_CurrentPage + 1) * m_Properties.RowsToFetch) - 1)
            {
                //set the current page
                m_CurrentPage = CurrentRow / (long)m_Properties.RowsToFetch;

                //fetch next set of results
                ExecuteFetch(m_CurrentPage);
            }
            //calculate the paging row
            long PageRow = CurrentRow % m_Properties.RowsToFetch;

            //get the object
            object obj = m_Data[(int)PageRow];

            //get the value
            object value = ResultFields[column].GetValue(obj);

            //check for boolean
            if (value != null && value.GetType() == typeof(bool))
            {
                out_data = Convert.ToByte(value);
            }
            else
            {
                out_data = value;
            }

            //throw new Exception("testing");

            return(false);
        }
示例#25
0
        /// <summary>
        /// Prepare the given SQL query for execution.
        ///
        /// An IQueryExecutor is returned which will be used to handle query execution.
        /// </summary>
        /// <param name="sqlQuery">The SQL query to prepare.</param>
        /// <returns>An IQueryExecutor instance that will handle the query execution.</returns>
        public override IQueryExecutor Prepare(string sqlQuery)
        {
            // TODO(ODBC) #06: Prepare a query.
            // TODO(ADO)  #08: Prepare a query.
            LogUtilities.LogFunctionEntrance(Log, sqlQuery);

            // This is the point where you will send the request to your SQL-enabled data source for
            // query preparation. You will need to provide your own implementation of IQueryExecutor
            // which should wrap your statement context to the prepared query.
            //
            // Query preparation is really a 3 part process and is described as follows:
            //      1. Generate and send the request to your data source for query preparation.
            //      2. Handle the response and for each statement in the query retrieve its column
            //         metadata information prior to query execution.  You will need to derive from
            //         DSISimpleResultSet to create your representation of a result set.
            //         See ULPersonTable.
            //      3. Create an instance of IQueryExector seeding it with the results of the query.
            //         See ULQueryExecutor.

            // Determine if doing a SELECT or DML/DDL via very, very simple parsing.
            //string query = sqlQuery.ToLower();

            //bool isSelect = (-1 != query.IndexOf("select"));
            //bool isParameterized = (-1 != query.IndexOf("?"));
            //bool isProcedure = (-1 != query.IndexOf("{call"));

            //// Example of how to throw a parsing error.
            //if (isProcedure)
            //{
            //    throw ExceptionBuilder.CreateException(
            //        String.Format(Simba.DotNetDSI.Properties.Resources.INVALID_QUERY, query));
            //}

            //trace the execute
            System.Diagnostics.Trace.WriteLine(string.Format("**********************\r\nQueryExecution\r\n{0}\r\n***************************", sqlQuery));

            return(new BQueryExecutor(Log, m_Properties, sqlQuery));
        }
示例#26
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="log">The logger to use for logging.</param>
        public BFakeResultTable(ILogger log, string sql, BProperties properties)
            : base(log, sql, properties)
        {
            //set parameters
            LogUtilities.LogFunctionEntrance(Log, log);
            m_Properties = properties;
            Sql          = sql;

            //init the columns
            try
            {
                using (var client = ExternalServiceClient.GetClient(m_Properties.Server))
                {
                    m_TableColumns = client.GetMetadataColumns();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
            //make the fake data
            InitializeFakeData(Sql);
        }
示例#27
0
        /// <summary>
        /// Fills in out_data with the data for a given column in the current row.
        /// </summary>
        /// <param name="columnTag">The column to retrieve data from.</param>
        /// <param name="offset">The number of bytes in the data to skip before copying.</param>
        /// <param name="maxSize">The maximum number of bytes of data to return.</param>
        /// <param name="out_data">The data to be returned.</param>
        /// <returns>True if there is more data in the column; false otherwise.</returns>
        public bool GetMetadata(
            MetadataSourceColumnTag columnTag,
            long offset,
            long maxSize,
            out object out_data)
        {
            LogUtilities.LogFunctionEntrance(Log, columnTag, offset, maxSize, "out_data");

            switch (columnTag)
            {
            case MetadataSourceColumnTag.SCHEMA_NAME:
            {
                out_data = Driver.B_SCHEMA;
                return(false);
            }

            default:
            {
                throw ExceptionBuilder.CreateException(
                          "Column Not Found",
                          columnTag.ToString());
            }
            }
        }
示例#28
0
        /// <summary>
        /// Indicates that the cursor should be moved to the next row.
        /// </summary>
        /// <returns>True if there are more rows; false otherwise.</returns>
        protected override bool MoveToNextRow()
        {
            LogUtilities.LogFunctionEntrance(Log);

            return(CurrentRow < RowCount);
        }
示例#29
0
 /// <summary>
 /// Closes the result set's internal cursor. After a call to this method, no
 /// more calls will be made to MoveToNextRow() and GetData().
 /// </summary>
 protected override void DoCloseCursor()
 {
     LogUtilities.LogFunctionEntrance(Log);
 }
示例#30
0
        /// <summary>
        /// Initialize the fake data
        /// </summary>
        public void InitializeFakeData(string sql)
        {
            LogUtilities.LogFunctionEntrance(Log);

            List <object> fake_row = new List <object>();

            string sql_no_select = sql.Substring(sql.IndexOf("SELECT ") + 7);
            string sql_no_top    = sql_no_select;

            if (sql_no_select.IndexOf("TOP ") != -1)
            {
                sql_no_top = sql_no_select.Substring(sql_no_select.IndexOf("TOP ") + 4).Trim();
                sql_no_top = sql_no_top.Substring(sql_no_top.IndexOf(" ") + 1).Trim();
            }
            string sql_no_from = sql_no_top.Substring(0, sql_no_top.IndexOf("FROM "));

            string[] columns_with_alias = sql_no_from.Split(',');

            foreach (var field_alias in columns_with_alias)
            {
                string[] aliases = field_alias.Split(new string[] { " AS ", " as " }, StringSplitOptions.None);

                string field = "";
                string alias = "";
                if (aliases.Length > 0)
                {
                    field = aliases[0].Trim();
                }
                if (aliases.Length > 1)
                {
                    alias = aliases[1].Trim();
                }

                field = field.Replace("\"", "");
                alias = alias.Replace("\"", "");

                string table = "";
                if (field.IndexOf('.') != -1)
                {
                    table = field.Substring(0, field.IndexOf('.'));
                    field = field.Substring(field.IndexOf('.') + 1);
                }

                var  column_meta = m_TableColumns.Where(c => c.Table == table && c.Column == field).FirstOrDefault();
                Type type;
                bool added = false;
                if (column_meta != null)
                {
                    type = Type.GetType(column_meta.DataType);
                }
                else
                {
                    double num;
                    if (double.TryParse(field, out num))
                    {
                        type = typeof(double);
                        fake_row.Add(num);
                        added = true;
                    }
                    else
                    {
                        type = typeof(string);
                        fake_row.Add(field);
                    }
                }
                if (!added)
                {
                    if (type == typeof(string))
                    {
                        fake_row.Add("FakeData");
                    }
                    else if (type == typeof(DateTime))
                    {
                        fake_row.Add(DateTime.UtcNow);
                    }
                    else if (type == typeof(bool))
                    {
                        byte b = 0;
                        fake_row.Add(b);
                    }
                    else
                    {
                        fake_row.Add(Activator.CreateInstance(type));
                    }
                }


                DSIColumn column = new DSIColumn(TypeMetadataHelper.CreateTypeMetadata(type));
                column.IsNullable = Nullability.Nullable;
                column.Catalog    = m_Properties.Catalog;
                column.Schema     = Driver.B_SCHEMA;
                column.TableName  = "Results";
                column.Name       = alias;
                column.Label      = alias;
                if (type == typeof(string))
                {
                    column.Size         = 1000;
                    column.IsSearchable = Searchable.Searchable;
                }
                else
                {
                    column.IsSearchable = Searchable.PredicateBasic;
                }
                m_Columns.Add(column);
            }
            RowCount = 10;
            for (int x = 0; x < RowCount; x++)
            {
                m_Data.Add(fake_row);
            }
        }