Beispiel #1
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="fieldCollent"></param>
        /// <param name="fieldValueCollect"></param>
        /// <param name="Condition"></param>
        /// <returns></returns>
        protected override long __Update(string TableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect, string Condition)
        {
            if (DatabaseReadOnlyState)
            {
                return(-9999);
            }

            if ((fieldCollent == null) || (fieldCollent.Count < 1))
            {
                throw new Exception("the fieldCollent can't is null.");
            }

            if ((fieldValueCollect == null) || (fieldValueCollect.Count < 1))
            {
                throw new Exception("the fieldValueCollect can't is null.");
            }

            if (fieldCollent.Count != fieldValueCollect.Count)
            {
                throw new Exception("fieldCollent and fieldValueCollect's Number of inconsistencies.");
            }

            TableName = ReplaceDefinitionForObjectName(TableName);

            string CommandString = "update " + TableName + " set ";

            int ParameterCount = 0;

            for (int i = 0; i < fieldCollent.Count; i++)
            {
                string FieldName  = ReplaceDefinitionForObjectName(fieldCollent[i]);
                object FieldValue = fieldValueCollect[i];

                CommandString += ((i > 0) ? ", " : "") + FieldName + " = ";

                if (FieldValue is FieldValueCalculate)
                {
                    CommandString += ((FieldValueCalculate)FieldValue).ToString();
                }
                else
                {
                    CommandString += "@p" + ParameterCount.ToString();
                    ParameterCount++;
                }
            }

            Condition = Condition.Trim();
            Condition = String.IsNullOrEmpty(Condition) ? "" : FilteSqlInfusionForCondition(ReplaceDefinitionForStatement(Condition));

            if (!String.IsNullOrEmpty(Condition))
            {
                CommandString += " where " + Condition;
            }

            CommandString += "; select ifnull(changes(), -99999999);";

            SQLiteCommand Cmd = new SQLiteCommand(CommandString, (SQLiteConnection)connection);

            ParameterCount = 0;

            for (int i = 0; i < fieldValueCollect.Count; i++)
            {
                object FieldValue = fieldValueCollect[i];

                if (FieldValue is FieldValueCalculate)
                {
                    continue;
                }

                SQLiteParameter p = new SQLiteParameter("@p" + ParameterCount.ToString(), (FieldValue == null ? System.DBNull.Value : (String.IsNullOrEmpty(FieldValue.ToString()) ? System.DBNull.Value : FieldValue)));
                Cmd.Parameters.Add(p);

                ParameterCount++;
            }

            if (transcation != null)
            {
                Cmd.Transaction = (SQLiteTransaction)transcation;
            }

            WriteCommandToLogger(4, CommandString + "\tParameterCount: " + ParameterCount.ToString());

            object objResult = Cmd.ExecuteScalar();
            long   Result    = System.Convert.ToInt64(objResult);

            if (Result == -99999999)
            {
                return(0);
            }

            return(Result);
        }
