pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paulo Assis <paulo@coralinformatica.com.br>
To: pgsql-sql@postgresql.org
Subject: Postgesql 8 beta 5: ecpg and date type - Access violations
Date: Mon, 6 Dec 2004 02:18:22 -0200
Message-ID: <000a01c4db4a$a10049b0$0100a8c0@paulo> (raw)

Hi,

There is an "access violation" caused by ecpgtypes when using date fields and ecpg.
Everything was runnig ok with dates rangin from 2000 - 2004, but this acces violation
occurs when the date with th year 1968 appears.

Looking at my program, I can see that this happens inside the SELECT into :data_admissao;
where "data_admissao" is a date type.
When I remove this field from the select, then it works.

Here is the steps to reproduce the error:

PostgreSQL 8.0.0 beta5
Windows XP Professional
MingW

Table:
CREATE TABLE funcionarios
(
  id int4 NOT NULL,
  nome varchar(40) NOT NULL,
  data_admissao date NOT NULL,
  funcao int4 NOT NULL,
  CONSTRAINT funcionarios_pkey PRIMARY KEY (id)
) 
WITHOUT OIDS;

Data:
INSERT INTO fpcadfun VALUES (111,'SILVA','1968-01-19',10);

Program:
class funcionario { ... };
typedef std::vector<funcionario> funcionario_type;

bool db_ler_funcionarios( funcionario_type &funcs )
{
 funcs.clear();

 EXEC SQL BEGIN DECLARE SECTION;
 int id;
 VARCHAR nome[40];
 date data_admissao;
 int funcao;
 EXEC SQL END DECLARE SECTION;

 EXEC SQL DECLARE func_cur CURSOR FOR
 SELECT id, nome, data_admissao, funcao
 FROM funcionarios ORDER BY id;

 EXEC SQL OPEN func_cur;
 EXEC SQL WHENEVER NOT FOUND DO break;

 char *txt_adm;
 
 while(true)
 {
  EXEC SQL FETCH NEXT FROM func_cur INTO
   :id, :nome, :data_admissao, :funcao;

  txt_adm = PGTYPESdate_to_asc(data_admissao);
  funcionario f( id, nome.arr, txt_adm, funcao );
  funcs.push_back(f);
  free(txt_adm);
 }
 EXEC SQL CLOSE func_cur;
 return true;
}

The access violation occurs at the bold line. I'm using mingw to compile this
program.

Please fell free to ask for any other question or comment about this error.

I hope that I could give my 2 cents for this incredible RDMS.

Best Regards,
Paulo Assis

Message-ID: <000a01c4db4a$a10049b0$0100a8c0@paulo>
Permalink:  ../000a01c4db4a$a10049b0$0100a8c0@paulo/
Also on:    postgresql.org/message-id/000a01c4db4a$a10049b0$0100a8c0@paulo

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: paulo@coralinformatica.com.br
  Subject: Re: Postgesql 8 beta 5: ecpg and date type - Access violations
  In-Reply-To: <000a01c4db4a$a10049b0$0100a8c0@paulo>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox