protected void Save(object sender, EventArgs e) { string oldName = ddlFind.SelectedValue; string newName = string.Format("#{0}", ddlDictionary.SelectedValue); if (!string.IsNullOrEmpty(oldName)) { string sql = @" UPDATE [cmsPropertyType] SET [Name] = @NewName WHERE [Name] = @OldName "; ISqlHelper helper = umbraco.BusinessLogic.Application.SqlHelper; int rowsAffected = helper.ExecuteNonQuery(sql, new[] { helper.CreateParameter("@NewName", newName), helper.CreateParameter("@OldName", oldName) }); ltrRowsAffected.Text = rowsAffected.ToString(); SetupPropertyNames(); } }
private static List <Relation> GetRelations(string alias, string sort, int parentId, int number) { List <Relation> retval = new List <Relation>(); ISqlHelper sqlhelper = umbraco.BusinessLogic.Application.SqlHelper; IRecordsReader rr = sqlhelper.ExecuteReader( string.Format(@" SELECT TOP {0} umbracoRelation.id FROM umbracoRelation INNER JOIN umbracoRelationType ON umbracoRelationType.id = umbracoRelation.relType AND umbracoRelationType.alias = @alias where parentId = @parent ORDER BY datetime {1} ", number, sort) , sqlhelper.CreateParameter("@parent", parentId), sqlhelper.CreateParameter("@alias", alias) ); while (rr.Read()) { retval.Add(new Relation(rr.GetInt("id"))); } rr.Close(); rr.Dispose(); return(retval); }
public Domain(string DomainName) { object result = SqlHelper.ExecuteScalar <object>( "select id from umbracoDomains where domainName = @DomainName", SqlHelper.CreateParameter("@DomainName", DomainName)); if (result == null || !(result is int)) { throw new Exception(string.Format("Domain name '{0}' does not exists", DomainName)); } InitDomain((int)result); }
public List <Field> GetAllFields(Form form) { List <Field> l = new List <Field>(); string sql = @"SELECT UFfields.*, UFpages.form AS form, UFfieldsets.sortorder as FieldsetIndex, UFpages.sortorder as PageIndex From UFfields INNER JOIN UFfieldsets ON UFfieldsets.id = fieldset INNER JOIN UFpages ON UFpages.id = UFfieldsets.page where UFpages.form = @form ORDER by UfPages.SortOrder ASC, UFFieldsets.sortorder ASC, UFfields.sortOrder ASC "; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@form", form.Id)); while (rr.Read()) { Field f = Field.CreateFromDataReader(rr); if (!rr.IsNull("prevalueProvider") && rr.GetGuid("prevalueProvider") != Guid.Empty) { f.PreValueSource = prevalueSourceStorage.GetPrevalueSource(rr.GetGuid("prevalueProvider")); if (f.PreValueSource != null && f.PreValueSource.Id != Guid.Empty) { f.PreValueSourceId = f.PreValueSource.Id; } } f.Settings = settings.GetSettingsAsList(f.Id); //if (f.FieldType.HasSettings()) // f.FieldType.LoadSettings(f.Settings); f.Condition = conditionStorage.GetFieldCondition(f); if (f.Condition == null) { f.Condition = new FieldCondition(); f.Condition.Enabled = false; f.Condition.ActionType = FieldConditionActionType.Show; f.Condition.LogicType = FieldConditionLogicType.All; } l.Add(f); } rr.Dispose(); return(l); }
/// <summary> /// Initializes a new instance of the <see cref="PreValue"/> class. /// </summary> /// <param name="DataTypeId">The data type id.</param> /// <param name="Value">The value.</param> public PreValue(int DataTypeId, string Value) { object id = SqlHelper.ExecuteScalar <object>( "Select id from cmsDataTypePreValues where [Value] = @value and DataTypeNodeId = @dataTypeId", SqlHelper.CreateParameter("@dataTypeId", DataTypeId), SqlHelper.CreateParameter("@value", Value)); if (id != null) { _id = int.Parse(id.ToString()); } initialize(); }
public Package(Guid Id) { int installStatusId = SqlHelper.ExecuteScalar <int>( "select id from umbracoInstalledPackages where package = @package and upgradeId = 0", SqlHelper.CreateParameter("@package", Id)); if (installStatusId > 0) { Initialize(installStatusId); } else { throw new ArgumentException("Package with id '" + Id.ToString() + "' is not installed"); } }
/// <summary> /// Creates a new language given the culture code - ie. da-dk (denmark) /// </summary> /// <param name="cultureCode">Culturecode of the language</param> public static void MakeNew(string cultureCode) { lock (Locker) { var culture = GetCulture(cultureCode); if (culture != null) { //insert it SqlHelper.ExecuteNonQuery( "insert into umbracoLanguage (languageISOCode) values (@CultureCode)", SqlHelper.CreateParameter("@CultureCode", cultureCode)); InvalidateCache(); //get it's id var newId = SqlHelper.ExecuteScalar <int>("SELECT MAX(id) FROM umbracoLanguage WHERE languageISOCode=@cultureCode", SqlHelper.CreateParameter("@cultureCode", cultureCode)); //load it and raise events using (var dr = SqlHelper.ExecuteReader(string.Format("{0} where id = {1}", m_SQLOptimizedGetAll, newId))) { while (dr.Read()) { var ct = new Language(); ct.PopulateFromReader(dr); ct.OnNew(new NewEventArgs()); } } } } }
public List <object> GetRecordFieldValues(RecordField rf) { string sql = string.Format("SELECT * FROM UFRecordData{0} where [Key] = @key ORDER BY Id ASC", rf.DataTypeAlias); List <object> l = new List <object>(); IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@key", rf.Key)); while (rr.Read()) { switch (rf.DataType) { case FieldDataType.String: case FieldDataType.LongString: l.Add(rr.GetString("Value")); break; case FieldDataType.Integer: l.Add(rr.GetInt("Value")); break; case FieldDataType.DateTime: l.Add(rr.GetDateTime("Value")); break; case FieldDataType.Bit: l.Add(rr.GetBoolean("Value")); break; } } rr.Dispose(); return(l); }
public bool IsInPublishedHierarchy(int nodeId, ISqlHelper sqlHelper) { var parentId = sqlHelper.ExecuteScalar<int>("select parentId from [umbracoNode] where id = @nodeId", sqlHelper.CreateParameter("nodeId", nodeId)); if (parentId == -1) return true; else { var parentIsPublished = sqlHelper.ExecuteScalar<int>("select count(*) from [cmsDocument] where nodeId = @nodeId and published = 1 ", sqlHelper.CreateParameter("nodeId", parentId)) > 0; if (!parentIsPublished) return false; else return (IsInPublishedHierarchy(parentId, sqlHelper)); } }
private void setupUser(int ID) { _id = ID; using (IRecordsReader dr = SqlHelper.ExecuteReader( "Select userNoConsole, userDisabled, userType,startStructureID, startMediaId, userName,userLogin,userEmail,userDefaultPermissions, userLanguage, defaultToLiveEditing from umbracoUser where id = @id", SqlHelper.CreateParameter("@id", ID))) { if (dr.Read()) { _userNoConsole = dr.GetBoolean("usernoconsole"); _userDisabled = dr.GetBoolean("userDisabled"); _name = dr.GetString("userName"); _loginname = dr.GetString("userLogin"); _email = dr.GetString("userEmail"); _language = dr.GetString("userLanguage"); _startnodeid = dr.GetInt("startStructureID"); if (!dr.IsNull("startMediaId")) { _startmediaid = dr.GetInt("startMediaID"); } _usertype = UserType.GetUserType(dr.GetShort("UserType")); _defaultToLiveEditing = dr.GetBoolean("defaultToLiveEditing"); } else { throw new ArgumentException("No User exists with ID " + ID.ToString()); } } _isInitialized = true; }
public FieldPreValueSource GetPrevalueSource(Guid id) { //check for the default guid so we don't try to look for a provider which are not there.. //this could be considered a hack, but not everything can follow a generic model. FieldPreValueSource pv = new FieldPreValueSource(); if (id == FieldPreValueSource.GetDefaultProvider().Id) { pv = FieldPreValueSource.GetDefaultProvider(); } else { string sql = "SELECT * From UFPrevalueSources where id = @id"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@id", id)); if (rr.Read()) { pv = FieldPreValueSource.CreateFromDataReader(rr); pv.Settings = settings.GetSettings(pv.Id); rr.Dispose(); return(pv); } rr.Dispose(); } return(pv); }
public PropertyType(int id) { using (IRecordsReader dr = SqlHelper.ExecuteReader( "Select mandatory, DataTypeId, tabId, ContentTypeId, sortOrder, alias, name, validationRegExp, description from cmsPropertyType where id=@id", SqlHelper.CreateParameter("@id", id))) { if (!dr.Read()) { throw new ArgumentException("Propertytype with id: " + id + " doesnt exist!"); } _mandatory = dr.GetBoolean("mandatory"); _id = id; if (!dr.IsNull("tabId")) { _tabId = dr.GetInt("tabId"); } _sortOrder = dr.GetInt("sortOrder"); _alias = dr.GetString("alias"); _name = dr.GetString("Name"); _validationRegExp = dr.GetString("validationRegExp"); _DataTypeId = dr.GetInt("DataTypeId"); _contenttypeid = dr.GetInt("contentTypeId"); _description = dr.GetString("description"); } }
private static int GetRelations(string alias, int parentId) { ISqlHelper sqlhelper = umbraco.BusinessLogic.Application.SqlHelper; int result = sqlhelper.ExecuteScalar <int>( @" SELECT count(umbracoRelation.id) FROM umbracoRelation INNER JOIN umbracoRelationType ON umbracoRelationType.id = umbracoRelation.relType AND umbracoRelationType.alias = @alias where parentId = @parent " , sqlhelper.CreateParameter("@parent", parentId), sqlhelper.CreateParameter("@alias", alias) ); return(result); }
public List <Page> GetAllPages(Form form) { string sql = "SELECT * FROM UFpages where form = @form ORDER BY sortorder ASC"; List <Page> l = new List <Page>(); IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@form", form.Id)); while (rr.Read()) { Page p = Page.CreateFromDataReader(rr); p.FieldSets.AddRange(storage.GetAllFieldSets(p)); l.Add(p); } rr.Dispose(); return(l); }
public List <Setting <string, string> > GetSettings(int dataTypeNodeID) { string sql = "select * from cmsDataTypePreValues where datatypenodeid = @datatypenodeid"; IRecordsReader settingsReader = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@datatypenodeid", dataTypeNodeID)); List <Setting <string, string> > settings = new List <Setting <string, string> >(); while (settingsReader.Read()) { Setting <string, string> setting = new Setting <string, string>(); setting.Key = settingsReader.GetString("alias"); setting.Value = settingsReader.GetString("value"); settings.Add(setting); } settingsReader.Dispose(); return(settings); }
public List <FieldSet> GetAllFieldSets(Page page) { string sql = "SELECT * FROM UFfieldsets where page = @id ORDER BY sortorder ASC"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@id", page.Id)); List <FieldSet> l = new List <FieldSet>(); while (rr.Read()) { FieldSet fs = FieldSet.CreateFromDataReader(rr); fs.Fields.AddRange(storage.GetAllFields(fs)); l.Add(fs); } rr.Dispose(); return(l); }
public List <Form> GetAllForms(bool archived) { //SQL string sql = "SELECT * FROM UFforms where archived = @archived order by name ASC;"; List <Form> l = new List <Form>(); IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@archived", archived)); while (rr.Read()) { Guid id = rr.GetGuid("id"); Form f = Form.CreateFromDataReader(rr); f.Pages.AddRange(pageStorage.GetAllPages(f)); l.Add(f); } rr.Dispose(); return(l); }
/// <summary> /// Creates a new language given the culture code - ie. da-dk (denmark) /// </summary> /// <param name="CultureCode">Culturecode of the language</param> public static void MakeNew(string CultureCode) { if (new CultureInfo(CultureCode) != null) { SqlHelper.ExecuteNonQuery( "insert into umbracoLanguage (languageISOCode) values (@CultureCode)", SqlHelper.CreateParameter("@CultureCode", CultureCode)); InvalidateCache(); NewEventArgs e = new NewEventArgs(); GetByCultureCode(CultureCode).OnNew(e); } }
public List <Workflow> GetActiveWorkFlows(Form form, FormState state) { string sql = "SELECT * from UFworkflows where form = @form AND executesOn = @state AND active = 1 ORDER by SortOrder ASC"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@form", form.Id), sqlHelper.CreateParameter("@state", state)); List <Workflow> l = new List <Workflow>(); while (rr.Read()) { Workflow wf = Workflow.CreateFromDataReader(rr); wf.Settings = settings.GetSettings(wf.Id); if (wf.Active) { l.Add(wf); } } rr.Dispose(); return(l); }
public Dictionary <Guid, RecordField> GetAllRecordFields(Record record, Form form) { string sql = "SELECT * FROM UFRecordFields where Record = @record"; Dictionary <Guid, RecordField> l = new Dictionary <Guid, RecordField>(); IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@record", record.Id)); while (rr.Read()) { RecordField r = RecordField.CreateFromDataReader(rr); r.Values = recordFieldValueStorage.GetRecordFieldValues(r); l.Add(r.FieldId, r); } rr.Dispose(); return(l); }
public List <Record> GetAllRecords(Form form) { string sql = "SELECT * FROM UFRecords where form = @form ORDER BY created ASC"; List <Record> l = new List <Record>(); IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@form", form.Id)); while (rr.Read()) { Record r = Record.CreateFromDataReader(rr); r.RecordFields = recordFieldStorage.GetAllRecordFields(r, form); l.Add(r); } rr.Dispose(); return(l); }
/// <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); }
public Boolean IsInUse() { ISqlHelper sqlHelper = Helper.SqlHelper; string sql = "Select 1 from UFfields where PreValueProvider = @id;"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@id", Id)); bool inuse = false; if (rr.Read()) { inuse = true; } rr.Dispose(); return(inuse); }
/// <summary> /// Wrapper around umbraco's sqlHelper.ExecuteNonQuery that handles a few exceptions /// </summary> /// <param name="query">The SQL Query to execute</param> /// <param name="parameters">Dictionary mapping parameter name to parameter value</param> /// <returns>The number of rows affected, or -1 on failure</returns> private static int?NonQuery(string query, Dictionary <string, object> parameters) { int? numRows; ISqlHelper sqlHelper = null; try { sqlHelper = DataLayerHelper.CreateSqlHelper(global::Umbraco.Core.ApplicationContext.Current.DatabaseContext.ConnectionString); var numParams = parameters.Count; if (numParams < 1) { numRows = sqlHelper.ExecuteNonQuery(query); } else { var sqlParameters = new IParameter[numParams]; var i = 0; foreach (var parameter in parameters) { sqlParameters[i++] = sqlHelper.CreateParameter(parameter.Key, parameter.Value); } numRows = sqlHelper.ExecuteNonQuery(query, sqlParameters); } } catch (umbraco.UmbracoException ex) { LogHelper.Error(typeof(DbAccess), "Error In Database Query to fullTextCache.", ex); numRows = null; } finally { if (sqlHelper != null) { sqlHelper.Dispose(); } } return(numRows); }
public FieldCondition GetFieldCondition(Guid id) { string sql = "SELECT * from UFfieldconditions where id = @id"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@id", id)); FieldCondition fc = new FieldCondition(); if (rr.Read()) { fc = FieldCondition.CreateFromDataReader(rr); fc.Rules.AddRange(storage.GetAllFieldConditionRules(fc)); } rr.Dispose(); return(fc); }
/// <summary> /// Load content from database /// </summary> private XmlDocument LoadContentFromDatabase() { // Alex N - 2010 06 - Very generic try-catch simply because at the moment, unfortunately, this method gets called inside a ThreadPool thread // and we need to guarantee it won't tear down the app pool by throwing an unhandled exception try { // Moved User to a local variable - why are we causing user 0 to load from the DB though? // Alex N 20100212 User staticUser = null; try { staticUser = User.GetCurrent(); //User.GetUser(0); } catch { /* We don't care later if the staticUser is null */ } // Try to log to the DB Log.Add(LogTypes.System, staticUser, -1, "Loading content from database..."); var hierarchy = new Dictionary <int, List <int> >(); var nodeIndex = new Dictionary <int, XmlNode>(); try { Log.Add(LogTypes.Debug, staticUser, -1, "Republishing starting"); // Lets cache the DTD to save on the DB hit on the subsequent use var dtd = DocumentType.GenerateDtd(); // Prepare an XmlDocument with an appropriate inline DTD to match // the expected content var xmlDoc = new XmlDocument(); InitContentDocument(xmlDoc, dtd); // Esben Carlsen: At some point we really need to put all data access into to a tier of its own. string sql = @"select umbracoNode.id, umbracoNode.parentId, umbracoNode.sortOrder, cmsContentXml.xml from umbracoNode inner join cmsContentXml on cmsContentXml.nodeId = umbracoNode.id and umbracoNode.nodeObjectType = @type order by umbracoNode.level, umbracoNode.sortOrder"; lock (_dbReadSyncLock) { using (IRecordsReader dr = SqlHelper.ExecuteReader(sql, SqlHelper.CreateParameter("@type", new Guid("C66BA18E-EAF3-4CFF-8A22-41B16D66A972")))) { while (dr.Read()) { int currentId = dr.GetInt("id"); int parentId = dr.GetInt("parentId"); // Retrieve the xml content from the database // and parse it into a DOM node xmlDoc.LoadXml(dr.GetString("xml")); nodeIndex.Add(currentId, xmlDoc.FirstChild); // Build the content hierarchy List <int> children; if (!hierarchy.TryGetValue(parentId, out children)) { // No children for this parent, so add one children = new List <int>(); hierarchy.Add(parentId, children); } children.Add(currentId); } } } Log.Add(LogTypes.Debug, staticUser, -1, "Xml Pages loaded"); try { // If we got to here we must have successfully retrieved the content from the DB so // we can safely initialise and compose the final content DOM. // Note: We are reusing the XmlDocument used to create the xml nodes above so // we don't have to import them into a new XmlDocument // Initialise the document ready for the final composition of content InitContentDocument(xmlDoc, dtd); // Start building the content tree recursively from the root (-1) node GenerateXmlDocument(hierarchy, nodeIndex, -1, xmlDoc.DocumentElement); Log.Add(LogTypes.Debug, staticUser, -1, "Done republishing Xml Index"); return(xmlDoc); } catch (Exception ee) { Log.Add(LogTypes.Error, staticUser, -1, string.Format("Error while generating XmlDocument from database: {0}", ee)); } } catch (OutOfMemoryException) { Log.Add(LogTypes.Error, staticUser, -1, string.Format("Error Republishing: Out Of Memory. Parents: {0}, Nodes: {1}", hierarchy.Count, nodeIndex.Count)); } catch (Exception ee) { Log.Add(LogTypes.Error, staticUser, -1, string.Format("Error Republishing: {0}", ee)); } } catch (Exception ee) { Log.Add(LogTypes.Error, -1, string.Format("Error Republishing: {0}", ee)); } // An error of some sort must have stopped us from successfully generating // the content tree, so lets return null signifying there is no content available return(null); }
/// <summary> /// Initializes a new instance of the <see cref="CMSNode"/> class. /// </summary> /// <param name="uniqueID">The unique ID.</param> public CMSNode(Guid uniqueID) { _id = SqlHelper.ExecuteScalar <int>("SELECT id FROM umbracoNode WHERE uniqueID = @uniqueId", SqlHelper.CreateParameter("@uniqueId", uniqueID)); setupNode(); }
public RelationType(int id) { using (IRecordsReader dr = SqlHelper.ExecuteReader( "select id, dual, name, alias from umbracoRelationType where id = @id", SqlHelper.CreateParameter("@id", id))) { if (dr.Read()) { PopulateFromReader(dr); } else { throw new ArgumentException("Not RelationType found for id " + id.ToString()); } } }
public List <PreValue> GetAllPreValues(Field field) { List <PreValue> l = new List <PreValue>(); string sql = "SELECT * From UFprevalues where field = @field"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@field", field.Id)); while (rr.Read()) { PreValue pv = PreValue.CreateFromDataReader(rr); l.Add(pv); } rr.Dispose(); return(l); }
public FieldConditionRule GetFieldConditionRule(Guid id) { string sql = "SELECT * from UFfieldconditionrules where id = @id"; IRecordsReader rr = sqlHelper.ExecuteReader(sql, sqlHelper.CreateParameter("@id", id)); FieldConditionRule fcr = new FieldConditionRule(); if (rr.Read()) { fcr = FieldConditionRule.CreateFromDataReader(rr); } rr.Dispose(); return(fcr); }
public static IParameter CreateStringParameter(this ISqlHelper sqlHelper, string parameterName, string value) { return(sqlHelper.CreateParameter(parameterName, string.IsNullOrEmpty(value) ? DBNull.Value : (object)value)); }