Exemplo n.º 1
0
        public void PqsqlTypeRegistryTest1()
        {
            PqsqlTransaction tran   = mConnection.BeginTransaction();
            string           old_tz = mConnection.TimeZone;

            mCmd.CommandText = "set timezone to 'Asia/Hong_Kong';" +
                               "select localtimestamp, now(), now() at time zone 'Europe/Vienna', '2016-10-01 12:00:00' at time zone 'UTC', '2016-10-01 12:00:00' at time zone 'Europe/Vienna', utc_offset from pg_timezone_names where name = current_setting('TIMEZONE');";
            mCmd.CommandType = CommandType.Text;

            PqsqlDataReader reader = mCmd.ExecuteReader();

            bool read = reader.Read();

            Assert.IsFalse(read);

            string new_tz = mConnection.TimeZone;

            Assert.AreNotEqual(old_tz, new_tz);

            bool hasnext = reader.NextResult();

            Assert.IsTrue(hasnext);

            read = reader.Read();
            Assert.IsTrue(read);

            DateTime now0 = reader.GetDateTime(0);
            DateTime now1 = reader.GetDateTime(1);
            DateTime now2 = reader.GetDateTime(2);
            DateTime now3 = reader.GetDateTime(3);
            DateTime now4 = reader.GetDateTime(4);
            TimeSpan ts   = reader.GetTimeSpan(5);

            reader.Close();

            DateTime nowutc0 = now0.ToUniversalTime();

            TimeZoneInfo tzi_from_china_pgsql = TimeZoneInfo.CreateCustomTimeZone(new_tz, ts, new_tz, new_tz);

#if WIN32
            var tz = "China Standard Time";
#else
            var tz = "Asia/Shanghai";
#endif
            TimeZoneInfo tzi_from_china_sys = TimeZoneInfo.FindSystemTimeZoneById(tz);

            TimeSpan       china_off = tzi_from_china_sys.GetUtcOffset(nowutc0);
            TimeSpan       local_off = TimeZoneInfo.Local.GetUtcOffset(nowutc0);
            DateTimeOffset nowlocal0 = (nowutc0 + local_off - china_off).ToLocalTime();

            DateTimeOffset dto_from_pgsql_to_sys       = TimeZoneInfo.ConvertTime(now0, tzi_from_china_pgsql, tzi_from_china_sys);
            DateTimeOffset dto_from_pgsql_to_localtime = TimeZoneInfo.ConvertTime(now0, tzi_from_china_pgsql, TimeZoneInfo.Local);

            Assert.AreEqual(nowutc0, dto_from_pgsql_to_sys);
            Assert.AreEqual(nowlocal0, dto_from_pgsql_to_localtime);

            tran.Rollback();
        }
Exemplo n.º 2
0
        public void PqsqlTypeRegistryTest6()
        {
            Action[] actions = new Action[20];

            // stress test user-defined type setup
            for (int i = 0; i < 20; i++)
            {
                actions[i] = () =>
                {
                    using (PqsqlConnection conn = new PqsqlConnection(mConnection.ConnectionString))
                        using (PqsqlCommand cmd = new PqsqlCommand("select 'hello world'::citext", conn))
                            using (PqsqlDataReader reader = cmd.ExecuteReader())
                            {
                                bool read = reader.Read();
                                Assert.IsTrue(read);
                                object helloWorld = reader.GetValue(0);                 // must access by GetValue, GetString verifies typoid
                                Assert.AreEqual("hello world", helloWorld);
                                read = reader.Read();
                                Assert.IsFalse(read);
                            }
                };
            }

            using (PqsqlCommand check = new PqsqlCommand("select oid from pg_extension where extname='citext'", mConnection))
                using (PqsqlCommand create = new PqsqlCommand("create extension citext", mConnection))
                    using (PqsqlTransaction t = mConnection.BeginTransaction())
                    {
                        object o = null;

                        try
                        {
                            check.Transaction = t;
                            o = check.ExecuteScalar();

                            if (o == null)
                            {
                                create.Transaction = t;
                                int aff = create.ExecuteNonQuery();
                                Assert.AreEqual(0, aff);
                            }

                            t.Commit();

                            Parallel.Invoke(actions);
                        }
                        finally
                        {
                            if (o == null)
                            {
                                using (PqsqlCommand drop = new PqsqlCommand("drop extension if exists citext", mConnection))
                                {
                                    int aff = drop.ExecuteNonQuery();
                                    Assert.AreEqual(0, aff);
                                }
                            }
                        }
                    }
        }
Exemplo n.º 3
0
        public void PqsqlDataReaderTest10()
        {
            mCmd.CommandText = @"select timestamp 'now', date 'now', time 'now';";

            TimeSpan time = DateTime.UtcNow.TimeOfDay;

            using (PqsqlDataReader reader = mCmd.ExecuteReader())
            {
                Assert.IsTrue(reader.HasRows);

                reader.Read();

                DateTime c0 = reader.GetDateTime(0);
                DateTime c1 = reader.GetDateTime(1);
                DateTime c2 = reader.GetDateTime(2);

                Assert.AreEqual(DateTime.Today, c0 - c0.TimeOfDay);
                Assert.AreEqual(DateTime.Today, c1);

                // only compare hours and minutes
                Assert.AreEqual(time.Hours, c2.TimeOfDay.Hours);
                Assert.AreEqual(time.Minutes, c2.TimeOfDay.Minutes);

                reader.Close();
            }
        }
Exemplo n.º 4
0
        public void PqsqlCommandTest2()
        {
            PqsqlCommand cmd = mConnection.CreateCommand();

            cmd.CommandText = "bit_length";
            cmd.CommandType = CommandType.StoredProcedure;

            IDbDataParameter i = cmd.CreateParameter();

            i.ParameterName = "i";
            i.Value         = "postgres";
            cmd.Parameters.Add(i);

            IDbDataParameter o = cmd.CreateParameter();

            o.ParameterName = "bit_length";
            o.Direction     = ParameterDirection.Output;
            cmd.Parameters.Add(o);

            PqsqlDataReader r = cmd.ExecuteReader();

            bool b = r.Read();

            Assert.AreEqual(true, b);

            Assert.AreEqual(64, o.Value);
        }
