[GENERAL] Hex numbers in psql

2007-05-20 Thread madhtr

hi group :)

How do use hex numbers in psql?  I.E.

instead of:
   select 16
I want to do
   select 0x10

like in c++

I tried doing what this website said
http://www.faqs.org/docs/ppbook/c12119.htm
but it does not work

TY :)




---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[GENERAL] exception question ....

2007-05-20 Thread madhtr

sry, one more question ...

I want to trap an exception and return a -1 no matter WHAT it is ... what do 
i need to replace  with?





create or replace function clrsplit(int4) returns unknown as
$$
BEGIN
delete from split where tkid=$1;
EXCEPTION
WHEN 
 return -1;
update tk set dtchksp=null where nid=$1;
return 0;
END
$$ language plpgsql; 




---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


[GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-14 Thread madhtr
when i intentioally try to connect asynchronously to a database that does 
not exist, i get


"server closed the connection unexpectedly"

My intention is to create the database if it does not exist ... Is there any 
way retrive the actual error so i can know when to create the database?


thanx:) 




---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-14 Thread madhtr

ok thanx:)

... here's the source ... can u tell me whats wrong? (the purpose of this 
function is to allow for thread safety on the connection, and allow for 
cancellation if the connection takes too long)


BTW ...

- coninfo is "host=localhost port=5432 dbname=testdb user=localuser 
password=localpassword"

- I am using VC++ and compiling a windows execuatble ...

PGconn* PQconnectStartCS(const char* coninfo,LPCRITICAL_SECTION lpcs,bool* 
lpcancel,int* lppge){

   int& pge = *lppge;
   bool& cancel = *lpcancel;
   bool keepon = true;
   PGconn* pr = 0;
   pge = 0;
   EnterCriticalSection(lpcs);
   pr = PQconnectStart(coninfo);

   while (!killthread(&cancel) && keepon){
   switch(pge = PQconnectPoll(pr)){
   case PGRES_POLLING_FAILED:
   keepon = false;
   break;
   case PGRES_POLLING_OK:
   pge = 0;
   keepon = false;
   break;
   default:
   break;
   };
   if (keepon)
   Sleep(1);
   };

   LeaveCriticalSection(lpcs);
   if (!pge && pr){
   switch(pge = PQstatus(pr)){
   case CONNECTION_OK:
   pge = 0;
   break;
   };
   };
   return pr;
};

- Original Message - 
From: "Tom Lane" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, August 14, 2007 14:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



"madhtr" <[EMAIL PROTECTED]> writes:

when i intentioally try to connect asynchronously to a database that does
not exist, i get



"server closed the connection unexpectedly"


There's something wrong with your code then.

regards, tom lane

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings
- Original Message - 
From: "Tom Lane" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, August 14, 2007 14:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



"madhtr" <[EMAIL PROTECTED]> writes:

when i intentioally try to connect asynchronously to a database that does
not exist, i get



"server closed the connection unexpectedly"


There's something wrong with your code then.

regards, tom lane

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings 




---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-14 Thread madhtr

I did make an error on the zero assumption, ty :)

However, the reason PGRES_POLLING_FAILED and PGRES_POLLING_OK both break the 
loop is because of this:


"If this call returns PGRES_POLLING_FAILED, the connection procedure has 
failed. If this call returns PGRES_POLLING_OK, the connection has been 
successfully made."


source: http://www.postgresql.org/docs/7.3/static/libpq-connect.html

I was also under the assumption that I would not need to perform my own 
selects on the underlying socket, and that whatever I got back would be 
either a null pointer, a successful connection pointer, or a broken 
connection pointer with an error indication.


cleary I am going to have to study this documentation more carefully ... So 
... for simplicity's sake, If I just do the following, how do I get back 
"database does not exist" ?



#pragma once



#include 

#include 

#include 



int main(int na,char** sa){



  char* host= "localhost";

  unsigned short port   = 5432;

  char* dbname  = "nonexistantdb";

  char* user= "user";

  char* password= "pass";



  int e = 0;

  PGconn* lpcn  = 0;

  bool keepon   = true;

  char cs[1024];



  sprintf(

 cs,

 "host=%s port=%u dbname=%s user=%s password=%s",

 host,port,dbname,user,password

  );



  if (lpcn = PQconnectStart(cs)){

 while (keepon){

switch(e = PQconnectPoll(lpcn)){

case PGRES_POLLING_FAILED:

case PGRES_POLLING_OK:

   keepon = false;

   break;

};

Sleep(1);

 };

 printf(

   "PQerrorMessage(lpcn) returns:\n\n%s\n\nPQstatus(lpcn) 
returns %d\n",


   PQerrorMessage(lpcn),PQstatus(lpcn)

 );

 PQfinish(lpcn);

  } else

 printf("I am assuming we are out of memory ...\n");



  return e;

};

/

- Original Message - 
From: "Tom Lane" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, August 14, 2007 15:53
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



"madhtr" <[EMAIL PROTECTED]> writes:

 ... here's the source ... can u tell me whats wrong?


