コード例 #1
0
        public object ExecuteScalar(string sql, params object[] parameters)
        {
            using (var cmd = CreateCommand())
            {
                QueryBuilder.BuildCommand(cmd, sql, parameters);
                MicrOrmLogger.LogCommand(cmd);
                using (var rdr = cmd.ExecuteReader())
                {
                    if (!rdr.Read())
                    {
                        return(null);
                    }

                    if (Convert.IsDBNull(0))
                    {
                        return(null);
                    }

                    try
                    {
                        return(Convert.ChangeType(rdr[0], rdr.GetFieldType(0)));
                    }
                    catch (InvalidCastException)
                    {
                        return(null);
                    }
                }
            }
        }
コード例 #2
0
 public void ExecuteNonQuery(string sql, params object[] parameters)
 {
     using (var cmd = CreateCommand())
     {
         QueryBuilder.BuildCommand(cmd, sql, parameters);
         MicrOrmLogger.LogCommand(cmd);
         cmd.ExecuteNonQuery();
     }
 }
コード例 #3
0
 public IEnumerable <IDictionary <string, object> > ExecuteReader(string sql, params object[] parameters)
 {
     using (var cmd = CreateCommand())
     {
         QueryBuilder.BuildCommand(cmd, sql, parameters);
         MicrOrmLogger.LogCommand(cmd);
         using (var rdr = cmd.ExecuteReader())
         {
             while (rdr.Read())
             {
                 yield return(FieldMapping.MapRowToDictionary(rdr));
             }
         }
     }
 }