Пример #1
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<SecurityLogHash> TableToList(DataTable table){
			List<SecurityLogHash> retVal=new List<SecurityLogHash>();
			SecurityLogHash securityLogHash;
			for(int i=0;i<table.Rows.Count;i++) {
				securityLogHash=new SecurityLogHash();
				securityLogHash.SecurityLogHashNum= PIn.Long  (table.Rows[i]["SecurityLogHashNum"].ToString());
				securityLogHash.SecurityLogNum    = PIn.Long  (table.Rows[i]["SecurityLogNum"].ToString());
				securityLogHash.LogHash           = PIn.String(table.Rows[i]["LogHash"].ToString());
				retVal.Add(securityLogHash);
			}
			return retVal;
		}
Пример #2
0
 ///<summary>Inserts many SecurityLogHashs into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <SecurityLogHash> listSecurityLogHashs)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle || PrefC.RandomKeys)
     {
         foreach (SecurityLogHash securityLogHash in listSecurityLogHashs)
         {
             Insert(securityLogHash);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         while (index < listSecurityLogHashs.Count)
         {
             SecurityLogHash securityLogHash = listSecurityLogHashs[index];
             StringBuilder   sbRow           = new StringBuilder("(");
             bool            hasComma        = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO securityloghash (");
                 sbCommands.Append("SecurityLogNum,LogHash) VALUES ");
             }
             else
             {
                 hasComma = true;
             }
             sbRow.Append(POut.Long(securityLogHash.SecurityLogNum)); sbRow.Append(",");
             sbRow.Append("'" + POut.String(securityLogHash.LogHash) + "'"); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 if (index == listSecurityLogHashs.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
Пример #3
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SecurityLogHash> TableToList(DataTable table)
        {
            List <SecurityLogHash> retVal = new List <SecurityLogHash>();
            SecurityLogHash        securityLogHash;

            foreach (DataRow row in table.Rows)
            {
                securityLogHash = new SecurityLogHash();
                securityLogHash.SecurityLogHashNum = PIn.Long(row["SecurityLogHashNum"].ToString());
                securityLogHash.SecurityLogNum     = PIn.Long(row["SecurityLogNum"].ToString());
                securityLogHash.LogHash            = PIn.String(row["LogHash"].ToString());
                retVal.Add(securityLogHash);
            }
            return(retVal);
        }
Пример #4
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SecurityLogHash> TableToList(DataTable table)
        {
            List <SecurityLogHash> retVal = new List <SecurityLogHash>();
            SecurityLogHash        securityLogHash;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                securityLogHash = new SecurityLogHash();
                securityLogHash.SecurityLogHashNum = PIn.Long(table.Rows[i]["SecurityLogHashNum"].ToString());
                securityLogHash.SecurityLogNum     = PIn.Long(table.Rows[i]["SecurityLogNum"].ToString());
                securityLogHash.LogHash            = PIn.String(table.Rows[i]["LogHash"].ToString());
                retVal.Add(securityLogHash);
            }
            return(retVal);
        }
Пример #5
0
 ///<summary>Inserts one SecurityLogHash into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SecurityLogHash securityLogHash)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(securityLogHash, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             securityLogHash.SecurityLogHashNum = DbHelper.GetNextOracleKey("securityloghash", "SecurityLogHashNum");                  //Cacheless method
         }
         return(InsertNoCache(securityLogHash, true));
     }
 }
Пример #6
0
		///<summary>Inserts one SecurityLogHash into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(SecurityLogHash securityLogHash,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				securityLogHash.SecurityLogHashNum=ReplicationServers.GetKey("securityloghash","SecurityLogHashNum");
			}
			string command="INSERT INTO securityloghash (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="SecurityLogHashNum,";
			}
			command+="SecurityLogNum,LogHash) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(securityLogHash.SecurityLogHashNum)+",";
			}
			command+=
				     POut.Long  (securityLogHash.SecurityLogNum)+","
				+"'"+POut.String(securityLogHash.LogHash)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				securityLogHash.SecurityLogHashNum=Db.NonQ(command,true);
			}
			return securityLogHash.SecurityLogHashNum;
		}
Пример #7
0
		///<summary>Inserts one SecurityLogHash into the database.  Returns the new priKey.</summary>
		public static long Insert(SecurityLogHash securityLogHash){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				securityLogHash.SecurityLogHashNum=DbHelper.GetNextOracleKey("securityloghash","SecurityLogHashNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(securityLogHash,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							securityLogHash.SecurityLogHashNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(securityLogHash,false);
			}
		}
Пример #8
0
 ///<summary>Inserts one SecurityLogHash into the database.  Returns the new priKey.</summary>
 public static long Insert(SecurityLogHash securityLogHash)
 {
     return(Insert(securityLogHash, false));
 }
Пример #9
0
		///<summary>Updates one SecurityLogHash 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(SecurityLogHash securityLogHash,SecurityLogHash oldSecurityLogHash){
			string command="";
			if(securityLogHash.SecurityLogNum != oldSecurityLogHash.SecurityLogNum) {
				if(command!=""){ command+=",";}
				command+="SecurityLogNum = "+POut.Long(securityLogHash.SecurityLogNum)+"";
			}
			if(securityLogHash.LogHash != oldSecurityLogHash.LogHash) {
				if(command!=""){ command+=",";}
				command+="LogHash = '"+POut.String(securityLogHash.LogHash)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE securityloghash SET "+command
				+" WHERE SecurityLogHashNum = "+POut.Long(securityLogHash.SecurityLogHashNum);
			Db.NonQ(command);
			return true;
		}
Пример #10
0
		///<summary>Updates one SecurityLogHash in the database.</summary>
		public static void Update(SecurityLogHash securityLogHash){
			string command="UPDATE securityloghash SET "
				+"SecurityLogNum    =  "+POut.Long  (securityLogHash.SecurityLogNum)+", "
				+"LogHash           = '"+POut.String(securityLogHash.LogHash)+"' "
				+"WHERE SecurityLogHashNum = "+POut.Long(securityLogHash.SecurityLogHashNum);
			Db.NonQ(command);
		}