Well, your usage of "pge" seems fairly broken, in particular the random
(and wrong) assumptions about which values are or are not zero.  AFAICT
this code doesn't really distinguish between PGRES_POLLING_FAILED and
PGRES_POLLING_OK.  And if it does return failure, there's no way for the
caller to know which enum type the failure code belongs to.

You didn't show us the code that is actually reporting the error, but I
wonder whether it isn't equally confused about how to determine what the
error is.

regards, tom lane 




---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-14 Thread madhtr


- Original Message - 
From: "Tom Lane" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, August 14, 2007 18:50
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



"madhtr" <[EMAIL PROTECTED]> writes:
cleary I am going to have to study this documentation more carefully ... 
So

... for simplicity's sake, If I just do the following, how do I get back
"database does not exist" ?


[ shrug... ]  Your program works perfectly for me:

$ ./testit
PQerrorMessage(lpcn) returns:

FATAL:  database "nonexistantdb" does not exist


PQstatus(lpcn)
returns 1
$

... although it takes a good long while (several seconds) because of the
"sleep(1)" in the interaction with the postmaster.


hmm ... TY, must be my version or something like you state further down.

Sleep(1) should be only 1/1000 of a second. I do that so I don't hammer the 
processor with my while loop when i am not  using a select().




Maybe your problem is not with the program, but with the postmaster
you're trying to connect to?  Does psql work?



yep, good thought. psql command line works fine, its sycnhronous tho.


source: http://www.postgresql.org/docs/7.3/static/libpq-connect.html


Another line of thought, given the reading-between-the-lines conclusion
that you are trying to use PG 7.3 libraries on Windows, is that there
was something broken in the async-connect code back then on that
platform.  If you really are trying to do that, do yourself a favor and
move to 8.0 or later.  Nobody's going to be very interested in fixing
7.3.  (I did try your program with 7.3 on Unix, though, and it seemed
fine except the error message was spelled a bit differently.)



Ty, I'll check that ... :)


I was also under the assumption that I would not need to perform my own
selects on the underlying socket, and that whatever I got back would be
either a null pointer, a successful connection pointer, or a broken
connection pointer with an error indication.


You don't *have* to perform selects on the underlying socket, but if you
are not multiplexing this activity with some other I/O, I have to wonder
why you are bothering with an asynchronous connect at all.  What you've
got at the moment is a poorly-implemented equivalent of PQconnectdb().


yep, the little simplified program is fairly pointless... but in RL, i will 
pass a pointer to a cancel flag ...


void connect(bool* lpcancel){
   while (!*lpcancel && trying2connect){
   // yadda yadda yadda
   };
};

so that the user can click the "connect" button, start a thread, and then 
click the "cancel" button instead giving my app the three finger salute if 
they grow impatient, heh;)


In any case, I very much appreciate your help and time, I'll let you know 
what I figure out. I bet you're right about the version.  Hopefully I can 
contribute something back to the list at some point.  Again, sry for the 
sloppy code at the beginning :)


madhtr 




---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org/


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-15 Thread madhtr


- Original Message - 
From: "madhtr" <[EMAIL PROTECTED]>

To: "Tom Lane" <[EMAIL PROTECTED]>
Cc: 
Sent: Wednesday, February 14, 2007 22:33
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll


Another line of thought, given the reading-between-the-lines conclusion
that you are trying to use PG 7.3 libraries on Windows, is that there
was something broken in the async-connect code back then on that
platform.  If you really are trying to do that, do yourself a favor and
move to 8.0 or later.  Nobody's going to be very interested in fixing
7.3.  (I did try your program with 7.3 on Unix, though, and it seemed
fine except the error message was spelled a bit differently.)



Ty, I'll check that ... :)



Rats ... my source version is 8.2.3, psql returns 8.1.4 for select 
version();


back to the drawing board ... It worked for you, I just have to make it work 
for me ... mebbe I'll go through the source a bit, ty:)


madhtr 




---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-16 Thread madhtr

Hi Tom :)

Is this:

libpq-fe.h:

/**
$PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.134 2006/10/04 
00:30:13 momjian Exp $

**/

the latest version of libpq?


- Original Message - 
From: "Tom Lane" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, August 14, 2007 21:42
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



"madhtr" <[EMAIL PROTECTED]> writes:

From: "Tom Lane" <[EMAIL PROTECTED]>

... although it takes a good long while (several seconds) because of the
"sleep(1)" in the interaction with the postmaster.


Sleep(1) should be only 1/1000 of a second. I do that so I don't hammer 
the

processor with my while loop when i am not  using a select().


Ah.  I was interpreting it in Unix terms, where sleep() measures in
seconds.  With a wait of a few msec it might not be too intolerable.

regards, tom lane 




---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-16 Thread madhtr

ok, ty :)

- Original Message - 
From: "Alvaro Herrera" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: "Tom Lane" <[EMAIL PROTECTED]>; 
Sent: Thursday, August 16, 2007 11:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



madhtr wrote:


Is this:

libpq-fe.h:

