Обсуждение: PostgreSQL and C#

Поиск
Список
Период
Сортировка

PostgreSQL and C#

От
"Daniel Morgan"
Дата:

I am interested in Platform Invoking in PostgreSQL using C#.  Unfortunately, I cannot find any information about the various structures that are used in libpq to do this.  Like, what is PGConn structure defined as?

I looked in the various header files for the library, but no luck.  Do I need to get the source the PostgreSQL database itself? 

 

I really want to use C# and .NET to query PostgreSQL 7.2 databases?

 

Currently, I am running PostgreSQL and C# and .NET under Windows XP, but my long-term goal is to connect to PostgreSQL databases using Mono C# on Linux.

 

Any help is appreciated,

 

Please reply to my email address because for some strange reason I don’t get any mail from this list even though I subscribed to it and other PostgreSQL lists.  I would like to though…

 

Thank you,

Daniel Morgan

 

Re: PostgreSQL and C#

От
Jean-Michel POURE
Дата:
Le Mardi 9 Avril 2002 15:13, Daniel Morgan a écrit :
> I am interested in Platform Invoking in PostgreSQL using C#.
> Unfortunately, I cannot find any information about the various
> structures that are used in libpq to do this.  Like, what is PGConn
> structure defined as?

Dave Page, pgAdmin2 author (http://pgadmin.postgresql.org), is interested in
C# and (might be) working on this issue. Maybe you can contact him on
pgadmin-hackers@postgresql.org mailing list.

Best regards,
Jean-Michel POURE

Re: PostgreSQL and C#

От
Matthew Stanfield
Дата:
> I really want to use C# and .NET to query PostgreSQL 7.2 databases?

Hi Daniel,

The way I have done it is by using ODBC. You will need to download:
odbc.net from the microsoft site (URL below) and the postgresql odbc driver
(URL below).

Some of the .net CLR database orientated classes are specific to
Microsoft's SQL Server so you can't use them. odbc.net provides a suite of
classes such as OdbcConnection, OdbcCommand and OdbcDataReader; which, so
far, have been really easy to use (see mini example below).


> Do I need to get the source the PostgreSQL database itself?

Absolutely not! I highly recommend you using odbc.net to connect to
postgresql, it is simple to use (and learn), fast and has, so far, been bug
free.

postgresql odbc site:
http://odbc.postgresql.org

odbc.net is here (watch out for the line wrap)

http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/668/msdncompositedoc.xml

Mini Example:

string query = "SELECT * FROM testtable";
OdbcConnection odbcCon = new OdbcConnection("DSN=PostgreSQL");
OdbcCommand odbcCom = new OdbcCommand(query, odbcCon);
odbcCon.Open();
OdbcDataReader odbcReader =
odbcCom.ExecuteReader(CommandBehavior.CloseConnection);
Then you can start 'reading'.

Good luck,

..matthew

Re: PostgreSQL and C#

От
Matthew Stanfield
Дата:
This email just got returned to me as a failed delivery so I am resending
it, apologies if anyone gets it twice.  Matthew

> I really want to use C# and .NET to query PostgreSQL 7.2 databases?

Hi Daniel,

The way I have done it is by using ODBC. You will need to download:
odbc.net from the microsoft site (URL below) and the postgresql odbc driver
(URL below).

Some of the .net CLR database orientated classes are specific to
Microsoft's SQL Server so you can't use them. odbc.net provides a suite of
classes such as OdbcConnection, OdbcCommand and OdbcDataReader; which, so
far, have been really easy to use (see mini example below).


> Do I need to get the source the PostgreSQL database itself?

Absolutely not! I highly recommend you using odbc.net to connect to
postgresql, it is simple to use (and learn), fast and has, so far, been bug
free.

postgresql odbc site:
http://odbc.postgresql.org

odbc.net is here:

http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/668/msdncompositedoc.xml

Mini Example:

string query = "SELECT * FROM testtable";
OdbcConnection odbcCon = new OdbcConnection("DSN=PostgreSQL");
OdbcCommand odbcCom = new OdbcCommand(query, odbcCon);
odbcCon.Open();
OdbcDataReader odbcReader =
odbcCom.ExecuteReader(CommandBehavior.CloseConnection);
Then you can start 'reading'.

Good luck,

..matthew

Re: PostgreSQL and C#

От
"Daniel Morgan"
Дата:
Thanks for the help.  However, I'm more interested in a direct approach
from C# to the PostgreSQL client library.  Also, this must be able to
work under Windows, Linux, etc...

I discovered that pq.dll is the PostgreSQL client library under Windows
while libpq.so is library under Linux.  This was the cause of my
confusion because I couldn't find libpq.so under Windows.  Here is
snippet I used to pinvoke into pq.dll on cgwin.  Now, I can help work on
creating a provider for System.Data in Mono C#.  Work has already
started on System.Data classes by various people, including Rodrigo
Moya, the maintainer of Gnome-DB.

using System;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        [DllImport("pq.dll")]
        public static extern IntPtr PQconnectdb(String
conninfo);
        // PGconn *PQconnectdb(const char *conninfo)

        [DllImport("pq.dll")]
        public static extern void PQfinish(IntPtr conn);
        // void PQfinish(PGconn *conn)

        [DllImport("pq.dll")]
        public static extern IntPtr PQexec(IntPtr conn,
            String query);
        // PGresult *PQexec(PGconn *conn,    const char
*query);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            IntPtr dbconn;
            String sConnInfo;
            String sQuery;

            sConnInfo = "host=localhost dbname=test
