Esempio n. 1
0
        public void TestInsert()
        {
            var students = StudentHelper.CreateSample(10).ToArray();
            using (var sqlConnection = DatabaseHelper.OpenSqlConnection(DatabaseName))
            {
                var sqlUpserter = new SqlUpserter<Student>(StudentMapper, TableName, students);
                sqlUpserter.Execute(sqlConnection);

                var selectText = "SELECT " + string.Join(",", StudentMapper.Columns.Select(column => column.Name)) +
                                 " FROM " + TableName;
                var reader = new SqlCommand(selectText, sqlConnection).ExecuteReader();
                var row = 0;
                while (reader.Read())
                {
                    var student = students[row];
                    for (var column = 0; column < reader.FieldCount; column++)
                    {
                        var expected = StudentMapper.GetValueAt(column, student);
                        var actual = reader.GetValue(column);
                        Assert.AreEqual(expected, actual);
                    }
                    row++;
                }
            }
        }
Esempio n. 2
0
        public DateTime GetDateModifiedUtc(int id, string filename)
        {
            //this.FireAuthorizeEvent(id);
            SqlConnection connectionObj = this.GetConnectionObj();
            connectionObj.Open();
            DateTime result;

            using (connectionObj)
            {
                SqlDataReader sqlDataReader = new SqlCommand(this.modifiedDateQuery, connectionObj)
                {
                    Parameters =
                    {
                        CreateParameter("id", id, SqlDbType.Int),
                        CreateParameter("name", filename, SqlDbType.NVarChar)
                    }
                }.ExecuteReader();

                using (sqlDataReader)
                {
                    if (!sqlDataReader.Read())
                    {
                        result = DateTime.MinValue;
                        return result;
                    }
                    for (var i = 0; i < sqlDataReader.FieldCount; i++)
                    {
                        if (!sqlDataReader.IsDBNull(i) && sqlDataReader.GetValue(i) is DateTime)
                        {
                            result = (DateTime)sqlDataReader.GetValue(i);
                            return result;
                        }
                    }
                }
            }

            return DateTime.MinValue;
        }
Esempio n. 3
0
        public void TestUpdate()
        {
            var students = StudentHelper.CreateSample(10).ToArray();
            using (var sqlConnection = DatabaseHelper.OpenSqlConnection(DatabaseName))
            {
                var sqlUpserter1 = new SqlUpserter<Student>(StudentMapper, TableName, students);
                sqlUpserter1.Execute(sqlConnection);

                var expectedChanges = 0;
                foreach (var student in students)
                {
                    if (student.Id%2 == 0)
                    {
                        student.FirstName = student.FirstName + "_Changed";
                        expectedChanges++;
                    }
                }

                var sqlUpserter2 = new SqlUpserter<Student>(StudentMapper, TableName, students);
                sqlUpserter2.Execute(sqlConnection);

                var selectText = "SELECT " + string.Join(",", StudentMapper.Columns.Select(column => column.Name)) +
                                 " FROM " + TableName;
                var reader = new SqlCommand(selectText, sqlConnection).ExecuteReader();
                var row = 0;
                var currentChanges = 0;
                while (reader.Read())
                {
                    var student = students[row];
                    for (var column = 0; column < reader.FieldCount; column++)
                    {
                        var expected = StudentMapper.GetValueAt(column, student);
                        var actual = reader.GetValue(column);
                        if (actual.ToString().EndsWith("_Changed"))
                        {
                            currentChanges++;
                        }
                        Assert.AreEqual(expected, actual);
                    }
                    row++;
                }
                Assert.AreEqual(expectedChanges, currentChanges);
            }
        }
Esempio n. 4
0
 public virtual object[] getDataAry(string argString)
 {
     this.rState = 0;
     string cmdText = argString;
     object[] objArray = null;
     try
     {
         SqlConnection connection = new SqlConnection(this.connStr);
         connection.Open();
         SqlDataReader reader = new SqlCommand(cmdText, connection).ExecuteReader();
         int fieldCount = reader.FieldCount;
         object[,] objArray2 = null;
         while (reader.Read())
         {
             objArray2 = new object[fieldCount, 2];
             for (int i = 0; i < fieldCount; i++)
             {
                 objArray2[i, 0] = reader.GetName(i);
                 objArray2[i, 1] = reader.GetValue(i);
             }
             objArray = cls.mergeAry(objArray, objArray2);
         }
         reader.Close();
         connection.Close();
     }
     catch (Exception exception)
     {
         this.rState = 1;
         objArray = null;
         this.eMessage = exception.Message;
     }
     return objArray;
 }
Esempio n. 5
0
 private void cbOrder_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (SqlConnection connection = new SqlConnection(MainForm.STRCONN))
     {
         connection.Open();
         OrderBy orderBy = (OrderBy)cbOrderBy.SelectedItem;
         string q = String.Format("SELECT Country,League,Season{0} FROM dbo.Leagues ORDER BY {1} {2}",
             orderBy.SelectCol == "" ? "" : "," + orderBy.SelectCol, orderBy.OrderCol, cbOrderDir.SelectedItem);
         LeaguesKey lKey;
         lbLeagues.Items.Clear();
         using (SqlDataReader reader = new SqlCommand(q, connection).ExecuteReader())
         {
             while (reader.Read())
             {
                 lKey = new LeaguesKey();
                 lKey.Country = reader.GetString(0);
                 lKey.League = reader.GetString(1);
                 lKey.Season = reader.GetString(2);
                 if (reader.FieldCount >= 4) lKey.ExtraCol = reader.GetValue(3);
                 lbLeagues.Items.Add(lKey);
             }
         }
     }
 }