Beispiel #2
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieldCollent"></param>
        /// <param name="fieldValueCollect"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        protected override long __Update(string tableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect, string condition)
        {
            if ((fieldCollent == null) || (fieldCollent.Count < 1))
            {
                throw new Exception("the fieldCollent can't is null.");
            }

            if ((fieldValueCollect == null) || (fieldValueCollect.Count < 1))
            {
                throw new Exception("the fieldValueCollect can't is null.");
            }

            if (fieldCollent.Count != fieldValueCollect.Count)
            {
                throw new Exception("fieldCollent and fieldValueCollect's Number of inconsistencies.");
            }

            tableName = ReplaceDefinitionForObjectName(tableName);

            string commandString = "update " + tableName + " set ";

            int parameterCount = 0;

            for (int i = 0; i < fieldCollent.Count; i++)
            {
                string FieldName  = ReplaceDefinitionForObjectName(fieldCollent[i]);
                object FieldValue = fieldValueCollect[i];

                commandString += ((i > 0) ? ", " : "") + FieldName + " = ";

                if (FieldValue is FieldValueCalculate)
                {
                    commandString += ((FieldValueCalculate)FieldValue).ToString();
                }
                else
                {
                    commandString += "?p" + parameterCount.ToString();
                    parameterCount++;
                }
            }

            condition = condition.Trim();
            condition = string.IsNullOrEmpty(condition) ? "" : FilteSqlInfusionForCondition(ReplaceDefinitionForStatement(condition));

            if (!string.IsNullOrEmpty(condition))
            {
                commandString += " where " + condition;
            }

            commandString += "; select ifnull(ROW_COUNT(), -99999999)";

            MySqlCommand cmd = new MySqlCommand(commandString, (MySqlConnection)connection);

            parameterCount = 0;

            for (int i = 0; i < fieldValueCollect.Count; i++)
            {
                object FieldValue = fieldValueCollect[i];

                if (FieldValue is FieldValueCalculate)
                {
                    continue;
                }

                MySqlParameter p = new MySqlParameter("?p" + parameterCount.ToString(), (FieldValue == null ? System.DBNull.Value : (string.IsNullOrEmpty(FieldValue.ToString()) ? System.DBNull.Value : FieldValue)));
                cmd.Parameters.Add(p);

                parameterCount++;
            }

            if (transcation != null)
            {
                cmd.Transaction = (MySqlTransaction)transcation;
            }

            object objResult = cmd.ExecuteScalar();
            long   result    = System.Convert.ToInt64(objResult);

            if (result == -99999999)
            {
                return(0);
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="TableName"></param>
        /// <param name="fieldCollent"></param>
        /// <param name="fieldValueCollect"></param>
        /// <returns></returns>
        protected override long __Insert(string TableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect)
        {
            if (DatabaseReadOnlyState)
            {
                return(-9999);
            }

            if ((fieldCollent == null) || (fieldCollent.Count < 1))
            {
                throw new Exception("the fieldCollent can't is null.");
            }

            if ((fieldValueCollect == null) || (fieldValueCollect.Count < 1))
            {
                throw new Exception("the fieldValueCollect can't is null.");
            }

            if (fieldCollent.Count != fieldValueCollect.Count)
            {
                throw new Exception("fieldCollent and fieldValueCollect's Number of inconsistencies.");
            }

            TableName = ReplaceDefinitionForObjectName(TableName);

            string CommandString = "insert into " + TableName + " (";

            for (int i = 0; i < fieldCollent.Count; i++)
            {
                string FieldName = ReplaceDefinitionForObjectName(fieldCollent[i]);

                CommandString += (FieldName + ((i == (fieldCollent.Count - 1)) ? ") values (" : ", "));
            }

            int ParameterCount = 0;

            for (int i = 0; i < fieldValueCollect.Count; i++)
            {
                CommandString += (i > 0) ? ", " : "";
                object FieldValue = fieldValueCollect[i];

                if (FieldValue is FieldValueCalculate)
                {
                    throw new Exception("Insert method does not support FieldValueCalculate.");
                }

                if (FieldValue is FieldValueCalculate)
                {
                    CommandString += ((FieldValueCalculate)FieldValue).ToString();
                }
                else
                {
                    CommandString += "@p" + ParameterCount.ToString();
                    ParameterCount++;
                }
            }

            CommandString += "); select ifnull(last_insert_rowid(), -99999999);";

            SQLiteCommand Cmd = new SQLiteCommand(CommandString, (SQLiteConnection)connection);

            ParameterCount = 0;
            for (int i = 0; i < fieldValueCollect.Count; i++)
            {
                object FieldValue = fieldValueCollect[i];

                if (FieldValue is FieldValueCalculate)
                {
                    continue;
                }

                SQLiteParameter p = new SQLiteParameter("@p" + ParameterCount.ToString(), (FieldValue == null ? System.DBNull.Value : (String.IsNullOrEmpty(FieldValue.ToString()) ? System.DBNull.Value : FieldValue)));
                Cmd.Parameters.Add(p);

                ParameterCount++;
            }

            if (transcation != null)
            {
                Cmd.Transaction = (SQLiteTransaction)transcation;
            }

            WriteCommandToLogger(3, CommandString + "\tParameterCount: " + ParameterCount.ToString());

            object objResult = Cmd.ExecuteScalar();
            long   Result    = System.Convert.ToInt64(objResult);

            if (Result == -99999999)
            {
                return(0);
            }

            return(Result);
        }
Beispiel #4
0
        /// <summary>
        /// Insert
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieldCollent"></param>
        /// <param name="fieldValueCollect"></param>
        /// <returns></returns>
        protected override long __Insert(string tableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect)
        {
            if ((fieldCollent == null) || (fieldCollent.Count < 1))
            {
                throw new Exception("the fieldCollent can't is null.");
            }

            if ((fieldValueCollect == null) || (fieldValueCollect.Count < 1))
            {
                throw new Exception("the fieldValueCollect can't is null.");
            }

            if (fieldCollent.Count != fieldValueCollect.Count)
            {
                throw new Exception("fieldCollent and fieldValueCollect's Number of inconsistencies.");
            }

            tableName = ReplaceDefinitionForObjectName(tableName);

            string commandString = "insert into " + tableName + " (";

            for (int i = 0; i < fieldCollent.Count; i++)
            {
                string FieldName = ReplaceDefinitionForObjectName(fieldCollent[i]);

                commandString += (FieldName + ((i == (fieldCollent.Count - 1)) ? ") values (" : ", "));
            }

            int parameterCount = 0;

            for (int i = 0; i < fieldValueCollect.Count; i++)
            {
                commandString += (i > 0) ? ", " : "";
                object FieldValue = fieldValueCollect[i];

                if (FieldValue is FieldValueCalculate)
                {
                    throw new Exception("Insert method does not support FieldValueCalculate.");
                }

                if (FieldValue is FieldValueCalculate)
                {
                    commandString += ((FieldValueCalculate)FieldValue).ToString();
                }
                else
                {
                    commandString += "?p" + parameterCount.ToString();
                    parameterCount++;
                }
            }

            commandString += "); select ifnull(LAST_INSERT_ID(), -99999999);";

            MySqlCommand cmd = new MySqlCommand(commandString, (MySqlConnection)connection);

            parameterCount = 0;

            for (int i = 0; i < fieldValueCollect.Count; i++)
            {
                object FieldValue = fieldValueCollect[i];

                if (FieldValue is FieldValueCalculate)
                {
                    continue;
                }

                MySqlParameter p = new MySqlParameter("?p" + parameterCount.ToString(), (FieldValue == null ? System.DBNull.Value : (string.IsNullOrEmpty(FieldValue.ToString()) ? System.DBNull.Value : FieldValue)));
                cmd.Parameters.Add(p);

                parameterCount++;
            }

            if (transcation != null)
            {
                cmd.Transaction = (MySqlTransaction)transcation;
            }

            object objResult = cmd.ExecuteScalar();
            long   result    = System.Convert.ToInt64(objResult);

            if (result == -99999999)
            {
                return(0);
            }

            return(result);
        }
Beispiel #5
0
 /// <summary>
 /// 更新记录
 /// </summary>
 /// <param name="TableName"></param>
 /// <param name="fieldCollent"></param>
 /// <param name="fieldValueCollect"></param>
 /// <param name="Condition"></param>
 /// <returns></returns>
 public long Update(string TableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect, string Condition)
 {
     return(this.__Update(TableName, fieldCollent, fieldValueCollect, Condition));
 }
Beispiel #6
0
 /// <summary>
 /// 更新记录
 /// </summary>
 /// <param name="TableName"></param>
 /// <param name="fieldCollent"></param>
 /// <param name="fieldValueCollect"></param>
 /// <param name="Condition"></param>
 /// <returns></returns>
 protected virtual long __Update(string TableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect, string Condition)
 {
     return(0);
 }
Beispiel #7
0
 /// <summary>
 /// 插入记录
 /// </summary>
 /// <param name="TableName"></param>
 /// <param name="fieldCollent"></param>
 /// <param name="fieldValueCollect"></param>
 /// <returns></returns>
 public long Insert(string TableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect)
 {
     return(this.__Insert(TableName, fieldCollent, fieldValueCollect));
 }
Beispiel #8
0
 /// <summary>
 /// 插入记录
 /// </summary>
 /// <param name="TableName"></param>
 /// <param name="fieldCollent"></param>
 /// <param name="fieldValueCollect"></param>
 /// <returns></returns>
 protected virtual long __Insert(string TableName, FieldCollect fieldCollent, FieldValueCollect fieldValueCollect)
 {
     return(0);
 }