user=danmorg password=viewsonic";
            sQuery = "insert into sometable " +
                     "(tid,tdesc) " +
                     "values('dan','morgan') ";

            dbconn = PQconnectdb(sConnInfo);

            if(dbconn == IntPtr.Zero)
                Console.WriteLine("dbconn is null");
            else
            {
                Console.WriteLine("assuming successful
connection");
                PQexec(dbconn,sQuery);
                PQfinish(dbconn);
            }
        }
    }
}

-----Original Message-----
From: Matthew Stanfield [mailto:matthew@propertyknowledge.com]
Sent: Tuesday, April 09, 2002 1:39 PM
To: Daniel Morgan
Cc: PostgreSQL General Mailing List
Subject: Re: [GENERAL] PostgreSQL and C#

This email just got returned to me as a failed delivery so I am
resending
it, apologies if anyone gets it twice.  Matthew

> I really want to use C# and .NET to query PostgreSQL 7.2 databases?

Hi Daniel,

The way I have done it is by using ODBC. You will need to download:
odbc.net from the microsoft site (URL below) and the postgresql odbc
driver
(URL below).

Some of the .net CLR database orientated classes are specific to
Microsoft's SQL Server so you can't use them. odbc.net provides a suite
of
classes such as OdbcConnection, OdbcCommand and OdbcDataReader; which,
so
far, have been really easy to use (see mini example below).


> Do I need to get the source the PostgreSQL database itself?

Absolutely not! I highly recommend you using odbc.net to connect to
postgresql, it is simple to use (and learn), fast and has, so far, been
bug
free.

postgresql odbc site:
http://odbc.postgresql.org

odbc.net is here:
http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.as
p?url=/MSDN-FILES/027/001/668/msdncompositedoc.xml

Mini Example:

string query = "SELECT * FROM testtable";
OdbcConnection odbcCon = new OdbcConnection("DSN=PostgreSQL");
OdbcCommand odbcCom = new OdbcCommand(query, odbcCon);
odbcCon.Open();
OdbcDataReader odbcReader =
odbcCom.ExecuteReader(CommandBehavior.CloseConnection);
Then you can start 'reading'.

Good luck,

..matthew


Re: PostgreSQL and C#

От
Medi Montaseri
Дата:
 
