X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=web%2Fpostgresql;h=90c3f4f600919ed27de349cb8aaf62154bf9841c;hb=e4c6c4395f0f85bcbb6378c18f31b1a4d6e506f6;hp=ef1bf1e9e72038eca8a7e595c2765bbca77ee019;hpb=af653b483b9bf8247c85ec0fcfa984e082d1718d;p=mono.git diff --git a/web/postgresql b/web/postgresql index ef1bf1e9e72..90c3f4f6009 100644 --- a/web/postgresql +++ b/web/postgresql @@ -1,12 +1,21 @@ -* PostgreSQL Data Provider +* PostgreSQL and Mono - There are two ADO.NET data providers for PostgreSQL in Mono: + When it comes to Mono and PostgreSQL, there are many ways + you can access your data. + +* Data Providers + + There are many ADO.NET data providers for PostgreSQL: + + There are two providers created specifically for PostgreSQL included with Mono:
In order to test Mono.Data.PostgreSqlClient, you will need to have - access to a remote PostgreSQL DBMS, or you will have to install - one locally. PostgreSQL was the first ADO.NET provider created in Mono. - -
Why use PostgreSQL? Because it is free software, has a client - library that is easy to use, PostgreSQL is easy to install on - Unix and Windows (using the Cygwin install program), not difficult to setup after - installation, and it runs under: Linux, - Windows (via cygwin and ipc-daemon), Unix, and - others. This allowed us to create the - System.Data functionality in Mono much quicker. +** Testing Npgsql + +
If you plan on using a remote PostgreSQL DBMS Server, - than you will need to have the PostgreSQL client software on your - local computer that includes libpq.so (pq.dll on Windows). +
The System.Data tests use this connection string to connect - to the PostgreSQL database named "test" at host "localhost" as - user "postgres". - +
-"Server=localhost;Database=test;User ID=postgres;Password=fun2db" - (or) -"host=localhost;dbname=test;user=postgres;password=fun2db" + using System; + using System.Data; + using Npgsql; + + public class Test + { + public static void Main(string[] args) + { + string connectionString = + "Server=localhost;" + + "Database=test;" + + "User ID=postgres;" + + "Password=fun2db;"; + IDbConnection dbcon; + dbcon = new NpgsqlConnection(connectionString); + dbcon.Open(); + IDbCommand dbcmd = dbcon.CreateCommand(); + // requires a table to be created named employee + // with columns firstname and lastname + // such as, + // CREATE TABLE employee ( + // firstname varchar(32), + // lastname varchar(32)); + string sql = + "SELECT firstname, lastname " + + "FROM employee"; + dbcmd.CommandText = sql; + IDataReader reader = dbcmd.ExecuteReader(); + while(reader.Read()) { + string FirstName = (string) reader["firstname"]; + string LastName = (string) reader["lastname"]; + Console.WriteLine("Name: " + + FirstName + " " + LastName); + } + // clean up + reader.Close(); + reader = null; + dbcmd.Dispose(); + dbcmd = null; + dbcon.Close(); + dbcon = null; + } + }+
+ mcs TestExample.cs -r System.Data.dll \ + -r Npgsql.dll ++
+mono TestExample.exe ++
Installation instructions for PostgreSQL DBMS: - On Unix + +** Installation instructions for PostgreSQL DBMS: +
On Unix
In the path mcs/class/System.Data/Test - there is a test for Mono.Data.PostgreSqlClient named - PostgreTest.cs. Thanks goes to Gonzalo for creating the original - PostgreSQL test. - -
- To compile the PostgresTest.cs program, do: - -
-
- mcs PostgresTest.cs \ - -r System.Data.dll \ - -r Mono.Data.PostgreSqlClient.dll -- -
If there are compile errors, such as, can not convert IDbConnection - to PgSqlConnection, then you need to run mcs like: - -
- mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \ - PostgresTest.cs \ - -r System.Data.dll \ - -r Mono.Data.PostgreSqlClient.dll -- -
- To run using mint, do: - -
-
-mint PostgresTest.exe -- -
- To run using mono, do: -
-mono PostgresTest.exe -- -
C# Example for Mono.Data.PostgreSqlClient: -
- using System; - using System.Data; - using Mono.Data.PostgreSqlClient; - - public class Test - { - public static void Main(string[] args) - { - string connectionString = - "Server=localhost;" + - "Database=test;" + - "User ID=postgres;" + - "Password=fun2db;"; - IDbConnection dbcon; - dbcon = new PgConnection(connectionString); - IDbCommand dbcmd = dbcon.CreateCommand(); - // requires a table to be created named employee - // with columns firstname and lastname - // such as, - // CREATE TABLE employee ( - // firstname varchar(32), - // lastname varchar(32)); - string sql = - "SELECT firstname, lastname" + - "FROM employee"; - dbcmd.CommandText = sql; - IDataReader reader = dbcmd.ExecuteReader(); - while(reader.Read()) { - string FirstName = reader["firstname"]; - string LastName = reader["lastname"]; - Console.WriteLine("Name: " + - FirstName + " " + LastName); - } - // clean up - reader.Close(); - reader = null; - dbcmd.Dispose(); - dbcmd = null; - dbcon.Close(); - dbcon = null; - } - } -- -
- mcs TestExample.cs -r System.Data.dll \ - -r Mono.Data.PostgreSqlClient.dll --
- mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \ - TestExample.cs \ - -lib:C:/cygwin/home/MyHome/mono/install/lib \ - -r System.Data.dll -r Mono.Data.PostgreSqlClient.dll --
-mono TestExample.exe --
- using System; - using System.Data; - using Npgsql; - - public class Test - { - public static void Main(string[] args) - { - string connectionString = - "Server=localhost;" + - "Database=test;" + - "User ID=postgres;" + - "Password=fun2db;"; - IDbConnection dbcon; - dbcon = new NpgsqlConnection(connectionString); - IDbCommand dbcmd = dbcon.CreateCommand(); - // requires a table to be created named employee - // with columns firstname and lastname - // such as, - // CREATE TABLE employee ( - // firstname varchar(32), - // lastname varchar(32)); - string sql = - "SELECT firstname, lastname " + - "FROM employee"; - dbcmd.CommandText = sql; - IDataReader reader = dbcmd.ExecuteReader(); - while(reader.Read()) { - string FirstName = reader["firstname"]; - string LastName = reader["lastname"]; - Console.WriteLine("Name: " + - FirstName + " " + LastName); - } - // clean up - reader.Close(); - reader = null; - dbcmd.Dispose(); - dbcmd = null; - dbcon.Close(); - dbcon = null; - } - } --
- mcs TestExample.cs -r System.Data.dll \ - -r Npgsql.dll --
- mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \ - TestExample.cs \ - -lib:C:/cygwin/home/MyHome/mono/install/lib \ - -r System.Data.dll -r Npgsql.dll --
-mono TestExample.exe --