This is a discussion on Version 1 Calling convention within the pgsql Novice forums, part of the PostgreSQL category; --> I have a .pgc file and i have the following code snippet in it: PG_FUNCTION_INFO_V1 (test); Datum test (PG_FUNCTION_ARGS) ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have a .pgc file and i have the following code snippet in it: PG_FUNCTION_INFO_V1 (test); Datum test (PG_FUNCTION_ARGS) { EXEC SQL BEGIN DECLARE SECTION; int id = PG_GETARG_INT(0); char *raw_rawemail1 = PG_GETARG_CHAR_P(1); char *rawemail1 = (char *) palloc (VARSIZE(rawemail1)); VARATT_SIZEP ( rawemail1 ) = VARSIZE (raw_rawemail1); //LINE 140 (thats where i get syntax error) memcpy( (void *) (VARDATA) (rawemail1), (void *) (VARDATA) (raw_rawemail1) , (VARSIZE) (raw_rawemail1) - VARHDRSZ ); EXEC SQL END DECLARE SECTION; EXEC SQL CONNECT TO dbxyz; } When I compile this using ECPG parser.pgc I get the follwing error Syntax error at or near 'rawemail1' (LINE 140 marked above) Don't know what this error is all about. Don't know if my declaration in BEGIN END block is correct in the pgc file for version 1 calling convention Thanks ~Jas |
| |||
| Well I think I can because so far its been working fine. Anyways, as suggested by others too, I'm going to change it to SPI but right now the matter of concern is the error that I'm getting. Is it because I'm using ECPG in server side code or something else? On 8/30/06, Alvaro Herrera <alvherre@commandprompt.com> wrote: > > Jasbinder Bali wrote: > > I have a .pgc file and i have the following code snippet in it: > > > > PG_FUNCTION_INFO_V1 (test); > > > > Datum > > test (PG_FUNCTION_ARGS) > > { > > EXEC SQL BEGIN DECLARE SECTION; > > You can't use ecpg in server-side functions. You need to use the SPI > interface. > > -- > Alvaro Herrera > http://www.CommandPrompt.com/ > PostgreSQL Replication, Consulting, Custom Development, 24x7 support > |
| |||
| OK. I've removed the ECPG code and error has gone away. Thanks jas On 8/30/06, Alvaro Herrera <alvherre@commandprompt.com> wrote: > > Jasbinder Bali wrote: > > I have a .pgc file and i have the following code snippet in it: > > > > PG_FUNCTION_INFO_V1 (test); > > > > Datum > > test (PG_FUNCTION_ARGS) > > { > > EXEC SQL BEGIN DECLARE SECTION; > > You can't use ecpg in server-side functions. You need to use the SPI > interface. > > -- > Alvaro Herrera > http://www.CommandPrompt.com/ > PostgreSQL Replication, Consulting, Custom Development, 24x7 support > |
| |||
| Do i need to download spi.h from somewhere or what? I can't see it anywhere On 8/30/06, Jasbinder Bali <jsbali@gmail.com> wrote: > > OK. I've removed the ECPG code and error has gone away. > Thanks > jas > > On 8/30/06, Alvaro Herrera <alvherre@commandprompt.com > wrote: > > > Jasbinder Bali wrote: > > > I have a .pgc file and i have the following code snippet in it: > > > > > > PG_FUNCTION_INFO_V1 (test); > > > > > > Datum > > > test (PG_FUNCTION_ARGS) > > > { > > > EXEC SQL BEGIN DECLARE SECTION; > > > > You can't use ecpg in server-side functions. You need to use the SPI > > interface. > > > > -- > > Alvaro Herrera > > http://www.CommandPrompt.com/ > > PostgreSQL Replication, Consulting, Custom Development, 24x7 support > > > > |
| |||
| Isn't there any rpm to download the SPI ?? On 8/30/06, Martijn van Oosterhout <kleptog@svana.org> wrote: > > On Wed, Aug 30, 2006 at 01:01:32AM -0400, Jasbinder Bali wrote: > > Do i need to download spi.h from somewhere or what? I can't see it > anywhere > > You need the backend header files. In Debian they're in the > postgresql-dev package. You'll need to add > -I/usr/include/postgresql/server to your compile command to see them. > > Hope this helps, > -- > Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > > From each according to his ability. To each according to his ability to > litigate. > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > > iD8DBQFE9R/4IB7bNG8LQkwRAiekAJ9VV+aC+bshCm8H6Lifa5rwTtBl8wCcC yli > 9BMLtVsMsLzJM1FwLvhqMbs= > =Xbxl > -----END PGP SIGNATURE----- > > > |
| |||
| OK..i got it.. spi.h was in /usr/include/pgsql/server/executor Jas On 8/30/06, Jasbinder Bali <jsbali@gmail.com> wrote: > > Isn't there any rpm to download the SPI ?? > > On 8/30/06, Martijn van Oosterhout <kleptog@svana.org> wrote: > > > On Wed, Aug 30, 2006 at 01:01:32AM -0400, Jasbinder Bali wrote: > > Do i need to download spi.h from somewhere or what? I can't see it > anywhere > > You need the backend header files. In Debian they're in the > postgresql-dev package. You'll need to add > -I/usr/include/postgresql/server to your compile command to see them. > > Hope this helps, > -- > Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > > From each according to his ability. To each according to his ability to > litigate. > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > > iD8DBQFE9R/4IB7bNG8LQkwRAiekAJ9VV+aC+bshCm8H6Lifa5rwTtBl8wCcC yli > 9BMLtVsMsLzJM1FwLvhqMbs= > =Xbxl > -----END PGP SIGNATURE----- > > > > |
| |||
| How does the SPI manager know which database to connect using SPI_CONNECT() As there can be more than one datbase in the postgres server, how does it make out which database to connect as we don't specify the datbase name we intend to connect. ~Jas On 8/30/06, Jasbinder Bali <jsbali@gmail.com> wrote: > > OK..i got it.. > spi.h was in /usr/include/pgsql/server/executor > > Jas > > On 8/30/06, Jasbinder Bali <jsbali@gmail.com > wrote: > > > Isn't there any rpm to download the SPI ?? > > > > On 8/30/06, Martijn van Oosterhout < kleptog@svana.org> wrote: > > > > > On Wed, Aug 30, 2006 at 01:01:32AM -0400, Jasbinder Bali wrote: > > > Do i need to download spi.h from somewhere or what? I can't see it > > anywhere > > > > You need the backend header files. In Debian they're in the > > postgresql-dev package. You'll need to add > > -I/usr/include/postgresql/server to your compile command to see them. > > > > Hope this helps, > > -- > > Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > > > From each according to his ability. To each according to his ability > > to litigate. > > > > > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.1 (GNU/Linux) > > > > iD8DBQFE9R/4IB7bNG8LQkwRAiekAJ9VV+aC+bshCm8H6Lifa5rwTtBl8wCcC yli > > 9BMLtVsMsLzJM1FwLvhqMbs= > > =Xbxl > > -----END PGP SIGNATURE----- > > > > > > > > > |
| |||
| PG_FUNCTION_INFO_V1 (test); Datum test (PG_FUNCTION_ARGS) { int id = PG_GETARG_INT(0); char *raw_rawemail1 = PG_GETARG_CHAR_P(1); //line 6 (warning thrown for this line) char *rawemail1 = (char *) palloc (VARSIZE(rawemail1)); VARATT_SIZEP ( rawemail1 ) = VARSIZE (raw_rawemail1); //LINE 140 (thats where i get syntax error) memcpy( (void *) (VARDATA) (rawemail1), (void *) (VARDATA) (raw_rawemail1) , (VARSIZE) (raw_rawemail1) - VARHDRSZ ); } Was trying to test the code given in the postgres manual. The only diff being that i changed the data type from text* to char* and it gives me a warning like: "initialization makes pointer from integer without a cast" at line 6 as commented above. Can any1 point why? ~Jas Compiling this code gives me the follwoing error: Compiling this code throws the follwoing error On 8/30/06, Jasbinder Bali <jsbali@gmail.com> wrote: > > I have a .pgc file and i have the following code snippet in it: > > PG_FUNCTION_INFO_V1 (test); > > Datum > test (PG_FUNCTION_ARGS) > { > EXEC SQL BEGIN DECLARE SECTION; > int id = PG_GETARG_INT(0); > char *raw_rawemail1 = PG_GETARG_CHAR_P(1); > char *rawemail1 = (char *) palloc (VARSIZE(rawemail1)); > VARATT_SIZEP ( rawemail1 ) = VARSIZE (raw_rawemail1); //LINE > 140 (thats where i get syntax error) > memcpy( (void *) (VARDATA) (rawemail1), (void *) (VARDATA) > (raw_rawemail1) , (VARSIZE) (raw_rawemail1) - VARHDRSZ ); > EXEC SQL END DECLARE SECTION; > > EXEC SQL CONNECT TO dbxyz; > } > > When I compile this using > ECPG parser.pgc > > I get the follwing error > > Syntax error at or near 'rawemail1' (LINE 140 marked above) > > Don't know what this error is all about. > Don't know if my declaration in BEGIN END block is correct in the pgc file > for version 1 calling convention > > Thanks > ~Jas > |
| ||||
| Does that mean if I am passing a char value to the version 1 function from a function in the database then in the version 1 function it needs to be treated as text*?? On 8/30/06, Martijn van Oosterhout <kleptog@svana.org> wrote: > > On Wed, Aug 30, 2006 at 05:38:34AM -0400, Jasbinder Bali wrote: > > PG_FUNCTION_INFO_V1 (test); > > > <snip> > > > char *raw_rawemail1 = PG_GETARG_CHAR_P(1); //line 6 (warning > > thrown for this line) > > <snip> > > > Was trying to test the code given in the postgres manual. > > The only diff being that i changed the data type from text* to char* and > it > > gives me a warning like: > > > > "initialization makes pointer from integer without a cast" at line 6 as > > commented above. > > > > Can any1 point why? > > Sure, there's no such function PG_GETARG_CHAR_P(). You should set your > compiler to warn about stuff like this. > > Have a nice day, > -- > Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/ > > From each according to his ability. To each according to his ability to > litigate. > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > > iD8DBQFE9WGjIB7bNG8LQkwRAkp8AKCRGJemB/SCqk9R6Spd1Jf6k0rodwCePN4J > HuRH44T7Nx8MDIyLEMFoVvQ= > =8jHd > -----END PGP SIGNATURE----- > > > |