Re: Embed SQL in C

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: GMX <baldauf_m(at)gmx(dot)at>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Embed SQL in C
Date: 2005-03-07 04:08:07
Message-ID: 20050307040807.GA23291@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, Mar 02, 2005 at 06:46:10PM +0100, GMX wrote:

> I need a C-program that goes something like this:

Why the requirement to use C? Many tasks are easier in and can be
adequately written with higher-level languages like Perl, Python,
Ruby, Tcl, etc.

> 1) Check how much devices are in the database and look up the IP and
> the Port from them from the database.

Make an appropriate SELECT query against the table that contains
this information. If you need help with SQL in general or with
PostgreSQL in particular, see the Tutorial and other parts of the
the PostgreSQL documentation.

http://www.postgresql.org/docs/

> 2) Connect to the computer using the IP and the Port and send a
> certain string to this computer.

This isn't a PostgreSQL issue. Use an appropriate library/module
or write the socket code yourself. The socket programming bible
is _UNIX Network Programming_, Volume 1, by W. Richard Stevens.

> [the computer echoes to this certain string with another string that
> contains 3 values]
>
> 3) The received string should be split and each value should be
> written in the right field of the SQL database.

Split the string using whatever facilities your programming language
provides and do an INSERT or UPDATE into the desired table. PostgreSQL
also has some string-handling functions -- see "String Functions and
Operators" in the "Functions and Operators" chapter in the documentation.

If you're having a specific problem, then please post what you've
tried, explain what you'd like to happen, and describe what actually
does happen, including the exact text of any errors or warnings.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2005-03-07 04:10:25 Re: Embed SQL in C
Previous Message Michael Fuhr 2005-03-07 03:44:01 Re: Error in transaction... Log file