Automatic sequence

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
Edijus
Fresh Boarder
Fresh Boarder
Posts: 3
Joined: 23.12.2013, 15:25

Automatic sequence

Post by Edijus »

Hello.
We have a problem: PostgreSQL + Zeos + Delphi XE2... Consider this:
DB part:

Code: Select all

CREATE DATABASE test
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'Lithuanian_Lithuania.1257'
       LC_CTYPE = 'Lithuanian_Lithuania.1257'
       CONNECTION LIMIT = -1;

CREATE TABLE sutartis
(
  st_id serial NOT NULL,
  st_vardas character varying(255) NOT NULL,
  CONSTRAINT sutartis_pkey PRIMARY KEY (st_id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE sutartis
  OWNER TO postgres;

CREATE OR REPLACE FUNCTION fnk_sutartis_edt(
    prm_id integer,
    prm_vardas character varying)
  RETURNS integer AS
$BODY$
BEGIN
  INSERT INTO sutartis(
    st_vardas)
  VALUES(
    prm_vardas
  );

  RETURN 0;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE SECURITY DEFINER
  COST 100;
ALTER FUNCTION fnk_sutartis_edt(integer, character varying)
  OWNER TO postgres;
Delphi part:
TZQuery named qDuomenys:

Code: Select all

SELECT
  *
FROM
  sutartis;
Assign UpdateObject property to TZUpdateSQL (named uqDuomenys) with InsertSQL:

Code: Select all

SELECT
  *
FROM
  fnk_sutartis_edt(null, :prm_vardas);

Code: Select all

qDuomenys.Close;
qDuomenys.Open;
qDuomenys.Insert;
uqDuomenys.Params.ParamByName('prm_vardas').Value := DateTimeToStr(Now);
qDuomenys.Post;
Resulting data in DB will be: last sequence + 2 e.g. 1, 3, 5, 7, 9, etc.

I think it is a bug that ZeosLib doesn't look at AutoGenerateValue property setting.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Automatic sequence

Post by marsupilami »

Hello Edijus,

this problem is described in this thread to some extent: http://zeoslib.sourceforge.net/viewtopi ... =20&t=3332
For now I can only suggest to use TZSequence and a bigint column or something similar. If you want to look at the code for yourself and find a proper solution, I will be happy to assist you in any way I can.
With best regards,

Jan
Post Reply