[SQL] how to execute a C program via trigger ?

2000-12-04 Thread S.F. Lee

Hi,
   
   I am using Red Hat 6.1 + PostgreSQL 7.0.3. All of
my
applications are developed by C and ECPG.  I would
like to know how to execute a C program by Trigger,for
example:


   1. I have a program my_c_program.c shuch as:

#include 
main()
{
   printf("Hello World !\n");
}

   2. I create a table foo by following command

CREATE TABLE foo
(
x  int4
);

   3. create a trigger  foo_trig :

create trigger foo_trig after update
on foo for each row execute procedure sql_c();
   
   4. I don't know how to design sql_c(), can anyone
  give a small plpsql program that can execute
  my_c_program?  

   regards,S.F. Lee


__
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/



[HACKERS] Re: [SQL] Rules with Conditions: Bug, or Misunderstanding

2000-12-04 Thread Jan Wieck

Tom Lane wrote:
> Jan Wieck <[EMAIL PROTECTED]> writes:
> > Tom Lane wrote:
> >> Hm.  Perhaps the "cannot update view" test is too strict --- it's not
> >> bright enough to realize that the two rules together cover all cases,
> >> so it complains that you *might* be trying to update the view.  As the
> >> code stands, you must provide an unconditional DO INSTEAD rule to
> >> implement insertion or update of a view.
>
> > Disagree.
>
> > A  conditional rule splits the command into two, one with the
> > rules action and  the  condition  added,  one  which  is  the
> > original  statement  plus the negated condition. So there are
> > cases left where an INSERT can happen to  the  view  relation
> > and it's the job of this test to prevent it.
>
> Well, in that case the present code is broken, because it's going to
> spit up if any part of the rewritten query shows the view as result
> relation (cf. QueryRewrite() ... note that this logic no longer looks
> much like it did the last time you touched it ;-)).  You'd have to
> convert the existing rewrite-time test into a runtime test in order to
> see whether the query actually tries to insert any tuples into the view.

Yepp.

> While that is maybe reasonable for insertions, it's totally silly
> for update and delete queries.  Since the view itself can never contain
> any tuples to be updated or deleted, a runtime test that errors out
> when one attempts to update or delete such a tuple could never fire.
> I don't think that means that we shouldn't complain about an update
> or delete on a view.
>
> I think the test is best left as-is...

Since  conditional  rules  aren't  any  better compared to an
unconditional multi-action  instead  rule  where  the  single
actions  have all the different conditions, let's leave it as
is and insist on one unconditional instead rule.


Jan

--

#==#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.  #
#== [EMAIL PROTECTED] #





[SQL] SETOF

2000-12-04 Thread Limin Shen
Hi,
This is my first time using this address, so if I sent to the wroing place, please forgive me.
I have a question on how to use SETOF to return multiple values. IF someone can help me on that subject, that will be great.
Thank you.
 
 Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com


Re: [GENERAL] Re: [PHP-DB] Re: [SQL] a script that queries database periodically

2000-12-04 Thread Dan Wilson

> Jason wrote:
> >
> > aolserver is a web/application server.  PHP is a server-side scripting
> > language.  Why exactly *should* it have a job scheduler?
> >
> > Some (such as myself) might also ask why should a web server have a job
> > scheduler, but that's a thread for a different list :)
>
> Because PHP is supposed to solve web development problems. And this is
> one of them. It's very useful.

I disagree!  Cronjobs are not a web development problem.  That is something
that should be handled on the server/machine side.  PHP is purely designed
to dynamically create web pages.  It has other things built into it, but
each one interfaces with the web page somehow.  A cronjob doesn't use the
web at all.  The web is an interactive thing and the whole purpose of a job
scheduler is to avoid interaction.

Sure a job scheduler is useful, but it is outside the scope and mission of
PHP.

-Dan




Re: [SQL] how to execute a C program via trigger ?

2000-12-04 Thread clayton cottingham

take a look at the contrib sections fti or fulltext index example

it takes you through it all



"S.F. Lee" wrote:
> 
> Hi,
> 
>I am using Red Hat 6.1 + PostgreSQL 7.0.3. All of
> my
> applications are developed by C and ECPG.  I would
> like to know how to execute a C program by Trigger,for
> example:
> 
>1. I have a program my_c_program.c shuch as:
> 
> #include 
> main()
> {
>printf("Hello World !\n");
> }
> 
>2. I create a table foo by following command
> 
> CREATE TABLE foo
> (
> x  int4
> );
> 
>3. create a trigger  foo_trig :
> 
> create trigger foo_trig after update
> on foo for each row execute procedure sql_c();
> 
>4. I don't know how to design sql_c(), can anyone
>   give a small plpsql program that can execute
>   my_c_program?
> 
>regards,S.F. Lee
> 
> __
> Do You Yahoo!?
> Yahoo! Shopping - Thousands of Stores. Millions of Products.
> http://shopping.yahoo.com/



