Delphi using Postgresql unique primary key

Hello,

I'm trying to use a postgresql database from my Delphi application. This database has a sequence called 'uniquenumbergenerator' which should create a unique id for every database entry made.
I've tried 2 things to make this work:

1. I used a query with SQL: 'Select nextval('uniquenumbergenerator')';
2. I used the stored procedure nextval with arguments Input: String 'uniquenumbergenerator' and Result: integer

Problems with these things:
1. I tried to Close and Open the query directly behind each other:
Query.Open;
Query.Close;
And then I tried to read the value of the nextval. Executed 2 times within 20 statement behind eachother, this returned me the SAME values!!

2. Same story, I called these procedures within 20 statements from eachother and I got the same values for the unique numbers.

I think this problem has something to do with caching or something like this....

I have installed the postgresql ODBC driver on Windows 98 and everything works with the database, only these requests for unique values occuring behind eachother, do not work.

I am really stuck with this one, because my application cannot run without this problem solved, so that's why I offer 300 points to solve this one.

Greetings,

Martijn Beelen
martijnbeelenAsked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
use the storedproc, with the execproc-method

listening . . .

meikl ;-)
0
 
EpsylonCommented:
Can't you just create a field in the table that does autonumber?
0
 
EpsylonCommented:
Also take a look here:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20149488

It's about Interbase, but maybe it can help you...
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
martijnbeelenAuthor Commented:
This works indeed:

StoredProc1.ExecProc;
ID := StoredProc1.ParambyName('ID').AsInteger;

Greetings,

Martijn
0
 
EpsylonCommented:
:o(
0
 
kretzschmarCommented:
hu, thanks for the points :-))

glad that you get it work
good luck again

meikl ;-)

(sorry eps)
0
 
martijnbeelenAuthor Commented:
Epsylon,

Could you answer my other question (for 100 points..)

It's called "Connect Delphi to Postgresql"

Martijn
0
 
kretzschmarCommented:
ah, now i understand the other q :-)))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.