///<summary>Inserts one WikiPageHist into the database. Provides option to use the existing priKey.</summary> public static long Insert(WikiPageHist wikiPageHist, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { wikiPageHist.WikiPageNum = ReplicationServers.GetKey("wikipagehist", "WikiPageNum"); } string command = "INSERT INTO wikipagehist ("; if (useExistingPK || PrefC.RandomKeys) { command += "WikiPageNum,"; } command += "UserNum,PageTitle,PageContent,DateTimeSaved,IsDeleted) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(wikiPageHist.WikiPageNum) + ","; } command += POut.Long(wikiPageHist.UserNum) + "," + "'" + POut.String(wikiPageHist.PageTitle) + "'," + "'" + POut.String(wikiPageHist.PageContent) + "'," + POut.DateT(wikiPageHist.DateTimeSaved) + "," + POut.Bool(wikiPageHist.IsDeleted) + ")"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { wikiPageHist.WikiPageNum = Db.NonQ(command, true); } return(wikiPageHist.WikiPageNum); }
///<summary>Inserts one WikiPageHist into the database. Returns the new priKey.</summary> public static long Insert(WikiPageHist wikiPageHist) { if (DataConnection.DBtype == DatabaseType.Oracle) { wikiPageHist.WikiPageNum = DbHelper.GetNextOracleKey("wikipagehist", "WikiPageNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(wikiPageHist, true)); } catch (Oracle.DataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { wikiPageHist.WikiPageNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(wikiPageHist, false)); } }
///<summary>Updates one WikiPageHist in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables. Returns true if an update occurred.</summary> public static bool Update(WikiPageHist wikiPageHist, WikiPageHist oldWikiPageHist) { string command = ""; if (wikiPageHist.UserNum != oldWikiPageHist.UserNum) { if (command != "") { command += ","; } command += "UserNum = " + POut.Long(wikiPageHist.UserNum) + ""; } if (wikiPageHist.PageTitle != oldWikiPageHist.PageTitle) { if (command != "") { command += ","; } command += "PageTitle = '" + POut.String(wikiPageHist.PageTitle) + "'"; } if (wikiPageHist.PageContent != oldWikiPageHist.PageContent) { if (command != "") { command += ","; } command += "PageContent = " + DbHelper.ParamChar + "paramPageContent"; } if (wikiPageHist.DateTimeSaved != oldWikiPageHist.DateTimeSaved) { if (command != "") { command += ","; } command += "DateTimeSaved = " + POut.DateT(wikiPageHist.DateTimeSaved) + ""; } if (wikiPageHist.IsDeleted != oldWikiPageHist.IsDeleted) { if (command != "") { command += ","; } command += "IsDeleted = " + POut.Bool(wikiPageHist.IsDeleted) + ""; } if (command == "") { return(false); } if (wikiPageHist.PageContent == null) { wikiPageHist.PageContent = ""; } OdSqlParameter paramPageContent = new OdSqlParameter("paramPageContent", OdDbType.Text, POut.StringParam(wikiPageHist.PageContent)); command = "UPDATE wikipagehist SET " + command + " WHERE WikiPageNum = " + POut.Long(wikiPageHist.WikiPageNum); Db.NonQ(command, paramPageContent); return(true); }
///<summary>Updates one WikiPageHist in the database.</summary> public static void Update(WikiPageHist wikiPageHist) { string command = "UPDATE wikipagehist SET " + "UserNum = " + POut.Long(wikiPageHist.UserNum) + ", " + "PageTitle = '" + POut.String(wikiPageHist.PageTitle) + "', " + "PageContent = '" + POut.String(wikiPageHist.PageContent) + "', " + "DateTimeSaved= " + POut.DateT(wikiPageHist.DateTimeSaved) + ", " + "IsDeleted = " + POut.Bool(wikiPageHist.IsDeleted) + " " + "WHERE WikiPageNum = " + POut.Long(wikiPageHist.WikiPageNum); Db.NonQ(command); }
///<summary>Updates one WikiPageHist in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> public static void Update(WikiPageHist wikiPageHist, WikiPageHist oldWikiPageHist) { string command = ""; if (wikiPageHist.UserNum != oldWikiPageHist.UserNum) { if (command != "") { command += ","; } command += "UserNum = " + POut.Long(wikiPageHist.UserNum) + ""; } if (wikiPageHist.PageTitle != oldWikiPageHist.PageTitle) { if (command != "") { command += ","; } command += "PageTitle = '" + POut.String(wikiPageHist.PageTitle) + "'"; } if (wikiPageHist.PageContent != oldWikiPageHist.PageContent) { if (command != "") { command += ","; } command += "PageContent = '" + POut.String(wikiPageHist.PageContent) + "'"; } if (wikiPageHist.DateTimeSaved != oldWikiPageHist.DateTimeSaved) { if (command != "") { command += ","; } command += "DateTimeSaved = " + POut.DateT(wikiPageHist.DateTimeSaved) + ""; } if (wikiPageHist.IsDeleted != oldWikiPageHist.IsDeleted) { if (command != "") { command += ","; } command += "IsDeleted = " + POut.Bool(wikiPageHist.IsDeleted) + ""; } if (command == "") { return; } command = "UPDATE wikipagehist SET " + command + " WHERE WikiPageNum = " + POut.Long(wikiPageHist.WikiPageNum); Db.NonQ(command); }
///<summary>Inserts one WikiPageHist into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(WikiPageHist wikiPageHist) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(wikiPageHist, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { wikiPageHist.WikiPageNum = DbHelper.GetNextOracleKey("wikipagehist", "WikiPageNum"); //Cacheless method } return(InsertNoCache(wikiPageHist, true)); } }
///<summary>Converts a DataTable to a list of objects.</summary> public static List<WikiPageHist> TableToList(DataTable table){ List<WikiPageHist> retVal=new List<WikiPageHist>(); WikiPageHist wikiPageHist; for(int i=0;i<table.Rows.Count;i++) { wikiPageHist=new WikiPageHist(); wikiPageHist.WikiPageNum = PIn.Long (table.Rows[i]["WikiPageNum"].ToString()); wikiPageHist.UserNum = PIn.Long (table.Rows[i]["UserNum"].ToString()); wikiPageHist.PageTitle = PIn.String(table.Rows[i]["PageTitle"].ToString()); wikiPageHist.PageContent = PIn.String(table.Rows[i]["PageContent"].ToString()); wikiPageHist.DateTimeSaved= PIn.DateT (table.Rows[i]["DateTimeSaved"].ToString()); wikiPageHist.IsDeleted = PIn.Bool (table.Rows[i]["IsDeleted"].ToString()); retVal.Add(wikiPageHist); } return retVal; }
private void LoadWikiPage(WikiPageHist wikiPageCur) { try { if (string.IsNullOrEmpty(wikiPageCur.PageContent)) { //if this is the first time the user has clicked on this revision, get page content from db (the row's tag will have this as well) wikiPageCur.PageContent = WikiPageHists.GetPageContent(wikiPageCur.WikiPageNum); } textContent.Text = WikiPages.GetWikiPageContentWithWikiPageTitles(wikiPageCur.PageContent); webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(textContent.Text, false, hasWikiPageTitles: true); } catch (Exception ex) { webBrowserWiki.DocumentText = ""; MessageBox.Show(this, Lan.g(this, "This page is broken and cannot be viewed. Error message:") + " " + ex.Message); } }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <WikiPageHist> TableToList(DataTable table) { List <WikiPageHist> retVal = new List <WikiPageHist>(); WikiPageHist wikiPageHist; for (int i = 0; i < table.Rows.Count; i++) { wikiPageHist = new WikiPageHist(); wikiPageHist.WikiPageNum = PIn.Long(table.Rows[i]["WikiPageNum"].ToString()); wikiPageHist.UserNum = PIn.Long(table.Rows[i]["UserNum"].ToString()); wikiPageHist.PageTitle = PIn.String(table.Rows[i]["PageTitle"].ToString()); wikiPageHist.PageContent = PIn.String(table.Rows[i]["PageContent"].ToString()); wikiPageHist.DateTimeSaved = PIn.DateT(table.Rows[i]["DateTimeSaved"].ToString()); wikiPageHist.IsDeleted = PIn.Bool(table.Rows[i]["IsDeleted"].ToString()); retVal.Add(wikiPageHist); } return(retVal); }
///<summary>Updates one WikiPageHist in the database.</summary> public static void Update(WikiPageHist wikiPageHist) { string command = "UPDATE wikipagehist SET " + "UserNum = " + POut.Long(wikiPageHist.UserNum) + ", " + "PageTitle = '" + POut.String(wikiPageHist.PageTitle) + "', " + "PageContent = " + DbHelper.ParamChar + "paramPageContent, " + "DateTimeSaved= " + POut.DateT(wikiPageHist.DateTimeSaved) + ", " + "IsDeleted = " + POut.Bool(wikiPageHist.IsDeleted) + " " + "WHERE WikiPageNum = " + POut.Long(wikiPageHist.WikiPageNum); if (wikiPageHist.PageContent == null) { wikiPageHist.PageContent = ""; } OdSqlParameter paramPageContent = new OdSqlParameter("paramPageContent", OdDbType.Text, POut.StringParam(wikiPageHist.PageContent)); Db.NonQ(command, paramPageContent); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <WikiPageHist> TableToList(DataTable table) { List <WikiPageHist> retVal = new List <WikiPageHist>(); WikiPageHist wikiPageHist; foreach (DataRow row in table.Rows) { wikiPageHist = new WikiPageHist(); wikiPageHist.WikiPageNum = PIn.Long(row["WikiPageNum"].ToString()); wikiPageHist.UserNum = PIn.Long(row["UserNum"].ToString()); wikiPageHist.PageTitle = PIn.String(row["PageTitle"].ToString()); wikiPageHist.PageContent = PIn.String(row["PageContent"].ToString()); wikiPageHist.DateTimeSaved = PIn.DateT(row["DateTimeSaved"].ToString()); wikiPageHist.IsDeleted = PIn.Bool(row["IsDeleted"].ToString()); retVal.Add(wikiPageHist); } return(retVal); }
///<summary>Inserts one WikiPageHist into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(WikiPageHist wikiPageHist, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO wikipagehist ("; if (!useExistingPK && isRandomKeys) { wikiPageHist.WikiPageNum = ReplicationServers.GetKeyNoCache("wikipagehist", "WikiPageNum"); } if (isRandomKeys || useExistingPK) { command += "WikiPageNum,"; } command += "UserNum,PageTitle,PageContent,DateTimeSaved,IsDeleted) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(wikiPageHist.WikiPageNum) + ","; } command += POut.Long(wikiPageHist.UserNum) + "," + "'" + POut.String(wikiPageHist.PageTitle) + "'," + DbHelper.ParamChar + "paramPageContent," + POut.DateT(wikiPageHist.DateTimeSaved) + "," + POut.Bool(wikiPageHist.IsDeleted) + ")"; if (wikiPageHist.PageContent == null) { wikiPageHist.PageContent = ""; } OdSqlParameter paramPageContent = new OdSqlParameter("paramPageContent", OdDbType.Text, POut.StringParam(wikiPageHist.PageContent)); if (useExistingPK || isRandomKeys) { Db.NonQ(command, paramPageContent); } else { wikiPageHist.WikiPageNum = Db.NonQ(command, true, "WikiPageNum", "wikiPageHist", paramPageContent); } return(wikiPageHist.WikiPageNum); }
///<summary>Inserts one WikiPageHist into the database. Returns the new priKey.</summary> public static long Insert(WikiPageHist wikiPageHist){ if(DataConnection.DBtype==DatabaseType.Oracle) { wikiPageHist.WikiPageNum=DbHelper.GetNextOracleKey("wikipagehist","WikiPageNum"); int loopcount=0; while(loopcount<100){ try { return Insert(wikiPageHist,true); } catch(Oracle.DataAccess.Client.OracleException ex){ if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){ wikiPageHist.WikiPageNum++; loopcount++; } else{ throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return Insert(wikiPageHist,false); } }
///<summary>Returns true if Update(WikiPageHist,WikiPageHist) would make changes to the database. ///Does not make any changes to the database and can be called before remoting role is checked.</summary> public static bool UpdateComparison(WikiPageHist wikiPageHist, WikiPageHist oldWikiPageHist) { if (wikiPageHist.UserNum != oldWikiPageHist.UserNum) { return(true); } if (wikiPageHist.PageTitle != oldWikiPageHist.PageTitle) { return(true); } if (wikiPageHist.PageContent != oldWikiPageHist.PageContent) { return(true); } if (wikiPageHist.DateTimeSaved != oldWikiPageHist.DateTimeSaved) { return(true); } if (wikiPageHist.IsDeleted != oldWikiPageHist.IsDeleted) { return(true); } return(false); }
///<summary>Inserts one WikiPageHist into the database. Provides option to use the existing priKey.</summary> public static long Insert(WikiPageHist wikiPageHist,bool useExistingPK){ if(!useExistingPK && PrefC.RandomKeys) { wikiPageHist.WikiPageNum=ReplicationServers.GetKey("wikipagehist","WikiPageNum"); } string command="INSERT INTO wikipagehist ("; if(useExistingPK || PrefC.RandomKeys) { command+="WikiPageNum,"; } command+="UserNum,PageTitle,PageContent,DateTimeSaved,IsDeleted) VALUES("; if(useExistingPK || PrefC.RandomKeys) { command+=POut.Long(wikiPageHist.WikiPageNum)+","; } command+= POut.Long (wikiPageHist.UserNum)+"," +"'"+POut.String(wikiPageHist.PageTitle)+"'," +"'"+POut.String(wikiPageHist.PageContent)+"'," + POut.DateT (wikiPageHist.DateTimeSaved)+"," + POut.Bool (wikiPageHist.IsDeleted)+")"; if(useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { wikiPageHist.WikiPageNum=Db.NonQ(command,true); } return wikiPageHist.WikiPageNum; }
///<summary>Updates one WikiPageHist in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables.</summary> public static void Update(WikiPageHist wikiPageHist,WikiPageHist oldWikiPageHist){ string command=""; if(wikiPageHist.UserNum != oldWikiPageHist.UserNum) { if(command!=""){ command+=",";} command+="UserNum = "+POut.Long(wikiPageHist.UserNum)+""; } if(wikiPageHist.PageTitle != oldWikiPageHist.PageTitle) { if(command!=""){ command+=",";} command+="PageTitle = '"+POut.String(wikiPageHist.PageTitle)+"'"; } if(wikiPageHist.PageContent != oldWikiPageHist.PageContent) { if(command!=""){ command+=",";} command+="PageContent = '"+POut.String(wikiPageHist.PageContent)+"'"; } if(wikiPageHist.DateTimeSaved != oldWikiPageHist.DateTimeSaved) { if(command!=""){ command+=",";} command+="DateTimeSaved = "+POut.DateT(wikiPageHist.DateTimeSaved)+""; } if(wikiPageHist.IsDeleted != oldWikiPageHist.IsDeleted) { if(command!=""){ command+=",";} command+="IsDeleted = "+POut.Bool(wikiPageHist.IsDeleted)+""; } if(command==""){ return; } command="UPDATE wikipagehist SET "+command +" WHERE WikiPageNum = "+POut.Long(wikiPageHist.WikiPageNum); Db.NonQ(command); }
///<summary>Updates one WikiPageHist in the database.</summary> public static void Update(WikiPageHist wikiPageHist){ string command="UPDATE wikipagehist SET " +"UserNum = "+POut.Long (wikiPageHist.UserNum)+", " +"PageTitle = '"+POut.String(wikiPageHist.PageTitle)+"', " +"PageContent = '"+POut.String(wikiPageHist.PageContent)+"', " +"DateTimeSaved= "+POut.DateT (wikiPageHist.DateTimeSaved)+", " +"IsDeleted = "+POut.Bool (wikiPageHist.IsDeleted)+" " +"WHERE WikiPageNum = "+POut.Long(wikiPageHist.WikiPageNum); Db.NonQ(command); }
///<summary>Inserts one WikiPageHist into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(WikiPageHist wikiPageHist) { return(InsertNoCache(wikiPageHist, false)); }
private void LoadWikiPage(WikiPageHist WikiPageCur) { webBrowserWiki.DocumentText = WikiPages.TranslateToXhtml(WikiPageCur.PageContent, false); textContent.Text = WikiPageCur.PageContent; }