Exemplo n.º 5
0
        //
        // Summary:
        //     Executes a SQL statement against a connection object.
        //
        // Returns:
        //     The number of rows affected.
        public override int ExecuteNonQuery()
        {
            PqsqlDataReader r = ExecuteReader(CommandBehavior.Default);

            // fill OUT and INOUT parameters with result tuple from the first row
            if (CommandType == CommandType.StoredProcedure)
            {
                r.Read();                 // reading the first row will fill output parameters
            }

            int ra = Math.Max(-1, r.RecordsAffected);

            r.Consume();                                                                       // sync protocol: consume remaining rows

            if ((mCmdBehavior & CommandBehavior.SingleResult) == CommandBehavior.SingleResult) // only one statement available
            {
                return(ra);
            }

            // we have more than one statement
            while (r.NextResult())
            {
                int n = r.RecordsAffected;

                // accumulate positive RecordsAffected for each UPDATE / DELETE / INSERT / CREATE * / ... statement
                if (n >= 0)
                {
                    if (ra < 0)
                    {
                        ra = n;
                    }
                    else                     // ra >= 0
                    {
                        ra += n;
                    }
                }

                r.Consume();                 // sync protocol: consume remaining rows
            }

            int last = r.RecordsAffected;

            // accumulate positive RecordsAffected for each UPDATE / DELETE / INSERT / CREATE * / ... statement
            if (last >= 0)
            {
                if (ra < 0)
                {
                    ra = last;
                }
                else                 // ra >= 0
                {
                    ra += last;
                }
            }

            r.Consume();             // sync protocol: consume remaining rows

            return(ra);
        }
Exemplo n.º 6
0
        public void PqsqlTypeRegistryTest2()
        {
            mCmd.CommandText = "select localtimestamp, now()::timestamp, now(), now() at time zone 'UTC', '1999-01-01 00:00:00'::timestamp at time zone 'UTC', '2000-07-01 00:00:00'::timestamp at time zone 'Europe/Vienna'";
            mCmd.CommandType = CommandType.Text;

            PqsqlDataReader reader = mCmd.ExecuteReader();

            bool read = reader.Read();

            Assert.IsTrue(read);

            DateTime       localtimestamp0    = reader.GetDateTime(0);
            DateTimeOffset localtimestampoff0 = reader.GetDateTimeOffset(0);

            DateTime       nownotz1    = reader.GetDateTime(1);
            DateTimeOffset nownotzoff1 = reader.GetDateTimeOffset(1);

            DateTime       nowtz2    = reader.GetDateTime(2);
            DateTimeOffset nowtzoff2 = reader.GetDateTimeOffset(2);

            DateTime       nowutc3    = reader.GetDateTime(3);
            DateTimeOffset nowutcoff3 = reader.GetDateTimeOffset(3);

            DateTime       ts19990101000000_4    = reader.GetDateTime(4);
            DateTimeOffset ts19990101000000_off4 = reader.GetDateTimeOffset(4);

            DateTime       ts20000701000000_5    = reader.GetDateTime(5);
            DateTimeOffset ts20000701000000_off5 = reader.GetDateTimeOffset(5);

            DateTimeOffset off0 = TimeZoneInfo.ConvertTime(new DateTimeOffset(localtimestamp0.Ticks, TimeSpan.Zero), TimeZoneInfo.Local);
            DateTimeOffset off1 = TimeZoneInfo.ConvertTime(new DateTimeOffset(nownotz1.Ticks, TimeSpan.Zero), TimeZoneInfo.Local);
            DateTimeOffset off2 = TimeZoneInfo.ConvertTime(new DateTimeOffset(nowtz2.Ticks, TimeSpan.Zero), TimeZoneInfo.Local);
            DateTimeOffset off3 = TimeZoneInfo.ConvertTime(new DateTimeOffset(nowutc3.Ticks, TimeSpan.Zero), TimeZoneInfo.Local);
            DateTimeOffset off4 = TimeZoneInfo.ConvertTime(new DateTimeOffset(ts19990101000000_4.Ticks, TimeSpan.Zero), TimeZoneInfo.Local);
            DateTimeOffset off5 = TimeZoneInfo.ConvertTime(new DateTimeOffset(ts20000701000000_5.Ticks, TimeSpan.Zero), TimeZoneInfo.Local);

            Assert.AreEqual(localtimestampoff0, off0);
            Assert.AreEqual(nownotzoff1, off1);
            Assert.AreEqual(nowtzoff2, off2);
            Assert.AreEqual(nowutcoff3, off3);
            Assert.AreEqual(ts19990101000000_off4, off4);
            Assert.AreEqual(ts20000701000000_off5, off5);

            read = reader.Read();
            Assert.IsFalse(read);
        }
Exemplo n.º 7
0
        public void PqsqlTypeRegistryTest3()
        {
            mCmd.CommandText = "select 'YES'::information_schema.yes_or_no;";
            mCmd.CommandType = CommandType.Text;

            PqsqlDataReader reader = mCmd.ExecuteReader();

            bool read = reader.Read();

            Assert.IsTrue(read);

            string yes = reader.GetString(0);

            Assert.AreEqual("YES", yes);

            read = reader.Read();
            Assert.IsFalse(read);
        }
        public void PqsqlCommandBuilderTest2()
        {
            using (PqsqlConnection connection = new PqsqlConnection(connectionString))
                using (PqsqlCommand command = connection.CreateCommand())
                {
                    PqsqlTransaction transaction = connection.BeginTransaction();
                    command.Transaction = transaction;
                    command.CommandText = "create temp table temptab (c0 int4 primary key, c1 float8)";
                    command.CommandType = CommandType.Text;
                    command.ExecuteNonQuery();
                    transaction.Commit();             // temp table must be visible in the next transaction

                    transaction = connection.BeginTransaction();

                    PqsqlDataAdapter adapter = new PqsqlDataAdapter("select * from temptab", connection)
                    {
                        SelectCommand =
                        {
                            Transaction = transaction
                        },
                    };

                    adapter.RowUpdated += Adapter_RowUpdated;

                    PqsqlCommandBuilder builder = new PqsqlCommandBuilder(adapter);

                    DataSet ds = new DataSet();
                    adapter.FillSchema(ds, SchemaType.Source);
                    adapter.Fill(ds, "temptab");

                    DataTable temptab = ds.Tables["temptab"];
                    DataRow   row     = temptab.NewRow();
                    row["c0"] = 123;
                    row["c1"] = 1.23;
                    temptab.Rows.Add(row);

                    adapter.Update(ds, "temptab");

                    command.CommandText = "select * from temptab";
                    command.CommandType = CommandType.Text;

                    using (PqsqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Assert.AreEqual(123, reader.GetInt32(0));
                            Assert.AreEqual(1.23, reader.GetDouble(1));
                        }
                    }

                    transaction.Rollback();
                }
        }
