Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mike Chambers 635 posts 1252 karma points c-trib
    Dec 04, 2012 @ 11:25
    Mike Chambers
    1

    Alternative to sql script...

    might be of interest... I refactor the sql script for selecting the prevalue so that it isn't a database call and for our needs added in the pixel sizes of the crops into the description. ;-)

     

                try
                {
                    SortedList values = PreValues.GetPreValues(DataTypeDefinition.GetAll().First(dtDef => dtDef.DataType.DataTypeName.ToString() == defaultDataType).DataType.DataTypeDefinitionId);
                    umbraco.cms.businesslogic.datatype.PreValue value = (umbraco.cms.businesslogic.datatype.PreValue)values[0];
    
                    string[] cropOptions = value.Value.Split('|');
                    string[] cropTypes = cropOptions[1].Split(';');
    
                    foreach (string item in cropTypes)
                    {
                        string[] cropItem = item.Split(',');
                        items.Add(new ListItem(cropItem[0] + " (" + cropItem[1] + "x" + cropItem[2] + ")", cropItem[0]));
                    }
                }
                catch { return null; }

     

  • Nigel Wilson 944 posts 2076 karma points
    Dec 04, 2012 @ 17:47
    Nigel Wilson
    0

    Hi Mike

    Wicked man - very much interested as I didn't know about this alternative, so thank you for sharing.

    One question:

    Where does "Prevalues.GetPreValues" get the data from - is it cached somewhere to prevent the database call. Or is this simply a method that in the end is in fact making a database call to get the data.

    I ask as I am curious to learn more.

    Cheers, Nigel

  • Mike Chambers 635 posts 1252 karma points c-trib
    Dec 04, 2012 @ 18:10
    Mike Chambers
    0

    from umbraco.codeplex.com source....

     /// <summary>
            /// Gets the pre values collection.
            /// </summary>
            /// <param name="DataTypeId">The data type id.</param>
            /// <returns></returns>
            public static SortedList GetPreValues(int DataTypeId)
            {
                SortedList retval = new SortedList();
                IRecordsReader dr = SqlHelper.ExecuteReader(
                    "Select id, sortorder, [value] from cmsDataTypePreValues where DataTypeNodeId = @dataTypeId order by sortorder",
                    SqlHelper.CreateParameter("@dataTypeId", DataTypeId));
    
                int counter = 0;
                while (dr.Read())
                {
                    retval.Add(counter, new PreValue(dr.GetInt("id"), dr.GetInt("sortorder"), dr.GetString("value")));
                    counter++;
                }
                dr.Close();
                return retval;
            }

     So looks like underlying db call.. I actually mistyped... was meaning more a direct db call.. eg should the db ever change this should still work as the underlying core should be updated too. ;-)

  • Nigel Wilson 944 posts 2076 karma points
    Dec 04, 2012 @ 19:29
    Nigel Wilson
    0

    Hi Mike

    Ahh - I did do a quick google search but didn't take the time to track down the source code.

    Totally agree that using a method (over a direct SQL query) is a more robust solution so can look to update the package accordingly.

    Cheers for the input - you are part of the very reason why this community is successful - open and sharing of information.

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft