示例#1
0
    static long InSum    = 0; // this really is a SUM of the bytes! comparison depends on that.

    public static void Main(String[] args)
    {
        conn = new NpgsqlConnection(NpgsqlTests.getConnectionString());

        conn.Open();

        // clear our test table
        new NpgsqlCommand("TRUNCATE copy1", conn).ExecuteNonQuery();

        CopyInFromStream();
        CopyInByWriting();
        CopyOutToStream();
        CopyOutByReading();

        FailCopyInFromStream();
        FailCopyInByWriting();
        FailCopyOutToStream();
        FailCopyOutByReading();

        // now test serialization into a table with multiple data types
        new NpgsqlCommand("TRUNCATE copy2", conn).ExecuteNonQuery();

        CopyInWithSerializer();

        // confirm that connection and server states stay valid through failures.
        new NpgsqlCommand("TRUNCATE copy1", conn).ExecuteNonQuery();

        conn.Close();
    }
示例#2
0
    public static void Main(String[] args)
    {
        NpgsqlConnection conn = null;

        try
        {
            conn = new NpgsqlConnection(NpgsqlTests.getConnectionString());
            conn.Open();
            Console.WriteLine("Connection completed");

            NpgsqlCommand command = new NpgsqlCommand();
            command.CommandText = "select count(*) from tablea";
            command.Connection  = conn;
            Object result = command.ExecuteScalar();
            Console.WriteLine(result.ToString());
        }
        catch (NpgsqlException e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }
示例#3
0
    public static void Main(String[] args)
    {
        NpgsqlConnection conn = null;

        try
        {
            conn = new NpgsqlConnection(NpgsqlTests.getConnectionString());
            conn.Open();
            Console.WriteLine("Connection completed");

            NpgsqlCommand command = new NpgsqlCommand();
            command.CommandText = "select * from tablea;";
            command.Connection  = conn;
            NpgsqlDataReader dr = command.ExecuteReader();

            Int32 j;

            do
            {
                j = dr.FieldCount;
                Console.WriteLine(j);
                DataTable         dt         = dr.GetSchemaTable();
                DataRowCollection schemarows = dt.Rows;

                Int32 i;

                for (i = 0; i < j; i++)
                {
                    Console.Write("{0} \t", schemarows[i][0]);
                }
                Console.WriteLine();
                Console.WriteLine("============================================");

                while (dr.Read())
                {
                    for (i = 0; i < j; i++)
                    {
                        Console.Write("{0} \t", dr[i]);
                    }
                    Console.WriteLine();
                }
            } while(dr.NextResult());

            dr.Close();
        }
        catch (NpgsqlException e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }
示例#4
0
    public static void Main(String[] args)
    {
        String connstring;

        connstring = NpgsqlTests.getConnectionString();

        NpgsqlConnection conn = new NpgsqlConnection(connstring);

        conn.Open();
        conn.Close();

        System.Console.WriteLine("Test Works");
    }
示例#5
0
    public static void Main(String[] args)
    {
        NpgsqlConnection conn = null;

        try
        {
            conn = new NpgsqlConnection(NpgsqlTests.getConnectionString());
            conn.Open();
            Console.WriteLine("Connection completed");

            // Check whether the insert statement works
            NpgsqlCommand command  = new NpgsqlCommand("insert into tablea(field_text) values ('Text from Npgsql');", conn);
            Int32         num_rows = command.ExecuteNonQuery();
            Console.WriteLine("{0} rows were added!", num_rows);

            // Check whether the update statement works
            command.CommandText = "update tablea set field_text='Updated Text from Npgsql' where field_text='Text from Npgsql';";
            num_rows            = command.ExecuteNonQuery();
            Console.WriteLine("{0} rows were updated!", num_rows);

            // Check whether the delete statement works
            command.CommandText = "delete from tablea where field_text = 'Updated Text from Npgsql'";
            num_rows            = command.ExecuteNonQuery();
            Console.WriteLine("{0} rows were deleted!", num_rows);
        }
        catch (NpgsqlException e)
        {
            Console.WriteLine(e.ToString());
        }

        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }
示例#6
0
    public static void Main(String[] args)
    {
        NpgsqlConnection conn = null;

        try
        {
            conn = new NpgsqlConnection(NpgsqlTests.getConnectionString());
            conn.Open();
            Console.WriteLine("Connection completed");

            NpgsqlCommand command = new NpgsqlCommand();
            command.CommandText = "select * from tablea";

            command.Connection = conn;

            NpgsqlDataAdapter da = new NpgsqlDataAdapter();
            da.SelectCommand = command;

            DataSet ds = new DataSet();

            da.Fill(ds);

            ds.WriteXml(Console.Out);
        }
        catch (NpgsqlException e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }
    public static void Main(String[] args)
    {
        NpgsqlConnection conn = null;

        try
        {
            conn = new NpgsqlConnection(NpgsqlTests.getConnectionString());

            conn.Open();
            Console.WriteLine("Connection completed");

            NpgsqlCommand command = new NpgsqlCommand();
            command.CommandText = "select * from tablea where field_int4 = :a;";
            command.Connection  = conn;
            command.Parameters.Add(new NpgsqlParameter("a", DbType.Int32));

            command.Prepare();
            command.Parameters[0].Value = 4;

            NpgsqlDataReader dr = command.ExecuteReader();

            Int32 j;

            do
            {
                j = dr.FieldCount;
                Console.WriteLine(j);

                /*DataTable dt = dr.GetSchemaTable();
                 * DataRowCollection schemarows = dt.Rows;
                 *
                 * for (i = 0; i < j; i++)
                 * {
                 * Console.Write("{0} \t", schemarows[i][0]);
                 *
                 * }
                 */
                Int32 i;

                Console.WriteLine();
                Console.WriteLine("============================================");

                while (dr.Read())
                {
                    for (i = 0; i < j; i++)
                    {
                        Console.Write("{0} \t", dr[i] == DBNull.Value ? "null" : dr[i]);
                    }
                    Console.WriteLine();
                }
            } while(dr.NextResult());

            dr.Close();
        }
        catch (NpgsqlException e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }
    }