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 private NpgsqlConnection _conn
= null;
43 private String _connString
= "Server=localhost;User ID=npgsql_tests;Password=npgsql_tests;Database=npgsql_tests;maxpoolsize=2;";
46 protected void SetUp()
48 //NpgsqlEventLog.Level = LogLevel.None;
49 //NpgsqlEventLog.Level = LogLevel.Debug;
50 //NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";
51 _conn
= new NpgsqlConnection(_connString
);
55 protected void TearDown()
57 if (_conn
.State
!= ConnectionState
.Closed
)
62 public void InsertWithDataSet()
67 DataSet ds
= new DataSet();
69 NpgsqlDataAdapter da
= new NpgsqlDataAdapter("select * from tableb", _conn
);
71 da
.InsertCommand
= new NpgsqlCommand("insert into tableb(field_int2, field_timestamp, field_numeric) values (:a, :b, :c)", _conn
);
73 da
.InsertCommand
.Parameters
.Add(new NpgsqlParameter("a", DbType
.Int16
));
75 da
.InsertCommand
.Parameters
.Add(new NpgsqlParameter("b", DbType
.DateTime
));
77 da
.InsertCommand
.Parameters
.Add(new NpgsqlParameter("c", DbType
.Decimal
));
79 da
.InsertCommand
.Parameters
[0].Direction
= ParameterDirection
.Input
;
80 da
.InsertCommand
.Parameters
[1].Direction
= ParameterDirection
.Input
;
81 da
.InsertCommand
.Parameters
[2].Direction
= ParameterDirection
.Input
;
83 da
.InsertCommand
.Parameters
[0].SourceColumn
= "field_int2";
84 da
.InsertCommand
.Parameters
[1].SourceColumn
= "field_timestamp";
85 da
.InsertCommand
.Parameters
[2].SourceColumn
= "field_numeric";
91 DataTable dt
= ds
.Tables
[0];
93 DataRow dr
= dt
.NewRow();
95 dr
["field_timestamp"] = new DateTime(2003, 03, 03, 14, 0, 0);
96 dr
["field_numeric"] = 7.3M
;
101 DataSet ds2
= ds
.GetChanges();
109 NpgsqlDataReader dr2
= new NpgsqlCommand("select * from tableb where field_serial > 4", _conn
).ExecuteReader();
113 Assert
.AreEqual(4, dr2
[1]);
114 Assert
.AreEqual(7.3000000M
, dr2
[3]);
116 new NpgsqlCommand("delete from tableb where field_serial > 4", _conn
).ExecuteNonQuery();
123 public void FillWithEmptyResultset()
128 DataSet ds
= new DataSet();
130 NpgsqlDataAdapter da
= new NpgsqlDataAdapter("select * from tableb where field_serial = -1", _conn
);
135 Assert
.AreEqual(1, ds
.Tables
.Count
);
136 Assert
.AreEqual(4, ds
.Tables
[0].Columns
.Count
);
137 Assert
.AreEqual("field_serial", ds
.Tables
[0].Columns
[0].ColumnName
);
138 Assert
.AreEqual("field_int2", ds
.Tables
[0].Columns
[1].ColumnName
);
139 Assert
.AreEqual("field_timestamp", ds
.Tables
[0].Columns
[2].ColumnName
);
140 Assert
.AreEqual("field_numeric", ds
.Tables
[0].Columns
[3].ColumnName
);
145 public void FillWithDuplicateColumnName()
148 DataSet ds
= new DataSet();
150 NpgsqlDataAdapter da
= new NpgsqlDataAdapter("select field_serial, field_serial from tableb", _conn
);