/**
$PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.134 2006/10/04
00:30:13 momjian Exp $
**/

the latest version of libpq?


This is what we ship with 8.2.4, yes.


--
Alvaro Herrera 
http://www.advogato.org/person/alvherre

"On the other flipper, one wrong move and we're Fatal Exceptions"
(T.U.X.: Term Unit X  - http://www.thelinuxreview.com/TUX/) 




---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll

2007-08-16 Thread madhtr
Ok, i figured something out anyway ... hopefully it will be helpful to the 
group ...
The following works on my WinXP pro machine most of the time.  I have 
confirmed

that I have the latest versions of everything.

///
#pragma once

#include 
#include 
#include 
#include 

PGconn* asyncconnect(const char* cs,bool* lp_USER_cancel){
int pqcp = 0;
PGconn* lpcn = 0;
if (lpcn = PQconnectStart(cs)){
 if (CONNECTION_BAD != PQstatus(lpcn)){
  bool keepon = true;
  while (keepon && !*lp_USER_cancel){
   switch(pqcp = PQconnectPoll(lpcn)){
   case PGRES_POLLING_READING:
{
 SOCKET s = PQsocket(lpcn);
 timeval tv = {0,10};
 int ns = 0;
 while (!*lp_USER_cancel && !ns){
  fd_set fdr,fde;
  FD_ZERO(&fdr);
  FD_ZERO(&fde);
  FD_SET(s,&fdr);
  FD_SET(s,&fde);
  ns = select(0,&fdr,0,&fde,&tv);
 };
};
break;
   case PGRES_POLLING_FAILED:
   case PGRES_POLLING_OK:
keepon = false;
break;
   };

   // NO!
   //  Sleep(1);

   /**
   I'm guessing the connection gets discoed while the
   thread is sleeping, resetting
   the error message buffer to something other than
   the initial error?

   if we use a select(), (the right way) we do not
   have to sleep. Still, even the select does NOT always
   allow for catching it in time.

   IMHO, the error that causes
   the disco should never be overwritten by the disco
   message itself:

'server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.'

   within the internal connection thread, IF this is
   indeed what is happening.
   */
  };
 };
};
return lpcn;
};

int main(int na,char** sa){
char* host= "localhost";
unsigned short port  = 5432;
char* dbname   = "nonexistantdb";
char* user= "";
char* password   = "";

bool cancel = false;
char cs[1024];

sprintf(
 cs,
 "host=%s port=%u dbname=%s user=%s password=%s",
 host,port,dbname,user,password
);

if (PGconn* lpcn = asyncconnect(cs,&cancel)){
 printf("PQerrorMessage(lpcn) returns:\n\n%s\n\nPQstatus(lpcn) returns 
%d\n",PQerrorMessage(lpcn),PQstatus(lpcn));

 PQfinish(lpcn);
};

return 0;

};
/////

cheers, madhtr


- Original Message - 
From: "Tom Lane" <[EMAIL PROTECTED]>

To: "madhtr" <[EMAIL PROTECTED]>
Cc: 
Sent: Tuesday, August 14, 2007 21:42
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll



"madhtr" <[EMAIL PROTECTED]> writes:

From: "Tom Lane" <[EMAIL PROTECTED]>

... although it takes a good long while (several seconds) because of the
"sleep(1)" in the interaction with the postmaster.


Sleep(1) should be only 1/1000 of a second. I do that so I don't hammer 
the

processor with my while loop when i am not  using a select().


Ah.  I was interpreting it in Unix terms, where sleep() measures in
seconds.  With a wait of a few msec it might not be too intolerable.

regards, tom lane

---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match 




---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


[GENERAL] How to clear bits?

2007-09-20 Thread madhtr

Hello group :)

How do a clear bits in a number in PostGreSQL?

in c++ its:

0xff00 &~ 0x

what is it in PostGreSQL from the psql command line app?

select ...

Thanx:)


---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match


Re: [GENERAL] How to clear bits?

2007-09-20 Thread madhtr

nevermind, I figured it out ...

fails:

0xff00 &~ 0x

succeeds:

0xff00 & ~ 0x

I had to add a space.




- Original Message - 
From: "madhtr" <[EMAIL PROTECTED]>

To: "PostgreSQL General" 
Sent: Thursday, September 20, 2007 13:01
Subject: [GENERAL] How to clear bits?



Hello group :)

How do a clear bits in a number in PostGreSQL?

in c++ its:

0xff00 &~ 0x

what is it in PostGreSQL from the psql command line app?

select ...

Thanx:)


---(end of broadcast)---
TIP 9: In versions below 8.0, the planner will ignore your desire to
  choose an index scan if your joining column's datatypes do not
  match



---(end of broadcast)---
TIP 4: Have you searched our list archives?

  http://archives.postgresql.org/


[GENERAL] stripping HTML, SQL injections ...

2007-11-14 Thread madhtr
Quick question, are there any native functions in PostGreSQL 8.1.4 that will 
strip HTML tags, escape chars, etc?


thanx:) 




---(end of broadcast)---
TIP 6: explain analyze is your friend