Daniel Morgan wrote:
Thanks for the help.  However, I'm more interested in a direct approach
from C# to the PostgreSQL client library.  Also, this must be able to
work under Windows, Linux, etc...
 
 
Are you saying that C# is available for non-Microsoft Operating Systems?
 
 

http://archives.postgresql.org

-- 
-------------------------------------------------------------------------
Medi Montaseri                               medi@CyberShell.com
Unix Distributed Systems Engineer            HTTP://www.CyberShell.com
CyberShell Engineering
-------------------------------------------------------------------------
 

Re: PostgreSQL and C#

От
"Daniel Morgan"
Дата:

Yes, there are three alternatives to Microsoft .NET Framework:

 

Mono C# and CLR which works on Windows and Linux at:

http://www.go-mono.com/

 

Portable.NET which works on Linux at

http://www.southern-storm.com.au/portable_net.html

 

Rotor which is Microsoft’s shared source C# and CLR available for Windows and FreeBSD:

http://msdn.microsoft.com/library/en-us/Dndotnet/html/mssharsourcecli.asp?frame=true

 

I’m currently working on Mono right now.  Those guys are moving pretty fast – they already have a C# compiler that can compile itself on its own CLR under Linux and Windows.  There are people working on the C# bindings to gtk/gnome and qt/kde.  Rodrigo Moya is working on the database access (System.Data etc) in Mono C#.  The first provider we are working on is the PostgreSQL provider.  After that is working, we will create other providers.

 

Want to help?

 

-----Original Message-----
From: medi@ncmx02.mgw.rr.com [mailto:medi@ncmx02.mgw.rr.com] On Behalf Of Medi Montaseri
Sent:
Wednesday, April 10, 2002 11:27 PM
To: Daniel Morgan
Cc: 'Matthew Stanfield'; 'PostgreSQL General Mailing List'
Subject: Re: [GENERAL] PostgreSQL and C#

 
Daniel Morgan wrote:

Thanks for the help.  However, I'm more interested in a direct approach
from C# to the PostgreSQL client library.  Also, this must be able to
work
under Windows, Linux, etc...
   

Are you saying that C# is available for non-Microsoft Operating Systems?
 

Re: PostgreSQL and C#

От
"Daniel Morgan"
Дата:

Nonsense.  You are not falling behind.  We all have to learn sometime.  Also, I am learning C# and Mono myself.  Remember, all the people working on Mono C# had to learn C# too. 

 

If you want to help with the PostgreSQL System.Data.OleDb Provider in C#, come on over to http://www.go-mono.com/ and lend a hand.  The best person to talk to, if interested, is to email Rodrigo Moya at address rodrigo at gnome-db dot org.  He is the maintainer of Gnome-DB.  For more info about gnome-db, see http://www.gnome-db.org/

 

The efforts for creating the PostgreSQL provider in C# for Mono can be used in creating the PostgreSQL C# provider for dotGNU’s Portable.NET, Microsoft’s .NET Framework, and Rotor.   This way, no matter what language that you use that compiles to IL and runs on a CLR, you can access data from PostgreSQL databases.

 

Because Mono’s class library uses the X11 license (which is like the BSD license), it is open source.  You can use it in both open source and closed souce programs.

 

-----Original Message-----
From: medi@ncmx02.mgw.rr.com [mailto:medi@ncmx02.mgw.rr.com] On Behalf Of Medi Montaseri
Sent: Saturday, April 13, 2002 12:33 AM
To: Daniel Morgan
Subject: Re: [GENERAL] PostgreSQL and C#

 

Thank you very much Daniel....very informative....I guess I'm falling behind
on these new technologies indeed......good lecture.....

Cheers...

Daniel Morgan wrote:

This link will tell you what the Mono:: project is all about.

They have a FAQ (Frequently Asked Questions) as well at:

http://www.go-mono.com/faq.html

To answer your questions, the Microsoft .NET is a "branding" that means many things.The Microsoft .NET Development Framework includes the .NET runtime (virtual machine and class library), compilers, linkers, assemblers, disassemblers, debuggers, etc..It does not include the GUI IDE, you need Visual Studio.net orSharpDevelop for that.

