Exemplo n.º 1
0
        /// <summary>
        /// Tries the get column value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reader">The recordsreader.</param>
        /// <param name="columnName">Name of the column.</param>
        /// <param name="value">The value.</param>
        /// <returns>Returns the value of the specified column.</returns>
        public static bool TryGetColumnValue <T>(this IRecordsReader reader, string columnName, out T value)
        {
            if (reader.ContainsField(columnName) && !reader.IsNull(columnName))
            {
                value = reader.Get <T>(columnName);

                return(true);
            }

            value = default(T);

            return(false);
        }
        /// <summary>
        /// Retrieve HTML from the database cache for the given node
        /// </summary>
        /// <param name="nodeId">Id of the node</param>
        /// <param name="fullHtml">string to fill with HTML</param>
        /// <returns>bool indicating success/failure</returns>
        public static bool GetRecord(int nodeId, out string fullHtml)
        {
            fullHtml = "";

            if (nodeId < 1)
            {
                return(false);
            }

            var            success   = false;
            ISqlHelper     sqlHelper = null;
            IRecordsReader result    = null;

            try
            {
                const string sqlQuery = "SELECT fullHTML FROM fullTextCache WHERE nodeId = @nodeId";
                sqlHelper = DataLayerHelper.CreateSqlHelper(global::Umbraco.Core.ApplicationContext.Current.DatabaseContext.ConnectionString);
                result    = sqlHelper.ExecuteReader(sqlQuery, sqlHelper.CreateParameter("@nodeId", nodeId));
                if (result != null && result.HasRecords && result.Read() && result.ContainsField("fullHTML"))
                {
                    fullHtml = result.GetString("fullHTML");
                    success  = true;
                }
            }
            catch (umbraco.UmbracoException ex)
            {
                LogHelper.Error(typeof(DbAccess), "Error In Database Query to fullTextCache", ex);
                fullHtml = "";
            }
            finally
            {
                if (result != null)
                {
                    result.Close();
                }
                if (sqlHelper != null)
                {
                    sqlHelper.Dispose();
                }
            }
            return(success);
        }
Exemplo n.º 3
0
        public static bool TryGetColumnBool(IRecordsReader reader, string columnName, out bool value)
        {
            if (reader.ContainsField(columnName) && !reader.IsNull(columnName))
            {
                value = reader.GetBoolean(columnName);
                return true;
            }

            value = false;
            return false;
        }
Exemplo n.º 4
0
        public static bool TryGetColumnInt32(IRecordsReader reader, string columnName, out int value)
        {
            if (reader.ContainsField(columnName) && !reader.IsNull(columnName))
            {
                value = reader.GetInt(columnName);
                return true;
            }

            value = -1;
            return false;
        }
Exemplo n.º 5
0
        public static bool TryGetColumnString(IRecordsReader reader, string columnName, out string value)
        {
            if (reader.ContainsField(columnName) && !reader.IsNull(columnName))
            {
                value = reader.GetString(columnName);
                return true;
            }

            value = string.Empty;
            return false;
        }