?
Solved

Delphi using Postgresql unique primary key

Posted on 2001-07-12
8
Medium Priority
?
788 Views
Last Modified: 2011-09-20
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
Comment
Question by:martijnbeelen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278531
Can't you just create a field in the table that does autonumber?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6278545
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
 
LVL 27

Accepted Solution

by:
kretzschmar earned 1200 total points
ID: 6279721
use the storedproc, with the execproc-method

listening . . .

meikl ;-)
0
Industry Leaders: 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!

 

Author Comment

by:martijnbeelen
ID: 6280028
This works indeed:

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

Greetings,

Martijn
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6280049
:o(
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6280056
hu, thanks for the points :-))

glad that you get it work
good luck again

meikl ;-)

(sorry eps)
0
 

Author Comment

by:martijnbeelen
ID: 6280097
Epsylon,

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

It's called "Connect Delphi to Postgresql"

Martijn
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6280310
ah, now i understand the other q :-)))
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question