Exemple #1
0
 public static System.Collections.Generic.Dictionary <string, object> GetTableCoulmns(string tableName, System.Collections.Generic.List <string> coulmns, System.Collections.Generic.Dictionary <string, object> primaryKeys, OracleDapperOld db)
 {
     System.Collections.Generic.Dictionary <string, object> dictionary = new System.Collections.Generic.Dictionary <string, object>(System.StringComparer.OrdinalIgnoreCase);
     if (coulmns.Count > 0 && primaryKeys.Count > 0)
     {
         DbCommand dbCommand = db.CreateCommand();
         System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
         stringBuilder.Append("SELECT ");
         int num = 0;
         foreach (string current in coulmns)
         {
             if (num > 0)
             {
                 stringBuilder.Append(",");
             }
             stringBuilder.Append(current);
             num++;
         }
         stringBuilder.AppendFormat(" FROM {0} ", tableName);
         num = 0;
         foreach (System.Collections.Generic.KeyValuePair <string, object> current2 in primaryKeys)
         {
             stringBuilder.Append((num == 0) ? " WHERE " : " AND ");
             string text = db.ParameterToken + "p_" + current2.Key;
             stringBuilder.AppendFormat(" {0} = {1} ", current2.Key, text);
             db.AddInParameter(dbCommand, text, DatabaseHelper.ObjectToDbType(current2.Value), current2.Value);
             num++;
         }
         dbCommand.CommandText = stringBuilder.ToString();
         dbCommand.CommandType = CommandType.Text;
         using (IDataReader dataReader = db.ExecuteReader(dbCommand))
         {
             if (dataReader.Read())
             {
                 for (int i = 0; i < dataReader.FieldCount; i++)
                 {
                     dictionary.Add(dataReader.GetName(i), dataReader[i]);
                 }
             }
         }
     }
     return(dictionary);
 }
Exemple #2
0
        public static bool TableInsert(System.Collections.Generic.Dictionary <string, object> coulmns, string tableName, OracleDapperOld db, DbTransaction t)
        {
            bool result = false;

            if (coulmns != null && coulmns.Count > 0)
            {
                DbCommand dbCommand = db.CreateCommand();
                dbCommand.CommandType = CommandType.Text;
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                stringBuilder.AppendFormat("Insert INTO {0} (", tableName);
                int num = 0;
                foreach (string current in coulmns.Keys)
                {
                    if (num > 0)
                    {
                        stringBuilder.Append(",");
                    }
                    stringBuilder.Append(current);
                    num++;
                }
                stringBuilder.Append(" ) VALUES ( ");
                num = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, object> current2 in coulmns)
                {
                    if (num > 0)
                    {
                        stringBuilder.Append(",");
                    }
                    string text = db.ParameterToken + "p_" + current2.Key;
                    stringBuilder.Append(text);
                    db.AddInParameter(dbCommand, text, DatabaseHelper.ObjectToDbType(current2.Value), current2.Value);
                    num++;
                }
                stringBuilder.Append(" )");
                dbCommand.CommandText = stringBuilder.ToString();
                result = ((t == null) ? (db.ExecuteNonQuery(dbCommand) > 0) : (db.ExecuteNonQuery(dbCommand, t) > 0));
            }
            return(result);
        }
Exemple #3
0
        public static bool TableUpdate(System.Collections.Generic.Dictionary <string, object> coulmns, System.Collections.Generic.Dictionary <string, object> primaryKeys, string tableName, OracleDapperOld db, DbTransaction t)
        {
            bool result = false;

            if (coulmns != null && coulmns.Count > 0 && primaryKeys != null && primaryKeys.Count > 0)
            {
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                DbCommand dbCommand = db.CreateCommand();
                dbCommand.CommandType = CommandType.Text;
                stringBuilder.AppendFormat("Update {0} SET ", tableName);
                int num = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, object> current in coulmns)
                {
                    if (num > 0)
                    {
                        stringBuilder.Append(",");
                    }
                    string text = db.ParameterToken + "pu_" + current.Key;
                    stringBuilder.AppendFormat(" {0} = {1}", current.Key, text);
                    db.AddInParameter(dbCommand, text, DatabaseHelper.ObjectToDbType(current.Value), current.Value);
                    num++;
                }
                num = 0;
                foreach (System.Collections.Generic.KeyValuePair <string, object> current in primaryKeys)
                {
                    stringBuilder.Append((num == 0) ? " WHERE " : " AND ");
                    string text = db.ParameterToken + "pw_" + current.Key;
                    stringBuilder.AppendFormat(" {0} = {1} ", current.Key, text);
                    db.AddInParameter(dbCommand, text, DatabaseHelper.ObjectToDbType(current.Value), current.Value);
                    num++;
                }
                dbCommand.CommandText = stringBuilder.ToString();
                result = ((t == null) ? (db.ExecuteNonQuery(dbCommand) > 0) : (db.ExecuteNonQuery(dbCommand, t) > 0));
            }
            return(result);
        }