Java has many meanings: it is a technology, it has a virtual machine, it is a programming language, it has a compiler, etc...

Java has a Java Virtual Machine which was designed from the ground up for the java programming language.

The big deal about .net is that it was designed from the ground up to support many languages. Microsoft .NET Development Framework includes many compilers for various languages: C++, C#, Visual Basic, and Jscript (JavaScript/ECMAScript).

Many companies have created compilers for the .NET CLR (Common Language Runtime - this is the virtual machine for .NET).Fujitsu has created COBOL.NET,ActiveState has create PERL.NET and Python.NET compilers.There are many others out there.Even Borland plans to come out with Delphi and C++ Builder for .NET.

COM/OLE/ActiveX/DCOM/COM+ or whatever new name Microsoft came up with was originally supposed to solve the problem of writing programs using "objects" in different languages - easy to develop, update, and maintain - no matter what platform (in Microsoft terms, this meant Windows 95, Window NT, etc), programming language, or compiler you used to create your objects.You could create an object in Visual Basic, extend it using C++, and then use that inherited class in J++.

This fail short.

.NET was Microsoft's answer to that promise they made to their developers many years ago.Sure, there are different "component object modules" like CORBA, COM, XPCOM, SOM, and many others - but they are very hard to develop IMHO.

I am not going to get into a discussines about the pros and cons between jvm/java and .net/C# though.Simply because I am simply a programmer and not a software architect, so those kind of discussions I have no use for.I am only interested in what future programming positions I can get. 

Microsoft submitted their specifications for C# and the CLI (Common Language Infratstructure) to the standards body ECMA. ECMA has since standardized it.

The Mono:: project is working on a C# and CLR for Linux.Currently, it works on Windows and Linux with other people trying to get it to work on FreeBSD and MacOS X. The C# compiler can build itself on Linux using its runtime.

Mono has created two CLR "virtual machines" .One is an interpreter that interprets the Intermediate Language bytecode.The other is a JIT (Just-In-Time compiler).A .NET program running on a JIT is much faster than on the interpreter; however, the interpreter is easier to port to another platform. The interpreter is called mint while the JIT is called mono. The C# compiler is called mcs.

Disclaimer, I am no expert at this. I am still learning C# and .NET.If you liked Java, you will like C# and .NET.

Daniel

