Skip site navigation (1) Skip section navigation (2)

Postgesql 8 beta 5: ecpg and date type - Access violations

From: "Paulo Assis" <paulo(at)coralinformatica(dot)com(dot)br>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Postgesql 8 beta 5: ecpg and date type - Access violations
Date: 2004-12-06 04:18:22
Message-ID: 000a01c4db4a$a10049b0$0100a8c0@paulo (view raw or flat)
Thread:
Lists: pgsql-sql
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

pgsql-sql by date

Next:From: pgsql-sqlDate: 2004-12-06 17:35:39
Subject: Making dirty reads possible?
Previous:From: Michael FuhrDate: 2004-12-06 04:03:24
Subject: Re: inserting values into types

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group