Exemple #1
0
        ///<summary>Inserts one SmsBlockPhone into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(SmsBlockPhone smsBlockPhone, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO smsblockphone (";

            if (!useExistingPK && isRandomKeys)
            {
                smsBlockPhone.SmsBlockPhoneNum = ReplicationServers.GetKeyNoCache("smsblockphone", "SmsBlockPhoneNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "SmsBlockPhoneNum,";
            }
            command += "BlockWirelessNumber) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(smsBlockPhone.SmsBlockPhoneNum) + ",";
            }
            command +=
                "'" + POut.String(smsBlockPhone.BlockWirelessNumber) + "')";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                smsBlockPhone.SmsBlockPhoneNum = Db.NonQ(command, true, "SmsBlockPhoneNum", "smsBlockPhone");
            }
            return(smsBlockPhone.SmsBlockPhoneNum);
        }
Exemple #2
0
        ///<summary>Inserts one SmsBlockPhone into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(SmsBlockPhone smsBlockPhone, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                smsBlockPhone.SmsBlockPhoneNum = ReplicationServers.GetKey("smsblockphone", "SmsBlockPhoneNum");
            }
            string command = "INSERT INTO smsblockphone (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "SmsBlockPhoneNum,";
            }
            command += "BlockWirelessNumber) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(smsBlockPhone.SmsBlockPhoneNum) + ",";
            }
            command +=
                "'" + POut.String(smsBlockPhone.BlockWirelessNumber) + "')";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                smsBlockPhone.SmsBlockPhoneNum = Db.NonQ(command, true, "SmsBlockPhoneNum", "smsBlockPhone");
            }
            return(smsBlockPhone.SmsBlockPhoneNum);
        }
 ///<summary>Inserts one SmsBlockPhone into the database.  Returns the new priKey.</summary>
 public static long Insert(SmsBlockPhone smsBlockPhone)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         smsBlockPhone.SmsBlockPhoneNum = DbHelper.GetNextOracleKey("smsblockphone", "SmsBlockPhoneNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(smsBlockPhone, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     smsBlockPhone.SmsBlockPhoneNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(smsBlockPhone, false));
     }
 }
Exemple #4
0
 ///<summary>Returns true if Update(SmsBlockPhone,SmsBlockPhone) 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(SmsBlockPhone smsBlockPhone, SmsBlockPhone oldSmsBlockPhone)
 {
     if (smsBlockPhone.BlockWirelessNumber != oldSmsBlockPhone.BlockWirelessNumber)
     {
         return(true);
     }
     return(false);
 }
Exemple #5
0
        ///<summary>Updates one SmsBlockPhone in the database.</summary>
        public static void Update(SmsBlockPhone smsBlockPhone)
        {
            string command = "UPDATE smsblockphone SET "
                             + "BlockWirelessNumber= '" + POut.String(smsBlockPhone.BlockWirelessNumber) + "' "
                             + "WHERE SmsBlockPhoneNum = " + POut.Long(smsBlockPhone.SmsBlockPhoneNum);

            Db.NonQ(command);
        }
Exemple #6
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SmsBlockPhone> TableToList(DataTable table)
        {
            List <SmsBlockPhone> retVal = new List <SmsBlockPhone>();
            SmsBlockPhone        smsBlockPhone;

            foreach (DataRow row in table.Rows)
            {
                smsBlockPhone = new SmsBlockPhone();
                smsBlockPhone.SmsBlockPhoneNum    = PIn.Long(row["SmsBlockPhoneNum"].ToString());
                smsBlockPhone.BlockWirelessNumber = PIn.String(row["BlockWirelessNumber"].ToString());
                retVal.Add(smsBlockPhone);
            }
            return(retVal);
        }
 ///<summary>Inserts one SmsBlockPhone into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SmsBlockPhone smsBlockPhone)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(smsBlockPhone, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             smsBlockPhone.SmsBlockPhoneNum = DbHelper.GetNextOracleKey("smsblockphone", "SmsBlockPhoneNum");                  //Cacheless method
         }
         return(InsertNoCache(smsBlockPhone, true));
     }
 }
Exemple #8
0
        ///<summary>Updates one SmsBlockPhone 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(SmsBlockPhone smsBlockPhone, SmsBlockPhone oldSmsBlockPhone)
        {
            string command = "";

            if (smsBlockPhone.BlockWirelessNumber != oldSmsBlockPhone.BlockWirelessNumber)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "BlockWirelessNumber = '" + POut.String(smsBlockPhone.BlockWirelessNumber) + "'";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE smsblockphone SET " + command
                      + " WHERE SmsBlockPhoneNum = " + POut.Long(smsBlockPhone.SmsBlockPhoneNum);
            Db.NonQ(command);
            return(true);
        }
Exemple #9
0
 ///<summary>Inserts one SmsBlockPhone into the database.  Returns the new priKey.</summary>
 public static long Insert(SmsBlockPhone smsBlockPhone)
 {
     return(Insert(smsBlockPhone, false));
 }