Exemplo n.º 9
0
        public void PqsqlCommandTest1()
        {
            PqsqlCommand cmd = mConnection.CreateCommand();

            cmd.CommandText = "select pg_sleep(1);";
            PqsqlDataReader r = cmd.ExecuteReader();

            bool b = r.Read();

            Assert.AreEqual(true, b);

            object v = r.GetValue(0);

            Assert.AreEqual("", v);
        }
Exemplo n.º 10
0
 public void PqsqlCommandTest17()
 {
     using (PqsqlCommand cmd =
                new PqsqlCommand("select /*state*/'x' from /* xxx */ pg_stat_activity ", mConnection)
     {
         CommandType = CommandType.Text
     })
     {
         PqsqlDataReader r = cmd.ExecuteReader();
         while (r.Read())
         {
             string s = !r.IsDBNull(0) ? r.GetString(0) : null;
         }
     }
 }
Exemplo n.º 11
0
 public void PqsqlCommandTest19()
 {
     using (PqsqlCommand cmd =
                new PqsqlCommand("select state from pg_stat_activity -- no semicolon", mConnection)
     {
         CommandType = CommandType.Text
     })
     {
         PqsqlDataReader r = cmd.ExecuteReader();
         while (r.Read())
         {
             string s = !r.IsDBNull(0) ? r.GetString(0) : null;
         }
     }
 }
Exemplo n.º 12
0
        public void PqsqlDataReaderTest7()
        {
            // test UTF-8 column names roundtrip
            mCmd.CommandText = "select 12345 as \"€₺£$¥\", 67890 as \"⣿⣶⣤⣀⠀\";";

            using (PqsqlDataReader reader = mCmd.ExecuteReader())
            {
                reader.Read();

                string c0 = reader.GetName(0);
                string c1 = reader.GetName(1);

                Assert.AreEqual("€₺£$¥", c0);
                Assert.AreEqual("⣿⣶⣤⣀⠀", c1);
            }

            // test lower/upper parameter names roundtrip
            mCmd.CommandText = "select :P0 as \"零\", :P1 as \"一\", :p2 as \"二\", :p3 as \"三\" ;";
            mCmd.Parameters.AddWithValue("p0", 0);
            mCmd.Parameters.AddWithValue("p1", 1);
            mCmd.Parameters.AddWithValue("P2", 2);
            mCmd.Parameters.AddWithValue("P3", 3);

            using (PqsqlDataReader reader = mCmd.ExecuteReader())
            {
                reader.Read();

                string c0 = reader.GetName(0);
                string c1 = reader.GetName(1);
                string c2 = reader.GetName(2);
                string c3 = reader.GetName(3);

                int i0 = reader.GetInt32(0);
                int i1 = reader.GetInt32(1);
                int i2 = reader.GetInt32(2);
                int i3 = reader.GetInt32(3);

                Assert.AreEqual(0, i0);
                Assert.AreEqual(1, i1);
                Assert.AreEqual(2, i2);
                Assert.AreEqual(3, i3);

                Assert.AreEqual("零", c0);
                Assert.AreEqual("一", c1);
                Assert.AreEqual("二", c2);
                Assert.AreEqual("三", c3);
            }
        }
Exemplo n.º 13
0
        public void PqsqlDataReaderTest12()
        {
            mCmd.CommandText = @"select interval '23 days', timestamp '2038-01-01', timestamptz '2038-01-01 00:00:00+02', date '2038-01-01', time '00:00:00', timetz '23:23:23+02';";

            using (PqsqlDataReader reader = mCmd.ExecuteReader())
            {
                Assert.IsTrue(reader.HasRows);

                reader.Read();

                TimeSpan ts0 = reader.GetTimeSpan(0);
                Assert.AreEqual(TimeSpan.FromDays(23), ts0);

                TimeSpan ts1 = reader.GetTimeSpan(1);
                DateTime dt1 = reader.GetDateTime(1);
                Assert.AreEqual(new DateTime(2038, 01, 01, 0, 0, 0), dt1);
                DateTimeOffset dto1 = reader.GetDateTimeOffset(1);
                Assert.AreEqual(new DateTimeOffset(2038, 01, 01, 0, 0, 0, TimeSpan.Zero), dto1);

                TimeSpan ts2 = reader.GetTimeSpan(2);
                DateTime dt2 = reader.GetDateTime(2);
                Assert.AreEqual(new DateTime(2037, 12, 31, 22, 0, 0), dt2);
                DateTimeOffset dto2 = reader.GetDateTimeOffset(2);
                Assert.AreEqual(new DateTimeOffset(2038, 01, 01, 0, 0, 0, TimeSpan.FromHours(2)), dto2);

                TimeSpan ts3 = reader.GetTimeSpan(3);
                DateTime dt3 = reader.GetDateTime(3);
                Assert.AreEqual(new DateTime(2038, 01, 01, 0, 0, 0), dt3);
                DateTimeOffset dto3 = reader.GetDateTimeOffset(3);
                Assert.AreEqual(new DateTimeOffset(2038, 01, 01, 0, 0, 0, TimeSpan.Zero), dto3);

                TimeSpan ts4 = reader.GetTimeSpan(4);
                Assert.AreEqual(TimeSpan.FromSeconds(0), ts4);
                DateTime dt4 = reader.GetDateTime(4);
                Assert.AreEqual(DateTime.MinValue, dt4);
                DateTimeOffset dto4 = reader.GetDateTimeOffset(4);
                Assert.AreEqual(DateTimeOffset.MinValue, dto4);

                TimeSpan ts5 = reader.GetTimeSpan(5);
                //Assert.AreEqual(TimeSpan.FromHours(21).Add(TimeSpan.FromMinutes(23)).Add(TimeSpan.FromSeconds(23)), ts5);
                DateTime dt5 = reader.GetDateTime(5);
                //Assert.AreEqual(DateTime.MinValue.AddHours(21).AddMinutes(23).AddSeconds(23), dt5);
                DateTimeOffset dto5 = reader.GetDateTimeOffset(5);
                //Assert.AreEqual(new DateTimeOffset(DateTime.MinValue.AddHours(23).AddMinutes(23).AddSeconds(23), TimeSpan.FromHours(2)), dto5);

                reader.Close();
            }
        }
