1 // created on 3/5/2003 at 14:29
4 // Francisco Figueiredo Jr. <fxjrlists@yahoo.com>
6 // Copyright (C) 2002 The Npgsql Development Team
7 // npgsql-general@gborg.postgresql.org
8 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 using System.Web.UI.WebControls;
32 using NUnit.Framework;
39 public class DataAdapterTests
42 NpgsqlConnection _conn;
45 protected void SetUp()
47 //NpgsqlEventLog.Level = LogLevel.None;
48 //NpgsqlEventLog.Level = LogLevel.Debug;
49 //NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";
50 _conn = new NpgsqlConnection(TestConfiguration.NpgsqlConnectionString);
54 protected void TearDown()
56 if (_conn != null && _conn.State != ConnectionState.Closed)
61 public void InsertWithDataSet()
66 DataSet ds = new DataSet();
68 NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb", _conn);
70 da.InsertCommand = new NpgsqlCommand("insert into tableb(field_int2, field_timestamp, field_numeric) values (:a, :b, :c)", _conn);
72 da.InsertCommand.Parameters.Add(new NpgsqlParameter("a", DbType.Int16));
74 da.InsertCommand.Parameters.Add(new NpgsqlParameter("b", DbType.DateTime));
76 da.InsertCommand.Parameters.Add(new NpgsqlParameter("c", DbType.Decimal));
78 da.InsertCommand.Parameters[0].Direction = ParameterDirection.Input;
79 da.InsertCommand.Parameters[1].Direction = ParameterDirection.Input;
80 da.InsertCommand.Parameters[2].Direction = ParameterDirection.Input;
82 da.InsertCommand.Parameters[0].SourceColumn = "field_int2";
83 da.InsertCommand.Parameters[1].SourceColumn = "field_timestamp";
84 da.InsertCommand.Parameters[2].SourceColumn = "field_numeric";
90 DataTable dt = ds.Tables[0];
92 DataRow dr = dt.NewRow();
94 dr["field_timestamp"] = new DateTime(2003, 03, 03, 14, 0, 0);
95 dr["field_numeric"] = 7.3M;
100 DataSet ds2 = ds.GetChanges();
108 NpgsqlDataReader dr2 = new NpgsqlCommand("select * from tableb where field_serial > 4", _conn).ExecuteReader();
112 Assert.AreEqual(4, dr2[1]);
113 Assert.AreEqual(7.3000000M, dr2[3]);
115 new NpgsqlCommand("delete from tableb where field_serial > 4", _conn).ExecuteNonQuery();
122 public void FillWithEmptyResultset()
127 DataSet ds = new DataSet();
129 NpgsqlDataAdapter da = new NpgsqlDataAdapter("select * from tableb where field_serial = -1", _conn);
134 Assert.AreEqual(1, ds.Tables.Count);
135 Assert.AreEqual(4, ds.Tables[0].Columns.Count);
136 Assert.AreEqual("field_serial", ds.Tables[0].Columns[0].ColumnName);
137 Assert.AreEqual("field_int2", ds.Tables[0].Columns[1].ColumnName);
138 Assert.AreEqual("field_timestamp", ds.Tables[0].Columns[2].ColumnName);
139 Assert.AreEqual("field_numeric", ds.Tables[0].Columns[3].ColumnName);
144 public void FillWithDuplicateColumnName()
147 DataSet ds = new DataSet();
149 NpgsqlDataAdapter da = new NpgsqlDataAdapter("select field_serial, field_serial from tableb", _conn);