• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 793
  • Last Modified:

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
0
martijnbeelen
Asked:
martijnbeelen
  • 3
  • 3
  • 2
1 Solution
 
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
 
kretzschmarCommented:
use the storedproc, with the execproc-method

listening . . .

meikl ;-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now