Exemplo n.º 14
0
        public void PqsqlCommandTest11()
        {
            PqsqlCommand cmd = new PqsqlCommand("select :p1;", mConnection);

            cmd.CommandType = CommandType.Text;

            // recursive parameters
            PqsqlParameter p1 = cmd.Parameters.AddWithValue(":p1", ":p1");

            PqsqlDataReader r = cmd.ExecuteReader();

            while (r.Read())
            {
                string s = r.GetString(0);
                Assert.AreEqual(p1.Value, s);
            }
        }
Exemplo n.º 15
0
        //
        // Summary:
        //     Executes the query and returns the first column of the first row in the result
        //     set returned by the query. All other columns and rows are ignored.
        //
        // Returns:
        //     The first column of the first row in the result set.
        public override object ExecuteScalar()
        {
            PqsqlDataReader r = ExecuteReader(CommandBehavior.Default);

            object o;

            if (r.Read())
            {
                o = r.GetValue(0);
            }
            else
            {
                o = null;
            }

            r.Consume();             // sync protocol: consume remaining rows
            return(o);
        }
Exemplo n.º 16
0
        public void PqsqlTypeRegistryTest4()
        {
            mCmd.CommandText = "select 'YES'::citext";
            mCmd.CommandType = CommandType.Text;

            using (PqsqlCommand check = new PqsqlCommand("select oid from pg_extension where extname='citext'", mConnection))
                using (PqsqlCommand create = new PqsqlCommand("create extension citext", mConnection))
                    using (PqsqlCommand drop = new PqsqlCommand("drop extension if exists citext", mConnection))
                    {
                        object o = null;

                        try
                        {
                            o = check.ExecuteScalar();

                            if (o == null)
                            {
                                int aff = create.ExecuteNonQuery();
                                Assert.AreEqual(0, aff);
                            }

                            PqsqlDataReader reader = mCmd.ExecuteReader();

                            bool read = reader.Read();
                            Assert.IsTrue(read);

                            object yes = reader.GetValue(0);             // must access by GetValue, GetString verifies typoid
                            Assert.AreEqual("YES", yes);

                            reader.Close();
                        }
                        finally
                        {
                            if (o == null)
                            {
                                int aff = drop.ExecuteNonQuery();
                                Assert.AreEqual(0, aff);
                            }
                        }
                    }
        }
Exemplo n.º 17
0
        public void PqsqlDataReaderTest9()
        {
            mCmd.CommandText = @"select 1234567890123456789::int8, 0::oid, '00000000-0000-0000-0000-000000000000'::uuid, 47.11::float4, E'\\000\\001\\002\\003'::bytea, null as ""lastcol""";

            using (PqsqlDataReader reader = mCmd.ExecuteReader())
            {
                Assert.IsTrue(reader.HasRows);

                reader.Read();

                long  c0 = reader.GetInt64(0);
                uint  c1 = reader.GetOid(1);
                Guid  c2 = reader.GetGuid(2);
                float c3 = reader.GetFloat(3);

                long len = reader.GetBytes(4, 0, null, 0, 0);
                Assert.AreEqual((long)4, len);
                byte[] c4   = new byte[len];
                long   read = reader.GetBytes(4, 0, c4, 0, (int)len);
                Assert.AreEqual(read, len);

                Assert.AreEqual(1234567890123456789, c0);
                Assert.AreEqual((uint)0, c1);
                Assert.AreEqual(Guid.Empty, c2);
                Assert.AreEqual((float)47.11, c3);

                byte[] buf = { 0, 1, 2, 3 };
                Assert.AreEqual(buf[0], c4[0]);
                Assert.AreEqual(buf[1], c4[1]);
                Assert.AreEqual(buf[2], c4[2]);
                Assert.AreEqual(buf[3], c4[3]);

                object last = reader[5];
                Assert.AreEqual(DBNull.Value, last);

                last = reader["lastcol"];
                Assert.AreEqual(DBNull.Value, last);

                reader.Close();
            }
        }
Exemplo n.º 18
0
        public void PqsqlCommandTest4()
        {
            PqsqlCommand cmd = new PqsqlCommand("generate_series", mConnection);

            const int p1_val = -1;
            const int p2_val = 2;

            PqsqlParameter p1 = cmd.CreateParameter();

            p1.ParameterName = "p1";
            p1.Value         = p1_val;
            p1.DbType        = DbType.Int32;

            PqsqlParameter p2 = cmd.CreateParameter();

            p2.ParameterName = "p2";
            p2.Value         = p2_val;
            p2.DbType        = DbType.Int32;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
            cmd.Parameters.Add(new PqsqlParameter("generate_series", DbType.Int32)
            {
                Direction = ParameterDirection.Output
            });

            PqsqlDataReader r = cmd.ExecuteReader();
            int             n = p1_val - 1;
            int             j = p1_val;

            while (r.Read())
            {
                int i = r.GetInt32(0);
                Assert.AreEqual(j++, i);
                n++;
            }
            Assert.AreEqual(p2_val, n);
        }
Exemplo n.º 19
0
        public void PqsqlDataReaderTest4()
        {
            mCmd.CommandText = "select :arr";

            PqsqlParameter arr = new PqsqlParameter
            {
                ParameterName = ":arr",
                PqsqlDbType   = PqsqlDbType.Array | PqsqlDbType.Boolean,
                Value         = new bool[] { true, true, false, false }
            };

            mCmd.Parameters.Add(arr);

            using (PqsqlDataReader reader = mCmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                bool read = reader.Read();
                Assert.IsTrue(read);
                object o = reader.GetValue(0);

                // postgres returns 1-based array bool[1..4] in o
                // whereas arr.Value is 0-based array bool[]
                CollectionAssert.AreEqual((ICollection)arr.Value, (ICollection)o);                  // round trip succeeded
            }
        }