[SQL] reinitialize a sequence?

2000-12-04 Thread Bruno Boettcher

hello,
played a bit around with the serial type
wanted to adapt my already existing tables to this system...
dumped the DB, created the new tables, loaded old data in

all works, until i try to insert something without specifying the id
field (that's the now sequential field). And the reason is that the
sequene is set to 1.

is there a simple way to tell all sequences to take the max value +1 of
their respective tables? (a bit like the vacuum command?)

i tryed to set the value by hand, but did something wrong :D the command
didn't completed:
fibu=> update journal_id_seq set last_value=1187;
ERROR:  You can't change sequence relation journal_id_seq

surely something real stupid again, but i never used sequences till
now... and there's no example in the docu (BTW would be nice if this
was addressed in the documentation)



-- 
ciao bboett
==
[EMAIL PROTECTED]
http://inforezo.u-strasbg.fr/~bboett http://erm1.u-strasbg.fr/~bboett
===
the total amount of intelligence on earth is constant.
human population is growing



[SQL] reinitialize a sequence?

2000-12-04 Thread Dan Lyke

Bruno Boettcher writes:
> is there a simple way to tell all sequences to take the max value +1 of
> their respective tables? (a bit like the vacuum command?)

This is completely gross, but what I've done:


#!/usr/bin/perl -w
use strict;
use DBI;
my ($dbh);
sub BEGIN
{
$dbh = DBI->connect('DBI:Pg:dbname=',
'zzz',
'z')
or die $DBI::errstr;
}
sub END
{
$dbh->disconnect;
}


sub UpdateSequenceFor($)
{
my ($table) = @_;
my ($sql,$sth,$id,$row);

$sql = "SELECT max(id) FROM $table";
$sth = $dbh->prepare($sql) or die $dbh->errstr."\n$sql\n";
$sth->execute or die $sth->errstr."\n$sql\n";
if ($id = $sth->fetchrow_arrayref)
{
$id = $id->[0];
$sql = "SELECT nextval('".$table."_id_seq')";
$sth = $dbh->prepare($sql) or die $dbh->errstr."\n$sql\n";
$sth->execute or die $sth->errstr."\n$sql\n";
while (($row = $sth->fetchrow_arrayref) && ($row->[0] < $id))
{
$sth = $dbh->prepare($sql) or die $dbh->errstr."\n$sql\n";
$sth->execute or die $sth->errstr."\n$sql\n";
}
}
}

# update the sequence for each table:
foreach ('users','blogentries','blogcomments','blogcommenthistory')
{
UpdateSequenceFor($_);
}



Re: [SQL] reinitialize a sequence?

2000-12-04 Thread Mike Castle


setval();

Sometimes it's good to read files in the source tree (such as HISTORY).

mrc
-- 
   Mike Castle   Life is like a clock:  You can work constantly
  [EMAIL PROTECTED]  and be right all the time, or not work at all
www.netcom.com/~dalgoda/ and be right at least twice a day.  -- mrc
We are all of us living in the shadow of Manhattan.  -- Watchmen



Re: [SQL] how to execute a C program via trigger ?

2000-12-04 Thread S.F. Lee

Thank for your hint, but I have some questions :

  1. Do I have to compile the C program into a shared
object (*.so)? 
  2. Do I have to use SPI (SPI is too complicate to
me)? 

  My request is very simple. I have a program
(my_c_program) 
  that I can execute it under shell by typing
(my_c_program).
  Basically my_c_program is not a function.

  I want to fire a trigger after I update the field
(x) in table foo, and the trigger can run the
my_c_program. Is there an easy way to execute a
PROCESS
via trigger?

   regards,S.F. Lee

--- clayton cottingham
<[EMAIL PROTECTED]> wrote:
> take a look at the contrib sections fti or fulltext
> index example
> 
> it takes you through it all
> 
> 
> 
> "S.F. Lee" wrote:
> > 
> > Hi,
> > 
> >I am using Red Hat 6.1 + PostgreSQL 7.0.3. All
> of
> > my
> > applications are developed by C and ECPG.  I would
> > like to know how to execute a C program by
> Trigger,for
> > example:
> > 
> >1. I have a program my_c_program.c shuch as:
> > 
> > #include 
> > main()
> > {
> >printf("Hello World !\n");
> > }
> > 
> >2. I create a table foo by following command
> > 
> > CREATE TABLE foo
> > (
> > x  int4
> > );
> > 
> >3. create a trigger  foo_trig :
> > 
> > create trigger foo_trig after update
> > on foo for each row execute procedure sql_c();
> > 
> >4. I don't know how to design sql_c(), can
> anyone
> >   give a small plpsql program that can execute
> >   my_c_program?
> > 
> >regards,S.F. Lee
> > 
> > __
> > Do You Yahoo!?
> > Yahoo! Shopping - Thousands of Stores. Millions of
> Products.
> > http://shopping.yahoo.com/


__
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/