Beispiel #1
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;
         }
     }
 }
Beispiel #2
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;
         }
     }
 }
Beispiel #3
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();
            }
        }
        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();
        }