Exemplo n.º 20
0
        public void PqsqlDataReaderTest11()
        {
            mCmd.CommandText = @"select null, ''::varchar, '你', '好'::text, '吗'::char(1), 'x'::""char"" ;";

            using (PqsqlDataReader reader = mCmd.ExecuteReader())
            {
                Assert.IsTrue(reader.HasRows);

                reader.Read();

                char   c1 = reader.GetChar(1);
                string s1 = reader.GetString(1);
                char   c2 = reader.GetChar(2);
                string s2 = reader.GetString(2);
                char   c3 = reader.GetChar(3);
                string s3 = reader.GetString(3);
                char   c4 = reader.GetChar(4);
                string s4 = reader.GetString(4);
                char   c5 = reader.GetChar(5);
                string s5 = reader.GetString(5);

                Assert.IsTrue(reader.IsDBNull(0));
                Assert.AreEqual(default(char), c1);
                Assert.AreEqual(string.Empty, s1);
                Assert.AreEqual('你', c2);
                Assert.AreEqual("你", s2);
                Assert.AreEqual('好', c3);
                Assert.AreEqual("好", s3);
                Assert.AreEqual('吗', c4);
                Assert.AreEqual("吗", s4);
                Assert.AreEqual('x', c5);
                Assert.AreEqual("x", s5);

                reader.Close();
            }
        }