-----Original Message-----
From: medi@ncmx02.mgw.rr.com [mailto:medi@ncmx02.mgw.rr.comOn Behalf Of Medi Montaseri
Sent:Thursday, April 11, 20021:56 AM
To: Daniel Morgan
Subject: Re: [GENERAL] PostgreSQL and C#

Actually I don't know anything about C# yet. I just read a bit about it and
put the book down when I found out that it is a Bill Gate thing....but I am
happy to see it making its way to Linux.... 

I suppose I need to learn a bit more about C# first. I think its a Interpreted
Language like Java requiring a *VM. But  I don't know what .net is.
I keep reading that .NET is a Development Framework. But I have seen
this Development Framework so many times in my 16 years of programming
that I don't know what is going on any more. The words don't even make sense
to me. What is a Framework? Is it an assembler, a linker, a compiler, a text editor,
a shared library, a GUI wordprocessor, a database. What is a FrameWork? Is it
a company name or a process of submiting expenses? I give up. 

Then there is JIT, CIL and probably more acronyms. Anyways, you can see, I'm falling behind in this terminology thing. So if you feel like educating me, I'd appreciate it. 

Cheers... 

Daniel Morgan wrote: 

Yes, there are three alternatives to Microsoft .NET Framework:

Mono C# and CLR which works on Windows and Linux at:

Portable.NET which works on Linux at 

http://www.southern-storm.com.au/portable_net.html

Rotor which is Microsoft's shared source C# and CLR available for Windows and FreeBSD:

http://msdn.microsoft.com/library/en-us/Dndotnet/html/mssharsourcecli.asp?frame=true

I'm currently working on Mono right now.Those guys are moving pretty fast - they already have a C# compiler that can compile itself on its own CLR under Linux and Windows. There are people working on the C# bindings to gtk/gnome and qt/kde.Rodrigo Moya is working on the database access (System.Data etc) in Mono C#.The first provider we are working on is the PostgreSQL provider.After that is working, we will create other providers.

Want to help?

-----Original Message-----
From: medi@ncmx02.mgw.rr.com [mailto:medi@ncmx02.mgw.rr.comOn Behalf Of Medi Montaseri
Sent:Wednesday, April 10, 200211:27 PM
To: Daniel Morgan
Cc: 'Matthew Stanfield'; 'PostgreSQL General Mailing List'
Subject: Re: [GENERAL] PostgreSQL and C#


Daniel Morgan wrote: 

Thanks for the help.  However, I'm more interested in a direct approach
from C# to the PostgreSQL client library.  Also, this must be able to
work under Windows, Linux, etc...


Are you saying that C# is available for non-Microsoft Operating Systems?

-- 
-------------------------------------------------------------------------
Medi Montaseri                               medi@CyberShell.com
Unix Distributed Systems Engineer            HTTP://www.CyberShell.com
CyberShell Engineering
-------------------------------------------------------------------------
-- 
-------------------------------------------------------------------------
Medi Montaseri                               medi@CyberShell.com
Unix Distributed Systems Engineer            HTTP://www.CyberShell.com
CyberShell Engineering
-------------------------------------------------------------------------

 

PostgreSQL - regularly sync.ing remote and local data

От
Ma Siva Kumar
Дата:
We are developing an application for leather industry using PostgreSQL with
PHP scripting. The program will be run from a central server and buyers and
sellers will login using internet connection and update/exchange information
through the system.

Some companies do not want to be connected to the internet throughout the
day. They want to use the system from a local server during the day and
update the data to the central server (and get the updated data from the
server) once or twice a day.

Can someone please advise me, how this can be accomplished? That is, to make
the two databases hand shake and exchange the changes effected since they
last met.

Best regards,


Siva,
Chennai, Tamil Nadu

Re: PostgreSQL - regularly sync.ing remote and local data

От
Frank Hilliard
Дата:
I think this is a logic question they haven't worked through. Let's say
company A and B are using the on-line server and company C is not. All
three start the day the same way with company A offering 500 shoes for
sale. Company B likes the shoes and buys 400 of them. The database on
the central server now says there are 100 shoes left. But Company C,
which also likes the shoes, thinks there are 500 since they haven't
updated their version of the database. They put in an order for 200
shoes and only find out later they have been shipped 100, with 100 back
ordered.

This is just a simple example with three companies. Multiply that by
hundreds of transactions and hundreds of companies and you get a real
nightmare.

The solution is pretty simple. The companies who don't want to be
connected all day only connect when they want to conduct a transaction.
The data is updated the moment they log on, they conduct their purchase
and then they log off.
Frank Hilliard
http://frankhilliard.com/


Ma Siva Kumar wrote:

>We are developing an application for leather industry using PostgreSQL with
>PHP scripting. The program will be run from a central server and buyers and
>sellers will login using internet connection and update/exchange information
>through the system.
>
>Some companies do not want to be connected to the internet throughout the
>day. They want to use the system from a local server during the day and
>update the data to the central server (and get the updated data from the
>server) once or twice a day.
>
>Can someone please advise me, how this can be accomplished? That is, to make
>the two databases hand shake and exchange the changes effected since they
>last met.
>
>Best regards,
>
>
>Siva,
>Chennai, Tamil Nadu
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>http://www.postgresql.org/users-lounge/docs/faq.html
>



Re: PostgreSQL - regularly sync.ing remote and local data

От
Ma Siva Kumar
Дата:
Fortunately, this particular situation involves simpler relations. It is more
like this.

Buying companies place orders to their supplier companies. Supplier companies
maintain the status of orders in the system. Buyer companies can login and
get information about the order status.

Thus, most of the update of information comes from the internal working of
supplier companies and the relationship is strictly one to one (what one
buyer buys from a supplier does not affect any one else in the system).

If everyone uses the central server to update the transactions that is ideal.
However, atleast in the initial stages, supplier companies may like to
conduct their day to day operations on the local server (due to connection
speeds, costs etc) and update the transactions to the central server several
times a day.

The information flow from the buyer is in the form of new orders, approval of
samples, payment information etc.

Hope now it is clearer. Even though there will be hundreds of companies in
the system, each one will have a strictly one to one relationship with
others.

What is the best possible way to do this using Postgres and PHP?

Best regards,


Siva,
Chennai, Tamil Nadu.



> I think this is a logic question they haven't worked through. Let's say
> company A and B are using the on-line server and company C is not. All
> three start the day the same way with company A offering 500 shoes for
> sale. Company B likes the shoes and buys 400 of them. The database on
> the central server now says there are 100 shoes left. But Company C,
> which also likes the shoes, thinks there are 500 since they haven't
> updated their version of the database. They put in an order for 200
> shoes and only find out later they have been shipped 100, with 100 back
> ordered.
>
> This is just a simple example with three companies. Multiply that by
> hundreds of transactions and hundreds of companies and you get a real
> nightmare.
>
> The solution is pretty simple. The companies who don't want to be
> connected all day only connect when they want to conduct a transaction.
> The data is updated the moment they log on, they conduct their purchase
> and then they log off.
> Frank Hilliard
> http://frankhilliard.com/
>
> Ma Siva Kumar wrote:
> >We are developing an application for leather industry using PostgreSQL
> > with PHP scripting. The program will be run from a central server and
> > buyers and sellers will login using internet connection and
> > update/exchange information through the system.
> >
> >Some companies do not want to be connected to the internet throughout the
> >day. They want to use the system from a local server during the day and
> >update the data to the central server (and get the updated data from the
> >server) once or twice a day.
> >
> >Can someone please advise me, how this can be accomplished? That is, to
> > make the two databases hand shake and exchange the changes effected since
> > they last met.
> >
> >Best regards,
> >
> >
> >Siva,
> >Chennai, Tamil Nadu
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 5: Have you checked our extensive FAQ?
> >
> >http://www.postgresql.org/users-lounge/docs/faq.html
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Re: PostgreSQL - regularly sync.ing remote and local data

От
GB Clark
Дата:
On Sun, 14 Apr 2002 07:29:12 +0530
Ma Siva Kumar <ma_sivakumar@yahoo.com> wrote:

> Fortunately, this particular situation involves simpler relations. It is more
> like this.
>
> Buying companies place orders to their supplier companies. Supplier companies
> maintain the status of orders in the system. Buyer companies can login and
> get information about the order status.
>
> Thus, most of the update of information comes from the internal working of
> supplier companies and the relationship is strictly one to one (what one
> buyer buys from a supplier does not affect any one else in the system).
>
> If everyone uses the central server to update the transactions that is ideal.
> However, atleast in the initial stages, supplier companies may like to
> conduct their day to day operations on the local server (due to connection
> speeds, costs etc) and update the transactions to the central server several
> times a day.
>
> The information flow from the buyer is in the form of new orders, approval of
> samples, payment information etc.
>
> Hope now it is clearer. Even though there will be hundreds of companies in
> the system, each one will have a strictly one to one relationship with
> others.
>
> What is the best possible way to do this using Postgres and PHP?
>
> Best regards,
>
>
> Siva,
> Chennai, Tamil Nadu.
>
<SNIP>

You might want to consider an email based system.

Your system will send email (which can be done via dial-up POP).
Send formated messages back and forth (something like EDI) using
maybe XML or a custom format.

I've done this before for customers who are paranoid about being on the
internet all of the time.  Its not hard.

While this is not really much help for PHP (as it web based), it is
just an idea.

GB