Ejemplo n.º 1
0
        private string GetQuery(TableDataSetProperties props, QueryType type)
        {
            string cmdtext = GetQueryTemplate(props.Perspective, type);

            if (m_supportsFilteringAndSorting)
            {
                if (type == QueryType.SelectNoUserInput)
                {
                    if (!props.FilterSqlConditionNoUserInput.IsEmpty())
                    {
                        cmdtext += "\nWHERE " + props.FilterSqlConditionNoUserInput;
                    }
                }
                else
                {
                    if (!props.FilterSqlCondition.IsEmpty())
                    {
                        cmdtext += "\nWHERE " + props.FilterSqlCondition;
                    }
                }
                if (type != QueryType.SelectCount)
                {
                    if (!props.SortOrder.IsEmpty())
                    {
                        cmdtext += "\nORDER BY " + props.SortOrder;
                    }
                }
            }
            return(cmdtext);
        }
Ejemplo n.º 2
0
        public void LoadAllRows(TableDataSetProperties props, Action <IBedRecord> forEachRow)
        {
            var per = props.Perspective;

            try
            {
                BedAdapter adapter;
                string     cmdtext;
                LoadTableDataProlog(props, out adapter, out cmdtext);
                using (var canc = Connection.AddOnCancel(adapter.CancelLoading))
                {
                    DateTime start = DateTime.Now;
                    try
                    {
                        adapter.LoadTableData(cmdtext, forEachRow);
                    }
                    catch (Exception err)
                    {
                        LoadTableDataPrologHandleError(props, err);
                    }
                    double len = (DateTime.Now - start).TotalSeconds;
                }
            }
            catch (Exception)
            {
                // probably error in command, clear adapter so that it is recreated next time
                m_adapters.Remove(per ?? nullPer);
                throw;
            }
        }
Ejemplo n.º 3
0
 public void LoadAllRows(TableDataSetProperties props, Action <IBedRecord> forEachRow)
 {
     foreach (var row in m_table.Rows)
     {
         forEachRow(row);
     }
 }
Ejemplo n.º 4
0
        public IEnumerable <IBedRecord> EnumRows(TableDataSetProperties props)
        {
            int page = 0;

            do
            {
                while (page < m_directory.Count)
                {
                    lock (m_directory)
                    {
                        BinaryReader br = new BinaryReader(m_cache);
                        m_cache.Seek(m_directory[page], SeekOrigin.Begin);
                        ChunkInfo info = ChunkInfo.LoadInfo(br);
                        for (int i = 0; i < info.Count; i++)
                        {
                            yield return(BedTool.LoadRecord(br, m_table));
                        }
                    }
                    page++;
                }
                if (State == TabularDataViewState.Loading)
                {
                    System.Threading.Thread.Sleep(100);
                }
            } while (State == TabularDataViewState.Loading);
        }
Ejemplo n.º 5
0
        public ITabularDataStore GetStoreAndClone(TableDataSetProperties props)
        {
            IPhysicalConnection conn = m_conn.Clone();

            if (!String.IsNullOrEmpty(m_dbname))
            {
                conn.AfterOpen += ConnTools.ChangeDatabaseCallback(m_dbname);
            }
            return(new GenericQueryDataStore(conn, m_dbname, GetQuery(props, QueryType.SelectVisible)));
        }
Ejemplo n.º 6
0
        private void LoadTableDataProlog(TableDataSetProperties props, out BedAdapter adapter, out string cmdtext)
        {
            var per = props.Perspective;

            WantAdapter(per);
            adapter = m_adapters[per ?? nullPer];

            m_conn.ReconnectIfBroken();
            if (m_conn.Dialect.DialectCaps.MultipleDatabase)
            {
                m_conn.SystemConnection.SafeChangeDatabase(m_dbname);
            }

            cmdtext = GetQuery(props, QueryType.Select);
            ProgressInfo.Debug(Texts.Get("s_executing$query", "query", cmdtext));
        }
Ejemplo n.º 7
0
        public int?LoadRowCount(TableDataSetProperties props)
        {
            string cmdtext = GetQuery(props, QueryType.SelectCount);

            if (cmdtext.IsEmpty())
            {
                return(null);
            }
            using (DbCommand cmd = m_conn.DbFactory.CreateCommand())
            {
                cmd.Connection  = m_conn.SystemConnection;
                cmd.CommandText = cmdtext;
                using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                {
                    if (reader.Read())
                    {
                        return(Int32.Parse(reader[0].SafeToString()));
                    }
                }
                return(0);
            }
        }
Ejemplo n.º 8
0
        public void GenerateScript(TableDataScript script, TableDataSetProperties props, ISqlDumper dmp)
        {
            switch (script)
            {
            case TableDataScript.Delete:
                if (!m_deleteQuery.IsEmpty())
                {
                    dmp.WriteRaw(m_deleteQuery);
                    if (!props.FilterSqlCondition.IsEmpty())
                    {
                        dmp.WriteRaw(" WHERE ");
                        dmp.WriteRaw(props.FilterSqlCondition);
                    }
                    dmp.EndCommand();
                }
                break;

            case TableDataScript.Select:
                dmp.WriteRaw(GetQuery(props, QueryType.Select));
                dmp.EndCommand();
                break;
            }
        }
Ejemplo n.º 9
0
        private void LoadTableDataPrologHandleError(TableDataSetProperties props, Exception err)
        {
            string cmd2 = GetQuery(props, QueryType.SelectNoUserInput);

            try
            {
                using (var cmd = Connection.SystemConnection.CreateCommand())
                {
                    cmd.CommandText = cmd2;
                    using (var reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        reader.Read();
                    }
                }
            }
            catch
            {
                // FAIL - throw original exception
                throw err;
            }
            // OK - there is syntax error in user input
            throw new UserInputSyntaxError(err.Message, err);
        }
Ejemplo n.º 10
0
 public int?LoadRowCount(TableDataSetProperties props)
 {
     WantTable();
     return(m_table.Rows.Count);
 }
Ejemplo n.º 11
0
 public void GenerateScript(TableDataScript script, TableDataSetProperties props, ISqlDumper dmp)
 {
 }
Ejemplo n.º 12
0
 public ITabularDataStore GetStoreAndClone(TableDataSetProperties props)
 {
     return(new DataTableTabularDataStore(m_conn.Clone(), (Func <IPhysicalConnection, DataTable>)LoadTable));
 }
Ejemplo n.º 13
0
 public ITabularDataStore GetStoreAndClone(TableDataSetProperties props)
 {
     return(this);
 }
Ejemplo n.º 14
0
 public void GenerateScript(TableDataScript script, TableDataSetProperties props, ISqlDumper dmp)
 {
     throw new NotImplementedError("DAE-00381");
 }
Ejemplo n.º 15
0
 public int?LoadRowCount(TableDataSetProperties props)
 {
     return(m_serializedRows);
 }