Exemplo n.º 21
0
        public void PqsqlTypeRegistryTest5()
        {
            mCmd.CommandText = "select :ts0,:ts1,:ts2,:ts3,:ts4";
            mCmd.CommandType = CommandType.Text;

            PqsqlParameter p0 = new PqsqlParameter("ts0", DbType.DateTimeOffset, new DateTimeOffset(2016, 1, 1, 0, 0, 0, 0, TimeSpan.Zero));

            mCmd.Parameters.Add(p0);

            PqsqlParameter p1 = new PqsqlParameter
            {
                ParameterName = "ts1",
                PqsqlDbType   = PqsqlDbType.Unknown,               // let PqsqlParameterCollection guess the type
                Value         = new DateTimeOffset(new DateTime(2016, 1, 1, 0, 0, 0, 0, DateTimeKind.Local))
            };

            mCmd.Parameters.Add(p1);

            PqsqlParameter p2 = new PqsqlParameter("ts2", DbType.DateTime, new DateTime(2016, 1, 1, 0, 0, 0, 0, DateTimeKind.Local));

            mCmd.Parameters.Add(p2);

            PqsqlParameter p3 = new PqsqlParameter("ts3", DbType.DateTime, new DateTime(2016, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));

            mCmd.Parameters.Add(p3);

            PqsqlParameter p4 = new PqsqlParameter("ts4", DbType.DateTime, new DateTime(2016, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            mCmd.Parameters.Add(p4);

            PqsqlDataReader reader = mCmd.ExecuteReader();

            bool read = reader.Read();

            Assert.IsTrue(read);

            DateTime       ts0      = reader.GetDateTime(0);
            DateTimeOffset tstz0    = reader.GetDateTimeOffset(0);
            DateTimeOffset tsutc0   = tstz0.ToUniversalTime();
            DateTimeOffset tslocal0 = tstz0.ToLocalTime();

            Assert.AreEqual(ts0, tsutc0.DateTime);

            DateTime       ts1      = reader.GetDateTime(1);
            DateTimeOffset tstz1    = reader.GetDateTimeOffset(1);
            DateTimeOffset tsutc1   = tstz1.ToUniversalTime();
            DateTimeOffset tslocal1 = tstz1.ToLocalTime();

            DateTime       ts2      = reader.GetDateTime(2);
            DateTimeOffset tstz2    = reader.GetDateTimeOffset(2);
            DateTimeOffset tsutc2   = tstz2.ToUniversalTime();
            DateTimeOffset tslocal2 = tstz2.ToLocalTime();

            Assert.AreEqual(ts2, tsutc2.UtcDateTime);
            Assert.AreEqual(ts2.ToLocalTime(), tstz2.LocalDateTime);
            Assert.AreEqual(ts2.ToLocalTime(), tsutc2.LocalDateTime);

            DateTime       ts3      = reader.GetDateTime(3);
            DateTimeOffset tstz3    = reader.GetDateTimeOffset(3);
            DateTimeOffset tsutc3   = tstz3.ToUniversalTime();
            DateTimeOffset tslocal3 = tstz3.ToLocalTime();

            Assert.AreEqual(ts3, tstz3.UtcDateTime);
            Assert.AreEqual(ts3, tsutc3.DateTime);

            DateTime       ts4      = reader.GetDateTime(4);
            DateTimeOffset tstz4    = reader.GetDateTimeOffset(4);
            DateTimeOffset tsutc4   = tstz4.ToUniversalTime();
            DateTimeOffset tslocal4 = tstz4.ToLocalTime();

            Assert.AreEqual(ts4, tstz4.UtcDateTime);
            Assert.AreEqual(ts4, tsutc4.DateTime);

            read = reader.Read();
            Assert.IsFalse(read);
        }
Exemplo n.º 22
0
        public void PqsqlDataReaderTest6()
        {
            const string qs = @"select ARRAY[0,1,2,3,42,null,4711]::_text, :p7, unnest(:p6), unnest(:p8) ;
								select interval '20 days', interval '123 secs', interval '20 years 10 months', now(), :p4, timestamp 'infinity', timestamp '-infinity', date 'infinity', date '-infinity';
								select 123.456::numeric, :p3::text ;
								select 'NaN'::numeric, '-1234567898765432123456789.87654321'::numeric ;
								select generate_series(1,1000000),generate_series(1,1000000);
								select generate_series(1,1000000),generate_series(1,1000000);
								select :p1,:p2::text ;
								select extract(epoch from date_trunc('day',current_date - :p9 ))::integer "                                ;

            const int    p1_val = -1;
            const int    p2_val = 2;
            const int    p3_val = -3;
            const double p4_val = 3.1415925;

            decimal p5_val = decimal.Parse("123456789,87654321");

            int[] p6_arr = { 1, 42, 4711, 0815 };

            const string p7_0 = "1 string mit ü and ä sowie 0";
            const string p7_1 = "2 string mit ü and ä sowie 🐨";
            const string p7_2 = "42 string mit ü and ä sowie е́";
            const string p7_3 = "0815 string mit ü and ä sowie П";

            decimal[] p8_arr = { decimal.MinValue, 1.23M, 12.345M, -123.4567M, decimal.MaxValue };

            const int p9_val = 47;

            mCmd.CommandText    = qs;
            mCmd.CommandTimeout = 20;

            PqsqlParameter p1 = mCmd.CreateParameter();

            p1.ParameterName = "p1";
            p1.Value         = p1_val;
            p1.DbType        = DbType.Int32;

            PqsqlParameter p2 = mCmd.CreateParameter();

            p2.ParameterName = "p2";
            p2.Value         = p2_val;
            p2.DbType        = DbType.Int32;

            PqsqlParameter p3 = mCmd.CreateParameter();

            p3.ParameterName = "p3";
            p3.Value         = p3_val;
            p3.DbType        = DbType.Int32;

            PqsqlParameter p4 = mCmd.CreateParameter();

            p4.ParameterName = "p4";
            p4.Value         = p4_val;
            p4.DbType        = DbType.Double;

            PqsqlParameter p5 = mCmd.CreateParameter();

            p5.ParameterName = "p5";
            p5.Value         = p5_val;
            p5.DbType        = DbType.Decimal;

            PqsqlParameter p6 = mCmd.CreateParameter();

            p6.ParameterName = "p6";
            p6.Value         = p6_arr;
            p6.PqsqlDbType   = PqsqlDbType.Array | PqsqlDbType.Int4;

            PqsqlParameter p7 = mCmd.CreateParameter();

            p7.ParameterName = "p7";
            Array b = Array.CreateInstance(typeof(string), new int[] { 4 }, new int[] { -1 });

            b.SetValue(p7_0, -1);
            b.SetValue(p7_1, 0);
            b.SetValue(p7_2, 1);
            b.SetValue(p7_3, 2);
            p7.Value       = b;
            p7.PqsqlDbType = PqsqlDbType.Array | PqsqlDbType.Text;

            PqsqlParameter p8 = mCmd.CreateParameter();

            p8.ParameterName = "p8";
            Array c = Array.CreateInstance(typeof(decimal), new int[] { 5 }, new int[] { -2 });

            c.SetValue(p8_arr[0], -2);
            c.SetValue(p8_arr[1], -1);
            c.SetValue(p8_arr[2], 0);
            c.SetValue(p8_arr[3], 1);
            c.SetValue(p8_arr[4], 2);
            p8.Value       = c;
            p8.PqsqlDbType = PqsqlDbType.Array | PqsqlDbType.Numeric;

            PqsqlParameter p9 = mCmd.CreateParameter();

            p9.ParameterName = "p9";
            p9.Value         = p9_val;
            // let Pqsql guess the parameter type

            mCmd.Parameters.Add(p1);
            mCmd.Parameters.Add(p2);
            mCmd.Parameters.Add(p3);
            mCmd.Parameters.Add(p4);
            mCmd.Parameters.Add(p5);
            mCmd.Parameters.Add(p6);
            mCmd.Parameters.Add(p7);
            mCmd.Parameters.Add(p8);
            mCmd.Parameters.Add(p9);

            PqsqlTransaction t = mConnection.BeginTransaction();

            mCmd.Transaction = t;

            PqsqlDataReader r = mCmd.ExecuteReader();

            int p6_rt = 0;

            //int p8_rt = 0;

            // select ARRAY[0,1,2,3,42,null,4711]::_text, :p7, unnest(:p6), unnest(:p8)
            while (r.Read())
            {
                object o0 = r.GetValue(0);
                object o1 = r.GetValue(1);
                object o2 = r.GetValue(2);
                object o3 = r.GetValue(3);

                Array arr = (Array)o0;

                Assert.AreEqual("0", arr.GetValue(1));
                Assert.AreEqual("1", arr.GetValue(2));
                Assert.AreEqual("2", arr.GetValue(3));
                Assert.AreEqual("3", arr.GetValue(4));
                Assert.AreEqual("42", arr.GetValue(5));
                Assert.AreEqual(null, arr.GetValue(6));
                Assert.AreEqual("4711", arr.GetValue(7));

                arr = (Array)o1;

                Assert.AreEqual(p7_0, arr.GetValue(1));
                Assert.AreEqual(p7_1, arr.GetValue(2));
                Assert.AreEqual(p7_2, arr.GetValue(3));
                Assert.AreEqual(p7_3, arr.GetValue(4));

                Assert.AreEqual(p6_arr[p6_rt++ % 4], o2);

                // TODO decimal vs. double: decimal.MinValue cast to double does not work here
                //Assert.AreEqual(p8_arr[p8_rt++], o3);
            }

            bool next = r.NextResult();

            Assert.IsTrue(next);

            // select interval '20 days', interval '123 secs', interval '20 years 10 months', now(), :p4, timestamp 'infinity', timestamp '-infinity', date 'infinity', date '-infinity'
            while (r.Read())
            {
                TimeSpan s = r.GetTimeSpan(0);
                Assert.AreEqual(TimeSpan.FromDays(20), s);

                s = r.GetTimeSpan(1);
                Assert.AreEqual(TimeSpan.FromSeconds(123), s);

                s = r.GetTimeSpan(2);
                Assert.AreEqual(TimeSpan.FromDays(7609), s);

                DateTime d    = r.GetDateTime(3);
                TimeSpan diff = DateTime.UtcNow - d;
                Assert.IsTrue(diff < TimeSpan.FromHours(1));
                Assert.IsTrue(-diff < TimeSpan.FromHours(1));

                double db = r.GetDouble(4);
                Assert.AreEqual(p4_val, db);

                d = r.GetDateTime(5);
                Assert.AreEqual(DateTime.MaxValue, d);

                d = r.GetDateTime(6);
                Assert.AreEqual(DateTime.MinValue, d);

                d = r.GetDateTime(7);
                Assert.AreEqual(DateTime.MaxValue, d);

                d = r.GetDateTime(8);
                Assert.AreEqual(DateTime.MinValue, d);
            }

            next = r.NextResult();
            Assert.IsTrue(next);

            // select 123.456::numeric, :p3::text
            while (r.Read())
            {
                decimal dec = r.GetDecimal(0);
                Assert.AreEqual(123.456M, dec);

                string str = r.GetString(1);
                Assert.AreEqual(p3_val.ToString(), str);
            }

            t.Commit();

            next = r.NextResult();
            Assert.IsTrue(next);

            // select 'NaN'::numeric, '-1234567898765432123456789.87654321'::numeric
            while (r.Read())
            {
                double dou = r.GetDouble(0);
                Assert.AreEqual(Double.NaN, dou);

                dou = r.GetDouble(1);
                Assert.AreEqual(decimal.ToDouble(-1234567898765432123456789.87654321M), dou);
            }

            next = r.NextResult();
            Assert.IsTrue(next);

            int comp = 1;

            // select generate_series(1,1000000),generate_series(1,1000000)
            while (r.Read())
            {
                int gen = r.GetInt32(0);
                Assert.AreEqual(comp++, gen);
            }

            next = r.NextResult();
            Assert.IsTrue(next);

            comp = 1;

            // select generate_series(1,1000000),generate_series(1,1000000)
            while (r.Read())
            {
                int gen = r.GetInt32(0);
                Assert.AreEqual(comp++, gen);
            }

            Assert.AreEqual(1000001, comp);

            next = r.NextResult();
            Assert.IsTrue(next);

            comp = 0;

            // select :p1,:p2::text
            while (r.Read())
            {
                int    i  = r.GetInt32(0);
                string st = r.GetString(1);

                Assert.AreEqual(p1_val, i);
                string p2s = Convert.ToString(p2_val);
                Assert.AreEqual(p2s, st);
                comp++;
            }

            Assert.AreEqual(1, comp);

            next = r.NextResult();
            Assert.IsTrue(next);

            comp = 0;

            // select extract(epoch from date_trunc('day',current_date - :p9 ))::integer
            while (r.Read())
            {
                int i = r.GetInt32(0);

                int unix = (int)DateTime.UtcNow.Subtract(new TimeSpan(p9_val, 0, 0, 0)).Date.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;

                Assert.AreEqual(unix, i);
                comp++;
            }

            next = r.NextResult();
            Assert.IsFalse(next);

            r.Close();
            r.Dispose();
        }
Exemplo n.º 23
0
        public void PqsqlDataReaderTest8()
        {
            const string qs = "select ARRAY[0,1,2,3,42,null,4711,-1]::int2[], :p1";

            short?[] p1_arr = { 0, 1, 2, 3, 42, null, 4711, -1 };

            mCmd.CommandText    = qs;
            mCmd.CommandTimeout = 5;

            PqsqlParameter p1 = mCmd.CreateParameter();

            p1.ParameterName = "p1";
            p1.Value         = p1_arr;
            p1.PqsqlDbType   = PqsqlDbType.Array | PqsqlDbType.Int2;

            mCmd.Parameters.Add(p1);

            using (PqsqlDataReader r = mCmd.ExecuteReader())
            {
                // select ARRAY[0,1,2,3,42,null,4711,-1]::_int2, :p1
                bool read = r.Read();
                Assert.IsTrue(read);

                Array a0 = (Array)r.GetValue(0);
                Array a1 = (Array)r.GetValue(1);

                Assert.AreEqual(a0.Length, a1.Length);
                Assert.AreEqual(a0.Rank, a1.Rank);

                IEnumerator e1 = a1.GetEnumerator();

                foreach (object o0 in a0)
                {
                    if (e1.MoveNext())
                    {
                        short?s0 = (short?)o0;
                        short?s1 = (short?)e1.Current;
                        Assert.AreEqual(s0, s1);
                    }
                    else
                    {
                        Assert.Fail("cannot advance a1");
                    }
                }

                Assert.AreEqual((short)0, a0.GetValue(1));
                Assert.AreEqual((short)1, a0.GetValue(2));
                Assert.AreEqual((short)2, a0.GetValue(3));
                Assert.AreEqual((short)3, a0.GetValue(4));
                Assert.AreEqual((short)42, a0.GetValue(5));
                Assert.AreEqual(null, a0.GetValue(6));
                Assert.AreEqual((short)4711, a0.GetValue(7));
                Assert.AreEqual((short)-1, a0.GetValue(8));

                Assert.AreEqual((short)0, a1.GetValue(1));
                Assert.AreEqual((short)1, a1.GetValue(2));
                Assert.AreEqual((short)2, a1.GetValue(3));
                Assert.AreEqual((short)3, a1.GetValue(4));
                Assert.AreEqual((short)42, a1.GetValue(5));
                Assert.AreEqual(null, a1.GetValue(6));
                Assert.AreEqual((short)4711, a1.GetValue(7));
                Assert.AreEqual((short)-1, a1.GetValue(8));

                read = r.Read();
                Assert.IsFalse(read);
            }
        }
Exemplo n.º 24
0
        public void PqsqlCommandTest10()
        {
            StringBuilder sb = new StringBuilder();

            const int N = 1664;          // postgres can handle at most 1664 columns in a select
            const int K = 5;             // create K*(K+1) / 2 queries

            PqsqlParameter[] pars = new PqsqlParameter[0];

            for (int k = 1; k <= K; k++)
            {
                if (k > 1)
                {
                    sb.Append(';');
                }
                sb.Append("select ");

                Array.Resize(ref pars, k * N);

                using (PqsqlTransaction t = mConnection.BeginTransaction())
                {
                    for (int i = 1; i <= N; i++)
                    {
                        int j = (k - 1) * N + i - 1;

                        if (i > 1)
                        {
                            sb.Append(',');
                        }
                        sb.Append("generate_series(:p" + j + ",:p" + j + ")");

                        PqsqlParameter p = new PqsqlParameter
                        {
                            ParameterName = "p" + j,
                            DbType        = DbType.Int32,
                            Value         = j
                        };
                        pars[j] = p;
                    }

                    sb.Append(';');

                    using (PqsqlCommand cmd = mConnection.CreateCommand())
                    {
                        cmd.Transaction    = t;
                        cmd.CommandText    = sb.ToString();
                        cmd.CommandTimeout = 20;
                        cmd.CommandType    = CommandType.Text;
                        cmd.Parameters.AddRange(pars.Take(k * N).ToArray());

                        using (PqsqlDataReader reader = cmd.ExecuteReader())
                        {
                            for (int n = 0; n < k; n++)
                            {
                                while (reader.Read())
                                {
                                    for (int m = 0; m < N; m++)
                                    {
                                        int o = reader.GetInt32(m);
                                        Assert.AreEqual(n * N + m, o);
                                    }
                                }
                                reader.NextResult();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        public void PqsqlCommandTest9()
        {
            PqsqlTransaction t = mConnection.BeginTransaction();

            PqsqlCommand cmd = mConnection.CreateCommand();

            cmd.Transaction    = t;
            cmd.CommandText    = @"create or replace function ""pg_temp"".""test me""(i int) returns int as $code$ begin return $1 * i; end; $code$ language plpgsql;
								select ""pg_temp"".""test me""(:p1);
								select ""pg_temp"".""test me""($1)"                                ;
            cmd.CommandTimeout = 2;
            cmd.CommandType    = CommandType.Text;
            cmd.Parameters.AddWithValue("p1", 4711);

            using (PqsqlDataReader r = cmd.ExecuteReader())
            {
                bool good = r.Read();
                Assert.IsFalse(good);

                good = r.NextResult();
                Assert.IsTrue(good);

                good = r.Read();
                Assert.IsTrue(good);

                int n = r.GetInt32(0);
                Assert.AreEqual(4711 * 4711, n);

                good = r.Read();
                Assert.IsFalse(good);

                good = r.NextResult();
                Assert.IsTrue(good);

                good = r.Read();
                Assert.IsTrue(good);

                n = r.GetInt32(0);
                Assert.AreEqual(4711 * 4711, n);

                good = r.Read();
                Assert.IsFalse(good);
            }

            cmd.CommandText = "\"pg_temp\".\"test me\"";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Clear();
            cmd.Parameters.AddWithValue("i", 4711);
            cmd.Parameters.Add(new PqsqlParameter
            {
                ParameterName = "\"pg_temp\".\"test me\"",
                DbType        = DbType.Int32,
                Direction     = ParameterDirection.Output
            });

            object x = cmd.ExecuteScalar();

            Assert.AreEqual(4711 * 4711, x);

            t.Rollback();
        }
Exemplo n.º 26
0
        public void PqsqlCommandTest6()
        {
            PqsqlTransaction t = mConnection.BeginTransaction();

            PqsqlCommand cmd = mConnection.CreateCommand();

            cmd.Transaction    = t;
            cmd.CommandText    = "create or replace function pg_temp.test_out(p1 out text, i1 inout int, p2 out int, r inout refcursor) as $$begin $1 := 'p1 text'; $2:=$2*-4711; $3:=12345; open r for select * from ( values (1,2,3),(4,5,6),(7,8,9) ) X; end;$$ LANGUAGE plpgsql;";
            cmd.CommandTimeout = 10;
            cmd.CommandType    = CommandType.Text;

            int n = cmd.ExecuteNonQuery();

            Assert.AreEqual(0, n);

            PqsqlParameter p1 = new PqsqlParameter("p1", DbType.String)
            {
                Direction = ParameterDirection.Output,
                Value     = "p1_val"
            };

            const int      p2_val = 4711;
            PqsqlParameter p2     = new PqsqlParameter("i1", DbType.Int32, (object)p2_val)
            {
                Direction = ParameterDirection.InputOutput,
            };

            PqsqlParameter p3 = new PqsqlParameter("p2", DbType.Int32)
            {
                Direction = ParameterDirection.Output,
                Value     = 42
            };

            const string   p4_val = "portal_name";
            PqsqlParameter p4     = new PqsqlParameter
            {
                ParameterName = "r",
                PqsqlDbType   = PqsqlDbType.Refcursor,
                Direction     = ParameterDirection.InputOutput,
                Value         = p4_val
            };

            cmd.CommandText = "pg_temp.test_out";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
            cmd.Parameters.Add(p3);
            cmd.Parameters.Add(p4);

            n = cmd.ExecuteNonQuery();
            Assert.AreEqual(-1, n);
            Assert.AreEqual("p1 text", p1.Value);
            Assert.AreEqual(p2_val * -p2_val, p2.Value);
            Assert.AreEqual(12345, p3.Value);
            Assert.AreEqual(p4_val, p4.Value);

            cmd.CommandText = string.Format("fetch all from {0}", p4.Value);
            cmd.CommandType = CommandType.Text;

            PqsqlDataReader r = cmd.ExecuteReader();

            int i = 1;

            while (r.Read())
            {
                Assert.AreEqual(i++, r.GetValue(0));
                Assert.AreEqual(i++, r.GetValue(1));
                Assert.AreEqual(i++, r.GetValue(2));
            }

            t.Rollback();
        }
Exemplo n.º 27
0
        public void PqsqlCopyFromTest2()
        {
            PqsqlTransaction tran = mConnection.BeginTransaction();

            mCmd.Transaction = tran;

            mCmd.CommandText    = "CREATE TEMP TABLE temp (id int4, val int4, txt text)";
            mCmd.CommandTimeout = 200;
            mCmd.CommandType    = CommandType.Text;

            const int    upperbound = 2000000;
            const string text       = "text value with ü and ä ";

            int q = mCmd.ExecuteNonQuery();

            Assert.AreEqual(0, q);

            PqsqlCopyFrom copy = new PqsqlCopyFrom(mConnection)
            {
                Table       = "temp",
                CopyTimeout = 30
            };

            copy.Start();

            for (int i = 0; i < upperbound; i++)
            {
                int j = copy.WriteInt4(i);
                Assert.AreEqual(4, j);

                j = copy.WriteInt4(i);
                Assert.AreEqual(4, j);

                j = copy.WriteText(text + i);
                Assert.AreEqual(Encoding.UTF8.GetByteCount(text + i), j); // length without nul byte
            }
            copy.WriteNull();                                             // id
            copy.WriteNull();                                             // val
            copy.WriteNull();                                             // txt
            copy.End();
            copy.Close();

            mCmd.CommandText    = "select * from temp";
            mCmd.CommandTimeout = 30;
            mCmd.CommandType    = CommandType.Text;

            PqsqlDataReader r = mCmd.ExecuteReader();

            int n = 0;
            int k = 0;

            while (r.Read())
            {
                if (n++ == upperbound)
                {
                    Assert.IsTrue(r.IsDBNull(0));
                    Assert.IsTrue(r.IsDBNull(1));
                    Assert.IsTrue(r.IsDBNull(2));
                }
                else
                {
                    Assert.AreEqual(k, r.GetInt32(0));
                    Assert.AreEqual(k, r.GetInt32(1));
                    Assert.AreEqual(text + k, r.GetString(2));
                    k++;
                }
            }

            Assert.AreEqual(upperbound + 1, n);

            r.Close();

            tran.Rollback();
        }